]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
libceph: reject zero bucket types in crush_decode
authorDouya Le <ldy3087146292@gmail.com>
Fri, 29 May 2026 08:11:44 +0000 (16:11 +0800)
committerIlya Dryomov <idryomov@gmail.com>
Thu, 23 Jul 2026 18:29:40 +0000 (20:29 +0200)
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(), which then indexes 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.

Cc: stable@vger.kernel.org
Fixes: f24e9980eb86 ("ceph: OSD client")
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>
Reviewed-by: Ilya Dryomov <idryomov@gmail.com>
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
net/ceph/osdmap.c

index 8e77096718c4d3b91f1baa2dabff13a4ba15f95a..3c87f4b24e51787d71cd65bbbc36c1e14714a019 100644 (file)
@@ -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 == 0)
+                       goto bad;
                b->alg = ceph_decode_8(p);
                if (b->alg != alg) {
                        b->alg = 0;