From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.173 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796118201; b=B1DMtJy5o7jPGR2MZxUdjb0LoVpYuaAbeaf9j75Guvy1Eh955dpwaDDF4JqYKf0wDwb5 4bhG1TU8L6lM+w3swiM2SvFR5dOgcfuJAeNQLktdC6JHN/xrDGPufT8lfhT4E1SP/R5sK nr8fFxj8raSbb4LpPyhW4qAG/SsPunpzfRe7lJicCvHPJBgYvE/hx7VMuvbSQ9tE32qKk wuXu0qie+RSNqARnxjpDItB3+RnE54k2IKReWmnQ2esmuNS5aURix95lecmtmbtSoKoaB bVRkrFHTG896O2qykj5MvGwbaJt1J+MTijWcqgsru+4ZkJ0GKEsVzXCY62LW6LKw9ug== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796118201; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=yrW2SUfttMI7hrzI8JCryYcGPKj2ZNc6QG1a99T6Aj0=; b=cYqnrR849nw+EFWO4mXDIklf0QhyzrfYO2IyiNfbHe4bNFeuJG7iW5/xWZ9evacUvNF/ vmMizIAXs4dDh949ijynQ6oqzPfcAaFNfqP/lvzoTlKLGAQM4KokP5VJ5EEpFbwGjF3wB a1Vljbpo2dyBZw9gb7HzFJtlYtsrmNaqcq0bpNX5m36up53fwIsb3z5uGnnPWaTcxctrP GzdS1AsBHp92YvOObrq20wu/fIWohoVVOEKTYIJfVU1iStDn5l8hg/L3Y4HqW1xk10ueA kpw6G9yOLSSWo3VEGytdLOyc2lzNinIqdnXXCDwl+sfH3lRUVun2g5RpHQo9LClWH6A== 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=jJCjeo8r; arc=none smtp.remote-ip=74.125.82.173 Received: from mail-dy1-f173.google.com (mail-dy1-f173.google.com [74.125.82.173]) (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 0A98A606A31A for ; Tue, 1 Dec 2026 09:43:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0A98A606A31A 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=jJCjeo8r Received: by mail-dy1-f173.google.com with SMTP id 5a478bee46e88-38699cf08dfso15906192eec.1 for ; Tue, 01 Dec 2026 01:43:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796118200; x=1796723000; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=yrW2SUfttMI7hrzI8JCryYcGPKj2ZNc6QG1a99T6Aj0=; b=jJCjeo8rm1Nl5HCTjsN1gyAttO5rDTsoWSZ2IUxEJw5ylpa0lw7CMrLyjEo3zKgVlv buSePIm1fsI9bIMHVhkfXUK1DjXzHVNJPrdvAVrErIydOMyZV5u0q4IzvsnUqNnOt851 R+tEp7AjYkitB0f1toJIBdCtFRX2/s1PGcetSPTw8xbVwDfMbXzQ7o1C3QLWHCPmX3Kp EFfbyRRHO0ngXwpVN8PIcpZbe5kkvW+e452jLC7DoUkzH7III8lpyCfFdVAaJpTwz/mw kGFSOYbzNu15ILVuoNjgbPAM09DtjXRE78NYlkQqKTzPxpUe1AwSHFM8VCeJulRD2U7D nhcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796118200; x=1796723000; h=content-transfer-encoding:mime-version:references:in-reply-to :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=yrW2SUfttMI7hrzI8JCryYcGPKj2ZNc6QG1a99T6Aj0=; b=E7FJjaQLJ4vdSNgwHqkMfnG6nSmHjXR/Ci2+cw9rsgZxswzuouOLjSy8Sqx+Xbw+Q6 cEvkMg0K0mWxENu2JLqXFosU8mC1PObusAGZk90TfPwat3gIYYNl997woAR7ggDw4IRV SaqIprkVsf/FSvx1YFrxQuL21EQTQ0TqRhbygOV+HlNFrrhAtwa9lgEaHzE7SBtM39Rt 7BX1ui7fCA+RvBu6RobLy+k9AwtlFDLsHhdcHwSgiuQ1zNjXyA0As0haxyK1qYnysoXS vONpfCHwdsF4WqE1TyuI4uY3nIVfoAtTLWBtNhBcov7H2KWO4DouNkmmNqhlBO64iImn 8HYQ== X-Gm-Message-State: APuU4Z/EscebQM+d4B8F3uQcDp2G0Os8CxWoZDQqsC1/7CK4ppifvS0w maAdZmp6bxjdKI1F6MdfMB5NVJaN86H+djSmlpI5JbtA+JK9Zxqq5kSlhLix1v6A X-Gm-Gg: AZFdTZfhCSsc2QM/R0f0Fpj0m9XM0AFSQw5vhZ+kSGMihEeo01RUZM/eYJ6N33qfVcI 6UDcctK+ZBCUleRgKrXGfnJv/DWbv4k53i6hugkGprQ1K1/0hmWHGOWTxxeZLzhrF4SSNpaAeLh jcvlI0itYQGiFyajRTyFqfbHybogOjN0lX863iAtlOa2MIXW/K9lC3TArsc7B+aPN7QuJdhbsa1 0xi364L8gfh9rcPxpfwi4mQ2kM6b7o2i54+/qIP1w7pS+wZ4jAisjpbvaCI8A/ZOx9Dmn2Q5RBl csdF9xJueGU+mQX13NUV7t1HfEPf0bN0QJBwhGCBuiGQvLTRvE6gPu4ghEOIAFozbFcVAohZTr8 PT+gBLWinqXWnvhhbESKRpForj8oy+Ffo2ak+mrPa67eBJcb1xasW7ckwqdlEtxP0hdk/gKxw22 UeoE7qI9cvyaWggszemxSCDGOB+xryG4Txj8Nd31dqZ/ZLlQgmFf9IUcsVrzeg0CVqgX+RB1EMA fE+qKGFpNgYH2b+xefc9a0Uv9lz87UTvuH6nbi2BiMDksRZ0/EdIkl+jLvbb0SShMYgyHRiCm5p 685Ki65SZVa+S+n0L47LnyCHo4z6aBBnhXn/8nze2lAY+haOkrFulZX+q8AjoOnGiPBGtEJctAj n9Z6TyS4FLp+9kd5kI4W9TqA5LrLwpQ== X-Received: by 2002:a05:7301:7107:b0:386:b494:8642 with SMTP id 5a478bee46e88-386b494879amr25811675eec.13.1796118200028; Tue, 01 Dec 2026 01:43:20 -0800 (PST) Received: from localhost.localdomain ([2601:646:4300:d042:f49c:45c4:c676:a80f]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-386d605c894sm49142650eec.2.2026.12.01.01.43.19 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 01 Dec 2026 01:43:19 -0800 (PST) From: Ozgun Kultekin To: Coly Li , Kent Overstreet Cc: linux-bcache@vger.kernel.org, Ozgun Kultekin 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 Message-ID: X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261128033609.42213-1-ozgunkultekin@gmail.com> References: <20261128033609.42213-1-ozgunkultekin@gmail.com> 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 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