All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ozgun Kultekin <ozgunkultekin@gmail.com>
To: Coly Li <colyli@fygo.io>, Kent Overstreet <kent.overstreet@linux.dev>
Cc: linux-bcache@vger.kernel.org, Ozgun Kultekin <ozgunkultekin@gmail.com>
Subject: [PATCH v2 0/2] bcache: bound the btree node and uuid reads by their buffers
Date: Tue,  1 Dec 2026 01:43:14 -0800	[thread overview]
Message-ID: <cover.1796081695.git.ozgunkultekin@gmail.com> (raw)
In-Reply-To: <20261128033609.42213-1-ozgunkultekin@gmail.com>

bch_btree_node_read() and uuid_io() read KEY_SIZE() sectors of a key
that comes from the journal into buffers of a fixed size, and nothing
checks that the key fits.  These two patches add that check on the read
side, one patch per read path.

Coly, about your question on v1: bcache never writes such a key itself.
Btree nodes are always written with c->btree_pages pages and the uuid
bucket with meta_bucket_pages() pages, so a cache device that only this
code has written is fine.  The bad size has to come from the disk, with
a jset checksum that matches, so it is a device whose metadata was not
written by bcache or was changed later.  The jset checksum is a crc64
that catches media errors, but it does not mean the fields are sane,
and the kernel already validates these keys with
__bch_btree_ptr_invalid() before it uses them.  That check just does
not compare the size with the buffer the read goes into.

With such a device, registration today reads past the node buffer
(KASAN: slab-out-of-bounds in bch_bio_map() for the PTR_DEV >= 8 case).
With these patches it fails with "btree node too big" or "bad uuid
pointer" and nothing else changes.  Tested on v7.4-rc5 with KASAN in
QEMU, with a normal cache device and with modified ones.  I can send
the small script that makes the test images if that helps.

Changes since v1:
- Split into two patches, one for the btree node read and one for the
  uuid read.
- Dropped the __bch_btree_ptr_invalid() change in extents.c.  That
  function also validates every btree pointer through
  bch_btree_ptr_invalid(), so the change reached further than needed.
  The checks in the read paths bound each read by its actual buffer and
  bio, which also covers pointers with a device index >=
  MAX_CACHES_PER_SET.

v1: https://lore.kernel.org/linux-bcache/20261128033609.42213-1-ozgunkultekin@gmail.com/

Ozgun Kultekin (2):
  bcache: check the btree node size before reading it
  bcache: check the uuid bucket size before reading it

 drivers/md/bcache/btree.c | 13 +++++++++++++
 drivers/md/bcache/super.c |  4 +++-
 2 files changed, 16 insertions(+), 1 deletion(-)

-- 
2.39.5


  parent reply	other threads:[~2026-12-01  9:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-28  3:36 [PATCH] bcache: don't read more than the buffer holds for a btree node or the uuids Ozgun Kultekin
2026-11-30 15:27 ` Coly Li
2026-12-01  9:43 ` Ozgun Kultekin [this message]
2026-12-01  9:43   ` [PATCH v2 1/2] bcache: check the btree node size before reading it Ozgun Kultekin
2026-12-01  9:43   ` [PATCH v2 2/2] bcache: check the uuid bucket " Ozgun Kultekin
2026-12-01 10:07   ` [PATCH v2 0/2] bcache: bound the btree node and uuid reads by their buffers Coly Li

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cover.1796081695.git.ozgunkultekin@gmail.com \
    --to=ozgunkultekin@gmail.com \
    --cc=colyli@fygo.io \
    --cc=kent.overstreet@linux.dev \
    --cc=linux-bcache@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.