Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp846640rdb; Mon, 29 Jan 2024 23:27:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IF+SoN/R65rWFKlN4YyUbJr37dZCvjdHAKINcyB73mvJe6wUk3pJPRhU8RDpygg81ND7vpU X-Received: by 2002:ad4:4ea6:0:b0:68c:5c8a:41b6 with SMTP id ed6-20020ad44ea6000000b0068c5c8a41b6mr1874059qvb.13.1706599620520; Mon, 29 Jan 2024 23:27:00 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706599620; cv=pass; d=google.com; s=arc-20160816; b=YNtF6Oa6fSmU3ubJ8B3chBOD4/VQL+r2IoK/ZclYr5Xxk2N18UnHOdyf+30ewwiG7f 8F263XRHNwti9wYEKbSJKa5xfJBGRQRes15T2h0DebXNLMgHzxhpQnUvlAkVNT5+Ysut IkplmXdNEzLrhalFdnqOAsXNG1I37Tab+GeJcqigTmRmsrIlsBaTA1atR5N7E+f1E5oZ xTQiAihfNr8c3e4i0rE/Zys61yTWIFFT80f/tOutJMaPtL7VD0pYvrgelQUS2zVdZ4aZ IirwA8cG0Bi8ZUtr/4iIautxxEqTTe56i78rPmYRgz0dqrniJyZEZhUM79QgEKQTIgg4 GYMw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=kO5pTcen7pGGB1LFTLolk2AtehNCG9X/iKJv3c8ZvhM=; fh=nQ58/qv1uOygkFz0vvydh+mBWY2DyJCHMRDNyKQnfOk=; b=vu8Emoo+KORGql7yrh88lE2ZFbaY2iHLd4hiJfqK02aWsVSMeVGLTzgBFCsOk/xygm iaGnMfXWEghiLQmDu6UduJPNBkIOhGf/pptpFBTSAY8QJoyoevRljPOVXH7uJ2gScxP4 d15WWBk5yNQP7wWy1wZypyLNVq/O9fJofOxIeeBe8wdjlGKTLXFmo5YFHb3Ingrz9TjF +SYQHy2srHIbpjDF2vH0XEiDBSR6FeONd0KdByDVc6+sQo+fazRSVNY0D1KNFzcPHq+z nIHxWV7FpJnTQZO42ACi/OYu1B9ZIRvXUWA/adpvMiFnqdxCbI56jn+U+ilqxbfuXnDN 9qpg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=UqDryXnL; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-44043-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44043-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id i9-20020ad45c69000000b0068c61af4165si715005qvh.440.2024.01.29.23.27.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 23:27:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-44043-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=UqDryXnL; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-44043-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44043-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 490FE1C251D1 for ; Tue, 30 Jan 2024 07:27:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DD8E453E3B; Tue, 30 Jan 2024 07:26:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UqDryXnL" Received: from mail-vk1-f177.google.com (mail-vk1-f177.google.com [209.85.221.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7D97653E1A for ; Tue, 30 Jan 2024 07:26:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706599614; cv=none; b=LcunP5YeqdrHREuLgXz1G0EpTIVuH3xoLpPMlyo8Sx61DhwGrAACJYJcIWN0G+3Cm7T+rj1wu0/xLxdORUpNFYin/4FicEIvOTbeo+MwotpYqqNhKM5W+EoPS5Ewi/9ouWYMF8aO9bWsp143QnRoAPuTgHc7Z7j3SeswqSSbL7c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706599614; c=relaxed/simple; bh=yLjQhS64+Wb6ybZ4ZTCbHetSrbH7ZGJpekaaEOc0yS8=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=Fkjx3AVYBlKlIhqxS59Wk/mTRIBQ/eYbEVSLxgHvWTo6L5xCm1o3D+/i/Vd4dMFyxsOLv96RiOwOGHcMUpaRjNkImk08Hhq5AMfysW3V0c9RrKW1e1pKayxDNnxVM+9HSWUmfWVEodrpRIRCc1CfROxx/J6TCRWax5NLXKLcdOc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=UqDryXnL; arc=none smtp.client-ip=209.85.221.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-vk1-f177.google.com with SMTP id 71dfb90a1353d-4bd87fd64c1so953043e0c.1 for ; Mon, 29 Jan 2024 23:26:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706599611; x=1707204411; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=kO5pTcen7pGGB1LFTLolk2AtehNCG9X/iKJv3c8ZvhM=; b=UqDryXnLxFRrZuUZ5TeEv3MWZKBKVgeSOoRfUcQZfn4QiG5tL9eFHD5HxNEO/+4kaY 6dsIiVoOUQBaHl5G9XL7NZU/19tIe/Jw+0NmCzUxM5+vw1GkjOND2edoj0mU8SF3TB9s pkYLA49xoVQwSfEaSsXuOGPz8jsO744IEx7SVLzU6GSpc4lGsid1kvcPW2UMVPNCDArT GiKhUympVpsiP9m3tmjVy3ru9/zx2CcB7HV7bU8tkGWpMGB08jEXH58vfhNAMr+WinI8 IiGvvtO+5xob+xkydKaAzaJWnKdCfGbvxY7yyVnwiGQ0wps0lqRqIldqR/kFcIP7d/0Y HJdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706599611; x=1707204411; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kO5pTcen7pGGB1LFTLolk2AtehNCG9X/iKJv3c8ZvhM=; b=Uv7gYtEJJUODxkcP0E9rJjA1+6u9LXFvj3lrxN/NZ0f3+6f7fYEHCg4tPUpoB/xOda tXB/HU4BN0mcewDLXoTW/aJRQnybMv1e1+6AB8KwVUbPfNIE9xfRVzg7acXHs2Q0rqBR BRkMyIWyGDIVkIY2KvqJYwt/mFQjCucFKHEwGlpwSrl9WwW2nwk0agBddbSly05bar30 wSmQr2yqN8MiYSVqUvVFh5aZ8usKTWAq6mHayWnp4HioSMKNe1yn4bevHt3tx1pUnw4q MmHdrGa9WbhigJFFKKqXJh4CozxE1iMpMWKc+4HvAOyy6AGqPALdzt3TCEDV4EiUdWv2 nF3A== X-Gm-Message-State: AOJu0YyZ4gMCqLsKL48dIoje+gpAC+A2GS1FVYyqzCffsJ3Xc8OkPDHl 4WNHfxRHRl9EG4bnAPp2u9xVT9qYDkbSITLQssOyrJP7Kyb2OqnnUtTfhQzNTyD0Upncr8sKkRM 7uy+zJykJmtvvFtF7frcp25ECAxA= X-Received: by 2002:a05:6122:4b1b:b0:4b6:c3ae:97f6 with SMTP id fc27-20020a0561224b1b00b004b6c3ae97f6mr3896410vkb.0.1706599611143; Mon, 29 Jan 2024 23:26:51 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240130013438.565167-1-hannes@cmpxchg.org> In-Reply-To: <20240130013438.565167-1-hannes@cmpxchg.org> From: Nhat Pham Date: Mon, 29 Jan 2024 23:26:40 -0800 Message-ID: Subject: Re: [PATCH] mm: zswap: fix objcg use-after-free in entry destruction To: Johannes Weiner Cc: Andrew Morton , Yosry Ahmed , Chengming Zhou , linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Jan 29, 2024 at 5:34=E2=80=AFPM Johannes Weiner wrote: > > In the per-memcg LRU universe, LRU removal uses entry->objcg to > determine which list count needs to be decreased. Drop the objcg > reference after updating the LRU, to fix a possible use-after-free. > > Fixes: a65b0e7607cc ("zswap: make shrinking memcg-aware") > Signed-off-by: Johannes Weiner > --- > mm/zswap.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/mm/zswap.c b/mm/zswap.c > index de68a5928527..7f88b3a77e4a 100644 > --- a/mm/zswap.c > +++ b/mm/zswap.c > @@ -522,10 +522,6 @@ static struct zpool *zswap_find_zpool(struct zswap_e= ntry *entry) > */ > static void zswap_free_entry(struct zswap_entry *entry) > { > - if (entry->objcg) { > - obj_cgroup_uncharge_zswap(entry->objcg, entry->length); > - obj_cgroup_put(entry->objcg); > - } > if (!entry->length) > atomic_dec(&zswap_same_filled_pages); > else { > @@ -534,6 +530,10 @@ static void zswap_free_entry(struct zswap_entry *ent= ry) > atomic_dec(&entry->pool->nr_stored); > zswap_pool_put(entry->pool); > } > + if (entry->objcg) { > + obj_cgroup_uncharge_zswap(entry->objcg, entry->length); > + obj_cgroup_put(entry->objcg); > + } Nice catch! Reviewed-by: Nhat Pham > zswap_entry_cache_free(entry); > atomic_dec(&zswap_stored_pages); > zswap_update_total_size(); > -- > 2.43.0 >