From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-170.mta1.migadu.com (out-170.mta1.migadu.com [95.215.58.170]) (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 093F3376BE0 for ; Mon, 13 Apr 2026 17:44:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776102299; cv=none; b=RWqGTB5poTEnTMUnUYbEeVUxWOOH7mf8kXORFJhOJAeXYPSLBmrnKDa9pBz2mFq/5BLfCtyRI1wlmBN5VZffY3cDEdnSBIfjXeVX23csduqKkxyFzzJRBjAhumGzTsQ+Nj9FquauBA2bWe5myHTiNlqJ009Y4qduPLQerdGARQs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776102299; c=relaxed/simple; bh=sOP7MTQef0cqRh+VRrISotffDSTqwCVfwDOGc92oW7Y=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Lakby+FVXI7/ilEd1R1XlE90BfoVM/NHJzS00YUMqr4DNpszzEusQpgMNvQi8I4+xF2LuujPFbYw4Qs6lXt02Zn4BLkVmmLKM5Lgj+i8Niu3RXbQgpQ2vAFZgZZempWP6rNzuwzKz5iuo6NG+nTbkgZiK9lrTTDea0tFDdmoP+o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=kF82xfwR; arc=none smtp.client-ip=95.215.58.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="kF82xfwR" Date: Mon, 13 Apr 2026 10:44:36 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1776102286; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=b0j9S/oeWv9cGrOnlEmdvesYiWMQozAk+6ZeIzA0Owc=; b=kF82xfwRKUDeEAuXqOchwk9JzjnHGoGfLr6ipXkTHA8Y9gDscmQu3i/dgmUx3cPA8uIVZb a4vMT/H+Owd+AsXn3B5FTclx+2LzDPYcGlTlnvfjefVUU4SzorZ631Fwoh1XzU06KX+uM+ TEyj96yOsj7dLckLcRg5oq87cs83K3A= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Shakeel Butt To: Breno Leitao Cc: Andrew Morton , David Hildenbrand , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Tejun Heo , Jens Axboe , 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: linux-kernel@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> X-Migadu-Flow: FLOW_OUT 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 Reviewed-by: Shakeel Butt