libceph: reject zero bucket types in crush_decode
PATCH v2 1/1 libceph: reject zero bucket types in crush_decode
From: Douya Le <[email protected]>
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.
To: Viacheslav Dubeyko <[email protected]>
---
Changes in v2:
- use CRUSH_ITEM_TYPE_DEVICE instead of hardcoded 0
- v1 Link: https://lore.kernel.org/all/[email protected]/
--- include/linux/crush/crush.h | 1 + net/ceph/osdmap.c | 2 ++ 2 files changed, 3 insertions(+)
include/linux/crush/crush.h +1 -0
@@ -111,6 +111,7 @@ struct crush_rule {* straw2 O(n) optimal optimal */ enum { +CRUSH_ITEM_TYPE_DEVICE =0 ,CRUSH_BUCKET_UNIFORM =1 ,CRUSH_BUCKET_LIST =2 ,CRUSH_BUCKET_TREE =3 ,
net/ceph/osdmap.c +2 -0
@@ -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 ;
Signature · 1 line
2.47.3
[email protected]
maintainerQuoted 41 lines · Ren Wei
From: Douya Le <[email protected]>
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
tois_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.
Fixes f24e9980eb86 ("ceph: OSD client")To: Viacheslav Dubeyko <[email protected]>
Reported-by Yuan Tan <[email protected]>Reported-by Zhengchuan Liang <[email protected]>Reported-by Xin Liu <[email protected]>Assisted-by Codex:GPT-5.4Signed-off-by Douya Le <[email protected]>Signed-off-by Ren Wei <[email protected]>---
Changes in v2:
- useCRUSH_ITEM_TYPE_DEVICEinstead of hardcoded 0
- v1 Link:
https://lore.kernel.org/all/[email protected]/---
include/linux/crush/crush.h | 1 +
net/ceph/osdmap.c | 2 ++2 files changed, 3 insertions(+)include/linux/crush/crush.h +0
-0
include/linux/crush/crush.h struct crush_rule { · line 114
Quoted 4 lines
include/linux/crush/crush.h +1
-0@@ -111,6 +111,7 @@ struct crush_rule {* straw2 O(n) optimal optimal */ enum { + CRUSH_ITEM_TYPE_DEVICE = 0,
Let's be consistent with other declarations. What's about CRUSH_BUCKET_DEVICE?
Thanks,
Slava.
Quoted 17 lines
include/linux/crush/crush.h +0
-0CRUSH_BUCKET_UNIFORM = 1, CRUSH_BUCKET_LIST = 2, CRUSH_BUCKET_TREE = 3,net/ceph/osdmap.c +2
-0@@ -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;