From patchwork Tue Jan 30 01:36:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Weiner X-Patchwork-Id: 13536670 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 97DF8C47DB3 for ; Tue, 30 Jan 2024 01:42:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 84CCD6B0080; Mon, 29 Jan 2024 20:42:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7D34D6B0081; Mon, 29 Jan 2024 20:42:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5FE1B6B0082; Mon, 29 Jan 2024 20:42:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 49CC36B0080 for ; Mon, 29 Jan 2024 20:42:21 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 276B11C1491 for ; Tue, 30 Jan 2024 01:42:21 +0000 (UTC) X-FDA: 81734277282.17.49101C4 Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) by imf16.hostedemail.com (Postfix) with ESMTP id 7649A180006 for ; Tue, 30 Jan 2024 01:42:19 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=NKVuP3Pp; dmarc=pass (policy=none) header.from=cmpxchg.org; spf=pass (imf16.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.222.172 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706578939; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=sMNhWdXKrsGXbbTndUjwna9Z9KC3QLUt3pRgP5ry3e4=; b=IC0cAQonIXSYwUke6XHAozT6RY+FIBzjmXDOHjQ0ClQiKSX8uex4ttHe1VW9F0uf8hP5uN bOTFRFdqqJxK+cYIZTT2l6HFuemb8hXyl6ik66dgzWTjGsNFpPwK80Mc+Bz+9AN8eFci9u fGF0AGVZ31I9tPnTgSDHWpUkKSnA2xQ= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=NKVuP3Pp; dmarc=pass (policy=none) header.from=cmpxchg.org; spf=pass (imf16.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.222.172 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706578939; a=rsa-sha256; cv=none; b=2rBzHNSDQfU+zWkYjjkNSXxgZyKc0PIIhMMVXpGxr3X2HA+z3Hl84bKkHQlzU6O/Up3kN/ QJS71NuuJgedL/2LoYJ++efhb33088U9sLdyznxqj9JadKLDdez4UkQpW1RTZfcQxarm6M YixvlMCltvCh1SRztA9wZ79b4JfTEJ8= Received: by mail-qk1-f172.google.com with SMTP id af79cd13be357-783d8e09a1cso241104285a.3 for ; Mon, 29 Jan 2024 17:42:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20230601.gappssmtp.com; s=20230601; t=1706578938; x=1707183738; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=sMNhWdXKrsGXbbTndUjwna9Z9KC3QLUt3pRgP5ry3e4=; b=NKVuP3PpG8uJasRVuGBCAw7LxHFZKHEx2B5lIgfbszFZWk30RVsN/mceu4eKC4a2vI zOLS9amTOWo2eGWViHrdPD320lUq0siK/jJ/d3Cl37WHH98npG5Ht+CNxasNLJC+I656 38ztnAL8vk6BEWT6HML1G6VyDd181kA7MEzzT/6KrQxlmBWuLAXRUMX1BQ9e70qEHGx3 j+zn5H+L1GbHE4Q0CREGlZl9eKejGbmtgODv7ZFmuR57LTPSyPIoA9ZD+NgHkJExA90h 9maTr1Lqi1VYeBQxNGhlviDILTKOX9AnnnY0QfAzXOHdMcZ4v2g5jRGr26gon6E4MQEe OQBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706578938; x=1707183738; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sMNhWdXKrsGXbbTndUjwna9Z9KC3QLUt3pRgP5ry3e4=; b=D513K0grTLt6LJ2GgObMfig3pYvzH/ZTDNlaWIEo5yuTYfezA4gOhehbpPzK+L/+rl SJyerRDjUNbakLFmFDqPQ7ddmz0ielTNihz+PoeD8f7xllh/KhGynrnO16Z/wxaT+i7+ WqYKwQt7GW8wBYZ2kDLnDh0r6nLYUZoAiGhsHXnJQpYJkOWovqqx+tzbqtvheQkvfflq zIexIIvXuDyFh7SkkURv8qdOyVGdTV8GpVl2OTQRJKcVy+xsYDSAyya20kui7b2jBZoH pQCwkXqF1uwpl+k47EYkar5qAHUrTyJ79N+Zrnl7N6u1nb0J2R7p+AGydT3yekcFpcv0 SDew== X-Gm-Message-State: AOJu0YwtUss9vl7Qx0uHFFRgaxk/VQHGrnqwcssjYchtTqM27JKCbrXW kn27/6ksPfo48rePV1Z4viC2UfZDY05xTXJf9DJ5Grgz6WwnnyMNPkxRl+lTEgs= X-Google-Smtp-Source: AGHT+IF5MO6AEMmCAsk5IQGTGkKhQ4HvnX3tReOL/xtjiCFFl+s4iNpGpwrLVsQ3sbMAj+NPQ5HOgA== X-Received: by 2002:ac8:7f0f:0:b0:42a:aaba:73cb with SMTP id f15-20020ac87f0f000000b0042aaaba73cbmr2427380qtk.74.1706578938767; Mon, 29 Jan 2024 17:42:18 -0800 (PST) Received: from localhost (2603-7000-0c01-2716-da5e-d3ff-fee7-26e7.res6.spectrum.com. [2603:7000:c01:2716:da5e:d3ff:fee7:26e7]) by smtp.gmail.com with ESMTPSA id y19-20020a05622a005300b004181e5a724csm3357547qtw.88.2024.01.29.17.42.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 17:42:18 -0800 (PST) From: Johannes Weiner To: Andrew Morton Cc: Nhat Pham , Yosry Ahmed , Chengming Zhou , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 04/20] mm: zswap: warn when referencing a dead entry Date: Mon, 29 Jan 2024 20:36:40 -0500 Message-ID: <20240130014208.565554-5-hannes@cmpxchg.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240130014208.565554-1-hannes@cmpxchg.org> References: <20240130014208.565554-1-hannes@cmpxchg.org> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: 4aw6tbop78xrzzet8fptoc8aonsx1yta X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 7649A180006 X-HE-Tag: 1706578939-864391 X-HE-Meta: U2FsdGVkX1+K0fWH1UUQUkH/SYUAvX1hq/3Q6NZyNhz6eJ9U1Zz7IG3CyqjQAa6zoCN0m0WxvOVPZFDGqR50aZU5Skck6Jq1W9paQTEC3IwbPSJMvOydc7HxUp0booCCHYk4LLRLZwhJDTiZpbBdfNn2SalCaP/jBjA3MwzdBzWOcP+01Y+rwKjncbErvDpLq7vSqPAdYLLGT5Qi458kLQmSc9wQ89q6CEzrC89W4JEVq2tzSaUuCToAxMkmiYGlsSKTjVQRZmEIfYwSk7ft7QZwwSODHlfT/F4CsTKv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7HCysDRV4m2/6/iIHfzPxb4D1ySRfu7av4ZL+ScKPpn943RGneNci4oCkw6P8A0C8h+HImgurbpXRNE53xmA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Put a standard sanity check on zswap_entry_get() for UAF scenario. Signed-off-by: Johannes Weiner Reviewed-by: Chengming Zhou Acked-by: Yosry Ahmed Reviewed-by: Nhat Pham --- mm/zswap.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mm/zswap.c b/mm/zswap.c index 9f05282efe3c..0c6adaf2fdb6 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -542,6 +542,7 @@ static void zswap_entry_free(struct zswap_entry *entry) /* caller must hold the tree lock */ static void zswap_entry_get(struct zswap_entry *entry) { + WARN_ON_ONCE(!entry->refcount); entry->refcount++; }