From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 76943280CFB; Mon, 13 Apr 2026 16:35:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776098137; cv=none; b=jDuR1l6C9/gpc+SMCBW95CqZVtq+Ss9/phXhcvB0mj/r3CUS5764TFOXyNPFYO3tJ3sJNIgwIhHNG94wFrwjiOTHzB2Ox9ZRmwX3PqgugD2a9WkCorFA2WmMNRnhX2O9t07B2BFd7kxi8gnT4dZU57t1LQyEUoluIYMO5nqlk14= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776098137; c=relaxed/simple; bh=Jc4nqUyrOUi1Nz4D+bekiKLIc0QDC++Iihbsm7TKSHQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=WQAhj9+ZWz2bTAu7gaqL6/PiaTZc3+sKGalZbKaygvwz7mBVjdLRHoNBYBdmUbJdCZeFKqnGQJ9gcQmghd24J9MWbiFtZi25fV9GYLkxU2jDOg1RZ3d+ggd11ICMKExbnrk/y62Ee7QhNFc7fB/2raMUQDXSeyFvP6A3uDMAbAM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=H5ps2bll; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="H5ps2bll" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D80CAC2BCAF; Mon, 13 Apr 2026 16:35:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776098137; bh=Jc4nqUyrOUi1Nz4D+bekiKLIc0QDC++Iihbsm7TKSHQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=H5ps2bll3FOA7hkTh90vEDWKW5ynlDPs0dp6oPTq0IobVU5jMWnbzdxEXelPJbnm3 0QeCEOpb6papaZ81PORXF62n/Qt7iNjs3Wj492dgoaerCXcgQ9CN2zWPI1HUbIPe4n UqU5AQGIP/Y/r4yXhwVuNGjM5f6WlwKjJFEsKchMa1Dv14fs1ovhApsOpKQQEpgodp vN89Rf+4aZTp22oLcKNxq4vzjxN1nSRjK/96YiF5KBdnq3ArW+bkZncbfC/ZyxXd/u KU8516Fp3Gud4ksfEeOCss/xT43MlH5z6fCxWNc7q5eQhUKb+X9BkX7gk2kvfnY4bF a4T5MognHEruQ== Date: Mon, 13 Apr 2026 06:35:35 -1000 From: Tejun Heo To: Breno Leitao Cc: Andrew Morton , David Hildenbrand , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Jens Axboe , shakeel.butt@linux.dev, inwardvessel@gmail.com, hannes@cmpxchg.org, josef@toxicpanda.com, "Dennis Zhou (Facebook)" , linux-mm@kvack.org, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, martin.lau@linux.dev, usama.arif@linux.dev, kernel-team@meta.com, stable@vger.kernel.org Subject: Re: [PATCH] mm: blk-cgroup: fix use-after-free in cgwb_release_workfn() Message-ID: References: <20260413-blkcg-v1-1-35b72622d16c@debian.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260413-blkcg-v1-1-35b72622d16c@debian.org> On Mon, Apr 13, 2026 at 03:09:19AM -0700, Breno Leitao wrote: > cgwb_release_workfn() calls css_put(wb->blkcg_css) and then later > accesses wb->blkcg_css again via blkcg_unpin_online(). If css_put() > drops the last reference, the blkcg can be freed asynchronously > (css_free_rwork_fn -> blkcg_css_free -> kfree) before blkcg_unpin_online() > dereferences the pointer to access blkcg->online_pin, resulting in a > use-after-free: > > BUG: KASAN: slab-use-after-free in blkcg_unpin_online (./include/linux/instrumented.h:112 ./include/linux/atomic/atomic-instrumented.h:400 ./include/linux/refcount.h:389 ./include/linux/refcount.h:432 ./include/linux/refcount.h:450 block/blk-cgroup.c:1367) > Write of size 4 at addr ff11000117aa6160 by task kworker/71:1/531 > Workqueue: cgwb_release cgwb_release_workfn > Call Trace: > > blkcg_unpin_online (./include/linux/instrumented.h:112 ./include/linux/atomic/atomic-instrumented.h:400 ./include/linux/refcount.h:389 ./include/linux/refcount.h:432 ./include/linux/refcount.h:450 block/blk-cgroup.c:1367) > cgwb_release_workfn (mm/backing-dev.c:629) > process_scheduled_works (kernel/workqueue.c:3278 kernel/workqueue.c:3385) > > Freed by task 1016: > kfree (./include/linux/kasan.h:235 mm/slub.c:2689 mm/slub.c:6246 mm/slub.c:6561) > css_free_rwork_fn (kernel/cgroup/cgroup.c:5542) > process_scheduled_works (kernel/workqueue.c:3302 kernel/workqueue.c:3385) > > ** Stack based on commit 66672af7a095 ("Add linux-next specific files > for 20260410") > > I am seeing this crash sporadically in Meta fleet across multiple > kernel versions. A full reproducer is available at: > https://github.com/leitao/debug/blob/main/reproducers/repro_blkcg_uaf.sh > > (The race window is narrow. To make it easily reproducible, inject > a msleep(100) between css_put() and blkcg_unpin_online() in > cgwb_release_workfn(). With that delay and a KASAN-enabled kernel, the > reproducer triggers the splat reliably in less than a second.) > > Fix this by moving blkcg_unpin_online() before css_put(), so the > cgwb's CSS reference keeps the blkcg alive while blkcg_unpin_online() > accesses it. > > Fixes: 59b57717fff8 ("blkcg: delay blkg destruction until after writeback has finished") > Cc: stable@vger.kernel.org > Signed-off-by: Breno Leitao Acked-by: Tejun Heo Thanks. -- tejun