From: Ren Wei <n05ec@lzu.edu.cn>
To: Viacheslav Dubeyko <vdubeyko@redhat.com>, ceph-devel@vger.kernel.org
Cc: idryomov@gmail.com, amarkuze@redhat.com, slava@dubeyko.com,
sage@newdream.net, Slava.Dubeyko@ibm.com, yuantan098@gmail.com,
zcliangcn@gmail.com, bird@lzu.edu.cn, ldy3087146292@gmail.com,
n05ec@lzu.edu.cn
Subject: [PATCH v4 1/2] libceph: reject zero bucket types in crush_decode
Date: Thu, 4 Jun 2026 11:18:46 +0800 [thread overview]
Message-ID: <8fbe4d61ba313a26.1780473720.git.ldy3087146292@gmail.com> (raw)
From: Douya Le <ldy3087146292@gmail.com>
CRUSH bucket type 0 is reserved for devices. The mapper relies on
that invariant and uses type 0 to identify leaf devices.
If crush_decode() accepts a bucket with type 0, a malformed CRUSH map
can make the mapper treat a negative bucket ID as a device and pass it
to is_out(), causing an out-of-bounds access when indexing the OSD
weight array with a negative value.
Reject zero bucket types while decoding the CRUSH map so the invalid
state never reaches the mapper.
Define the reserved device type as a standalone named constant instead
of mixing it into the bucket algorithm enum.
Fixes: f24e9980eb86 ("ceph: OSD client")
Cc: stable@vger.kernel.org
Reported-by: Yuan Tan <yuantan098@gmail.com>
Reported-by: Zhengchuan Liang <zcliangcn@gmail.com>
Reported-by: Xin Liu <bird@lzu.edu.cn>
Assisted-by: Codex:GPT-5.4
Signed-off-by: Douya Le <ldy3087146292@gmail.com>
Signed-off-by: Ren Wei <n05ec@lzu.edu.cn>
---
Changes in v4:
- define CRUSH_ITEM_TYPE_DEVICE as a standalone constant instead of
putting it in the bucket algorithm enum
- move the remaining type-0-to-constant cleanups into a separate patch
- v3 Link: https://lore.kernel.org/all/d21e2f97dfe6f250.1780369814.git.ldy3087146292@gmail.com/
Changes in v3:
- use CRUSH_BUCKET_DEVICE instead of CRUSH_ITEM_TYPE_DEVICE
- v2 Link: https://lore.kernel.org/all/3200151429f33554f06ced8a.1780197742.git.ldy3087146292@gmail.com/
Changes in v2:
- use CRUSH_ITEM_TYPE_DEVICE instead of hardcoded 0
- v1 Link: https://lore.kernel.org/all/4ad15b49fbbae00d86dfe12348bf94d45aa60ac2.1779949116.git.ldy3087146292@gmail.com/
---
include/linux/crush/crush.h | 4 +++-
net/ceph/osdmap.c | 2 ++
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/include/linux/crush/crush.h b/include/linux/crush/crush.h
index 30dba392b7302de3e14861f8b769242cd8cbac9e..76bd1fa036538df86d548b1c668163035c30ade6 100644
--- a/include/linux/crush/crush.h
+++ b/include/linux/crush/crush.h
@@ -110,6 +110,8 @@ struct crush_rule {
* straw O(n) better better
* straw2 O(n) optimal optimal
*/
+#define CRUSH_ITEM_TYPE_DEVICE 0
+
enum {
CRUSH_BUCKET_UNIFORM = 1,
CRUSH_BUCKET_LIST = 2,
@@ -130,7 +132,7 @@ extern const char *crush_bucket_alg_name(int alg);
struct crush_bucket {
__s32 id; /* this'll be negative */
- __u16 type; /* non-zero; type=0 is reserved for devices */
+ __u16 type; /* non-zero; CRUSH_ITEM_TYPE_DEVICE is reserved */
__u8 alg; /* one of CRUSH_BUCKET_* */
__u8 hash; /* which hash function to use, CRUSH_HASH_* */
__u32 weight; /* 16-bit fixed point */
diff --git a/net/ceph/osdmap.c b/net/ceph/osdmap.c
index 8b5b0587a0cfa2c437b76c8c87251199efe20291..21cdd33f2945e0c1f45277ac05fda373bf217586 100644
--- a/net/ceph/osdmap.c
+++ b/net/ceph/osdmap.c
@@ -518,6 +518,8 @@ static struct crush_map *crush_decode(void *pbyval, void *end)
ceph_decode_need(p, end, 4*sizeof(u32), bad);
b->id = ceph_decode_32(p);
b->type = ceph_decode_16(p);
+ if (b->type == CRUSH_ITEM_TYPE_DEVICE)
+ goto bad;
b->alg = ceph_decode_8(p);
if (b->alg != alg) {
b->alg = 0;
--
2.47.3
next reply other threads:[~2026-06-04 3:19 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-04 3:18 Ren Wei [this message]
2026-06-04 3:18 ` [PATCH v4 2/2] libceph: crush: use CRUSH_ITEM_TYPE_DEVICE for leaf device checks Ren Wei
2026-06-04 19:43 ` Viacheslav Dubeyko
2026-06-04 19:39 ` [PATCH v4 1/2] libceph: reject zero bucket types in crush_decode Viacheslav Dubeyko
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=8fbe4d61ba313a26.1780473720.git.ldy3087146292@gmail.com \
--to=n05ec@lzu.edu.cn \
--cc=Slava.Dubeyko@ibm.com \
--cc=amarkuze@redhat.com \
--cc=bird@lzu.edu.cn \
--cc=ceph-devel@vger.kernel.org \
--cc=idryomov@gmail.com \
--cc=ldy3087146292@gmail.com \
--cc=sage@newdream.net \
--cc=slava@dubeyko.com \
--cc=vdubeyko@redhat.com \
--cc=yuantan098@gmail.com \
--cc=zcliangcn@gmail.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox