From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.45 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796452802; b=RqqS3Mwtm3kl2vZQ4+OggrV6ZKUU+QRMZwndpB8+NldFJUije+uijcZ3DcsgXDjYe18u mWVIT9wv12wwYtLKN3Dy4UdF/gXRLTvoao7PWZ+xw7Kjn6+z9N++JmMzCGeuoiB+i3u9q 3fNIPebaBDVhHkaIpq+j+X69cgLh54clfslj1peIlxHvrWcrziJ072zvZ56gcFzN8con7 YNZm653htak2IoHNG2O+FYfAZqPeK6byORt6haZAraqu3QpbAb3R25IIEOULuJdou9sp5 43x1VhKkCk0wEAkJ21fUgR/7Bbj92jpRbkH5g+k901PBgl47CP7pe3KVDMJfn1k+u1Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796452802; 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=zYwtNGe9oPyO+T+wc3Nbu34crFuEAUIudK7l+BZcCZASkczMc8sdrTM7/oKFo7Q7N91k 0XidGbLOlZQy92JU01b0rElS6jgjBUorJZfIEnmrHl5mnyMHtOk9G9XUk5zIhh7Psj3PQ BgOgCGVXGrKTcSmcab3IWkcGyA3fe5KwHUchL7ibR0s6XAZSXS7A6N0CsiRMqNZGdWxSm CXvqAZsEfMkpaEnTXl59w9t9i05L3FpC3Dbx7hQQHWu7/dKBkWAshFpTcoxMH1kkX56zi tKXtzTRz760lyWvXGVSkaxwWiUUWzKZUnF5WD3svsTR+cFlzo5561scS54uQuohrl1g== 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.45 Received: from mail-dl1-f45.google.com (mail-dl1-f45.google.com [74.125.82.45]) (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 5FD54606A332 for ; Sat, 5 Dec 2026 06:40:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5FD54606A332 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-f45.google.com with SMTP id a92af1059eb24-1a3c08d6928so2535283c88.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=cG3ZTmdgYEJBpZx8y2u9Yn9wFAbZe9CGn5vx3/PNJUKN0UMa9bT+ekoGmPOKX5+O1k zkRppdLmsr8FLZS5c89O81FRNwR1VnImTWWLFtmzqwffchis5R597vRlKYIC+ztAT93j 1GsAi7oJuf/GkWsAxhQm1xpZ3azgkk+SAGhl6Ir6nVJHHr+C6MeO++1ADL8i4w9kj+r1 uLySbWLtiZ13YLX+xyBFv9kq7vbzt6r2Mdik5PYkzpt6Ecb7DvjnuPKaYMwDtua/KBMD 7PlrfEmubDmUfubLXBaN7sU9LhM2LszpV3GZOvnF5pIiOy0wdmqLDmOMhubP0fQK6qPd HjCQ== X-Forwarded-Encrypted: i=1; AL+hErEcRQMjkAiTwR1blGKSjvOAoB8O6YwBwpU1PfZtQyib0gfqYqMxYmn1jB70eNqxm4X8TKLDfaM=@vger.kernel.org X-Gm-Message-State: APuU4Z8IEgj0Yz97LUtXdTiGJwrzKmxG1XuSw9V1qlhZ00C6MIM8bmDX gbU9eipA/YiDG5MLyqPg46BgJgWnI4Q17TG5dHTVXSMd+J6YFwLLPc4e0NqYiOQm X-Gm-Gg: AZFdTZfYYPdoyXzZ71I4jmjWHL9/AxCVmZMfjONR4ayw63TJuGL1cWlkAj/Ii8KAegg XE05tSA3bCHb0C44cOrvoxo/gszyrkeMcdN4/aC7xOgytJdni2hYHNKFjplneeP6UtK6ttUqKnF 2FYf2qNyxwVyaMz4IUj4gy4MLBUKPwkeK+kRmxYJGBfmiJ9wnN+nturGBCWs7hVgvLyLQBXw5cx 0pRnzcI4Is9Pnki9qzD/MHmPgUAe+0B18ggh+VT/jXRPi2CjtYelXOI4bLzJIwVrKiPpvGFXK13 1PSOSd1xaqN5XMGsNYrThnboDPOV8p2ngVTnzuscasPcthDjvLOwMBmu2GnW9jzghVxyq8CIErd AyawPrwXofmSWzXYM0yedLGyLb8wrci0tBlNJbgXMkP2F0Ky6+h4BpvoZrxe1UreuVVsHFTU5Id 8J9ki1oPO1+r38ZNPYX655YN6Q9tUQdKw3WeU4V4+FeBWpw3jTY/pvYsrwU5i6szCBiPcpEwmaI asM+fo7jmfZtckR3iLga7NvG1CTPTVeOu1jreMn2hT0JPrcLGMf6sKp3AOaWrpUlcrcguSrCPW4 OqLIrBtWH+OvEHm2fB3oqy6WIgdox7KH8sd4l+YIIJHisU2YJbLX69s/eK9WCEcefGRlX1agFWR nPOzbS75Lu0U4 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: stable@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