From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.44 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796452801; b=LHpPXBrX0IUz7GzZ6j9EQl000rmLQrgU/uKgFBqORGIGk1+ND24nXgMYkKpXzVeP5U25 zdyBB7lg0FZd8wH8tr+wV/PbCaDBHNSSbG/Ub1QcrbOdzWdQ0HXYhOxkpMU+OrkenORWC ZijvogRecjP7+WEVETPtMT2k5qkoMcOOcVUPAIqg9hbnGiiWQZ9QyyFUWdbY4KTT+YDf4 3q7j+7wbAZ6edaZhBDVimrFam8ym6i67pxD9pvJSg9yHk/108/XlSuKM9AyPXlxzEf+eH GM2ptiBUpxGSULHb8m4uOdWLfvNkgfTMTDtv+/URO1dvBk4CDc8SaawjLvjtparC4+A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796452801; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-Id:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=va0HghzqExEGgwsPdpUwDHRbyiP/yGEQXHnfuaoiNp4=; b=qjlmsxw0adtaKgni/7TUYPpyMUdL/a8BW/n13jCKV6aO1rN5/T0R5RYstKO8jWH0c0LT YRAeji/8azXyNtSVGFuj8vpmJgTi0lwV/yMAV1ekO8TbPBJb7rpwQ1x9oVjyHL4WXPSAw ueAA/3vryM2gNt36LY+KyOc7wtYnfF96xa8c61eDogEK+R171U2u3I0LEPA/peN+POmVt +bYAUX1edRqAr3pkdArzCz7cgkcbi0GkcaeFMT/iUE2dQCdeecJPjSNPj36KTgB2Nk2Nk Ab3f8PeZCHvuz2N7R6vnbB7gPEC3e+kZB+2uvOaQKTluLsw9tAggpgjCZQ3wJjcjzhg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=aeIDALjx; arc=none smtp.remote-ip=74.125.82.44 Received: from mail-dl1-f44.google.com (mail-dl1-f44.google.com [74.125.82.44]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7034A606A334 for ; Sat, 5 Dec 2026 06:40:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7034A606A334 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=aeIDALjx Received: by mail-dl1-f44.google.com with SMTP id a92af1059eb24-1a3c08d6928so2535282c88.0 for ; Fri, 04 Dec 2026 22:40:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796452800; x=1797057600; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=va0HghzqExEGgwsPdpUwDHRbyiP/yGEQXHnfuaoiNp4=; b=aeIDALjxGpemY+s8CQN0Da0Tn/wbg6RLMqbzrK7wENrCpoHOZkSG2QHBa5PjMkxLmG rISy9BqNW52wypROShmgHifsHkCAUn+6BxOuQW8GPRVwCQfcGNiVKbyMN0s6vOTQYMps hUX8qe/fKAgAtaaj3FJPBwAe8fr2A69FTnlLbhlr7BMH9ld9JPQlWrPqWaQmOyewHslk 6FZs6NfPOxV5HdFHFfZBnImEuVgUS7syqdlddxSKjSN7FGiJJNISPmriCpJ51WzX7rk9 ixEQAIfpCvruwK6NAQK+lKwL4AQayO95uGrkqdvN0ZU33s3kXVuk0TJZqbtu6Bp1WeQG b0EA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796452800; x=1797057600; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=va0HghzqExEGgwsPdpUwDHRbyiP/yGEQXHnfuaoiNp4=; b=IRM2tAhxGcouJozZSEJI06Tm6CgsBbMRbBEAxU1ESzNlYCLhEPQ8QiK+QYDRHQXJ7g HvlIO0qoRf3htF2vn5j3HrhypI2ihUlvi0FXTuTAEENRcguwdrLxSkHId0EeJtympJJM js2HCy5KblI9FrIoG+GcoOqzxpj2tetSa30884zn0fXeZfLg0qGUa0Mr42MKswid05PD WRF2QZWQ0PHUAuqIH7/97bHYEmfW8ldNG4s/KeyCWUgPpTw2en/K5atLlnwH7cyuE4UM ZQDeB9JwXR6TpKAvowalvsbP9NNkLsmX3i0KTpJ3byHYiYCdbAEeWKY7fOJj8hvRlcPC NSUw== X-Forwarded-Encrypted: i=1; AL+hErF1nb5TbmzUwEdZIk2z+RAHsF+lWd0s9obTh9TwWTZFyqWuPrESPhKiUZkjbdODkn5SGzKdOVLZYbXzLyw=@vger.kernel.org X-Gm-Message-State: APuU4Z/Rmu7OJaRdPI16LJLmiYLFGQIPAkwtEAjdTeeIXO8wA4G+Odtm FgjYgCu6nR+qn0OK+lGqetCgRhsvClQT0hcmZ01mEwSk4+CRhqmjtsal X-Gm-Gg: AZFdTZcjw1R+WKnqwiJ6TGIpkTndGa2Axz5Ncf2SAdLScOd9+DCeFNFHPP3QpM6ypLd RUg5P+4V4cUD5nM/75cPyeWXfjviePCkjumHQsSJha3AfCfyZXaCp7ZDbE9V2QX1yL02qO3eDlO NleyRWE1q0mvqoUxUTJhNNcIabKa0kp4aJT4UdR70Wgdms7VNp6xkAZmv9z2WLSFav+ygEw1rzy a8e17Pryahe+07s/1ZJuTi3vHFpb75qyEx4xDq5QlalAKwDPwU2sXqySNyZqsrc2DmRh3LdTkjr hiu+amWuZ/Ke67DLt2n5Xs7uOeVa8JjXAxPUrmsnuNoIE74SL2MG1imlQUDzSPCD3iXgownorku t/SlBh3wTnWVjDXa9QCnN/Aw220QggcvPUMx7MLS6oNZjTiwiGKdyaiS2gd0XC8EJGRRN6J4CJD F8ycRongVnEC2Gimu8VEg5JVhfJPQOvINWs00i0F3X7eZVzVnmWIwc8tFIc0S1fxj/cCJ1SjVIm NYSGaDWHF9f3G0JN1VpGSdkIgmLr6xdj+p3UOWe5zSau2niyfXU46Lju+SbiCRoKEqgTHDNlgST dVw6A8PtoGVfaENbTKvtADtgbPf8X9tj1bNDldy3MP15z0QpnF8Crq/X7jkANKFjkG7WdosCyvi L7CHKjj1q4VhL X-Received: by 2002:a05:7022:ea81:20b0:1b2:4e29:92f4 with SMTP id a92af1059eb24-1b5d72708b5mr3410831c88.39.1796452800454; Fri, 04 Dec 2026 22:40:00 -0800 (PST) Received: from localhost.localdomain (wood.seclab.cs.ucsb.edu. [128.111.49.37]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b5d646217esm11927715c88.11.2026.12.04.22.39.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 22:40:00 -0800 (PST) From: Praneeth Balasubramanian To: Coly Li , Kent Overstreet Cc: Praneeth Balasubramanian , stable@vger.kernel.org, linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] bcache: hold invalidate_lock while reading the superblock folio Date: Fri, 4 Dec 2026 22:39:50 -0800 Message-Id: <20261205063950.2525443-1-praneethb2002@gmail.com> X-Mailer: git-send-email 2.25.1 X-Mailing-List: linux-bcache@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit read_super() reads the superblock folio with mapping_read_folio_gfp() without holding the mapping's invalidate_lock. That function documents the lock as a caller requirement. The read path allocates the folio using the mapping's minimum folio order and the block layer then fills it with buffers sized from the device block size. Both values must stay stable while the folio is allocated, inserted into the page cache and read. A concurrent BLKBSZSET on the same block device reaches set_blocksize(), which under filemap_invalidate_lock() discards the page cache and installs a larger block size together with a larger mapping minimum folio order. If that runs between the folio allocation and the read on the bcache side, the reader keeps an order-0 folio while the block size has grown, buffer allocation for the folio fails, and create_empty_buffers() dereferences the missing buffer head. Both racing paths require CAP_SYS_ADMIN, so the impact is a local privileged kernel crash. Take the shared variant of filemap_invalidate_lock() around the superblock folio read in read_super(). The page-cache read paths (filemap_create_folio, readahead) take it shared as well, so this matches them. The lock is dropped right after the read and the folio contents are parsed without it. Nothing else is locked on this path, and the lock is released long before register_bcache() takes any bcache lock. This was found by an LLM-based audit that checks code against the rules stated in kernel comments. Fixes: 39107ccbc696 ("bcache: switch from pages to folios in read_super()") Cc: stable@vger.kernel.org Signed-off-by: Praneeth Balasubramanian --- Notes: This was found by an LLM-based audit, part of research at UCSB SecLab. An LLM turned a kernel comment into a rule, and three LLM votes checked the code against it. The fix and changelog were drafted with GLM-5.3, then checked against the source and partly rewritten with Claude Opus 5.5. I reviewed the patch and take responsibility for it. Testing: builds without new warnings with W=1 (x86_64 allmodconfig), clang 23. checkpatch.pl is clean. Not runtime-tested, and there is no reproducer. I did not write a reproducer. Other in-kernel readers of block device page cache, for example read_part_sector() in block/partitions, also call read_mapping_folio() without invalidate_lock. This patch only changes bcache. drivers/md/bcache/super.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c index 97d9adb0bf96..50b36067d639 100644 --- a/drivers/md/bcache/super.c +++ b/drivers/md/bcache/super.c @@ -171,8 +171,10 @@ static const char *read_super(struct cache_sb *sb, struct block_device *bdev, struct folio *folio; unsigned int i; + filemap_invalidate_lock_shared(bdev->bd_mapping); folio = mapping_read_folio_gfp(bdev->bd_mapping, SB_OFFSET >> PAGE_SHIFT, GFP_KERNEL); + filemap_invalidate_unlock_shared(bdev->bd_mapping); if (IS_ERR(folio)) return "IO error"; s = folio_address(folio) + offset_in_folio(folio, SB_OFFSET); base-commit: 29beb21c21ada7207692b2d69fc58dcd15dab6e9 -- 2.25.1