From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.49 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796452801; b=vJUUJZQkL+mGJf5/7CLTIxPGlM5gC8mwIWDsu2+PX0VnRBfucwtbXZf1EVMR/8exs3WG UIqE9Y8QnSxk8SaFxinLHHrfF0azgJQXJJExRv74Wb+8bL3gGNndZS1jJ5Q3hQ8B9j6SD Mv4dnoxas4JQAYxwpbPlhTIjzG47+3F0y/2cNtAITv7YRh+aLhKcS5+fqoKVrQ4WHdTgP o01pjwMQXFvqYz/LpobZW2I/vbkDKv1emSoI+Pbe7q4PAfPHPU+QnyLg1xwq+uEoK9D3Z zEU39Qr8AJ5QmeTjHZEr9KNJtzBSTQhHZwinfL/2XhhEdz63UhfUmDC+y8tQPMThFHQ== 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=DBi85hLaqUemfBYXpXZ7j5eM1faOSBiTsu2A7EwpU0NsbO0QmQtDwgsuqnl6vMTa1LIb GGCy7NlydJgkq82a7Iv5fVmIFMjrLi+SW0df2aRgdK4QNMXIzqPPnf1Tm1l2zx4+NuWj1 p2QYfcTJjNG2tDm59vYbA2t86zIGcKBGPmygvvB6LXJW73w5V6pwSwIfd5v53hcPvoAmW TV/jwZDyKJOymRDkNzcahCGRegawLYo1FBgmdu27w6QEOiY2xBP0ntcHfZ5Y1P8ltfmtr YFNpIiE5xw1nMZEVPp9oEs2ukRq2iUx1PKqniohr0JjGpfZJ5Zk66Ez/+qsRabLgI9A== 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.49 Received: from mail-dl1-f49.google.com (mail-dl1-f49.google.com [74.125.82.49]) (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 59235606A32F for ; Sat, 5 Dec 2026 06:40:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 59235606A32F 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-f49.google.com with SMTP id a92af1059eb24-1b5d5f9938cso1934195c88.1 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=h/EcwICe7hEAiNwGMNddWujoM3NtWUqXU5U8appQOE5Ge+IJJ1ug/y5wwYsv+W0PaV 5qSVT2Lly9kK8CCXp9R30eBpc92xFOv7Sfrv5FjcYlbBzkzC1dhyol0HwxO86Zj0bNk0 q/HNhpUdS2bq2xrXr5XMOGCBSOlf99hbS3xiQJIJnNxOznomUkBdiuHOPS2TdpQX7Grz 3rjiG0eDA+1R2T78+NplmE/eF53QFOZAlMKozmARDxCLA5GWnY8jqero6ZAE6MpCdevQ Z3OtDYTqupTD+4k+MK22mpWoBwxj1HjmW8ldZ5dPtrQrP358J3R6Zbcfqu3UakZACXt5 aZoQ== X-Forwarded-Encrypted: i=1; AL+hErF7mC29YcajuykSOviIxQ7TeGW5XU6uW3dGcqzT1Ll/usEDZedJXCSQHC73ZXzjeeFy2JofLp81ZFfDbVM=@vger.kernel.org X-Gm-Message-State: APuU4Z+EicMXa4nBdDJmJkxcpoNNP5oRlJloGYYhvvT2Njk8SbC6dliu Kg3KuJ8cGpovlDw/On1JgN0mxd7gntP1kY7LteZ5ekUmx3fz91ikJ5AP X-Gm-Gg: AZFdTZdx8H+xFvvHTbdisGzXvcaKYHcsyMhrvReB113lQXRVdClM6Tcowb6tketCuu6 3JX8/AZEXNfJzRimDltpVsSPtMsu0LJpRLdvFwFVgTfZdXfKd3FgSLWcBlZygftw0WGsizq4/r1 DwwrpDEdKxuRedv4NiJ49g2wFNbaR8myP+VokEbW7Msb5JE++akP6J+NLa47EcufmyRKZZR+HXW yIhLo3h4UpXvi6/2TyaXl/wXfzu4t2ppemr6TCtR27+m/G0FvEimgNqffs2lfqNAV0jyL/P02kt BUuQ0V744x0UvJFtgfgZpvUU2cMSFPTdqzkswUwE+QW7dkiXRqbyPx2yLwkUf5lyOa1wVoHEevf j/GP9ltXfsVKFHajWPjQKfz47QebzBFvzVIwtoBGOb0IKGC/JQQpiD8LjTZ+5Wp9UvCHfn4dVs/ 4+ZlMleaNi6euNgpjLWlylwQx4DcFjJOCAF0Sug68aXPc4NjnLTiPRpGOGaR7aKsLIDyA4PVQFk 38ufhOW7PJxhBxX+6hDsA6d8C7xBer1IEu2HTjn7ourrYYNYzsyIG2ArczO5IIY2iht/JKoQ2nF Vl2u9qFwdtSR8cen0pExcB6LmodtUzfEIo+XpXySplXQm7xaMMvjeiU1kVN6StifdhyKNudxrgU 48hAqZ5qnDiw5 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-kernel@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