libceph: reject zero bucket types in crush_decode
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 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.
--- net/ceph/osdmap.c | 2 ++ 1 file changed, 2 insertions(+)
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 ==0 ) + goto bad; b->alg =ceph_decode_8 (p);if (b->alg != alg) { b->alg =0 ;
Signature · 1 line
2.47.3
Quoted 10 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.
Quoted 5 lines
Reject zero bucket types while decoding the CRUSH map so the invalid state never reaches the mapper.
Fixes f24e9980eb86 ("ceph: OSD client")
If I am not wrong, the correct email is [email protected].
Quoted 4 lines
Reported-by Yuan Tan <[email protected]>Reported-by Zhengchuan Liang <[email protected]>Reported-by Xin Liu <[email protected]>Assisted-by Codex:GPT-5.4
I am not sure that it's correct to mention it. But, maybe, my opinion is slightly outdated.
Quoted 11 lines
Signed-off-by Douya Le <[email protected]>Signed-off-by Ren Wei <[email protected]>--- net/ceph/osdmap.c | 2 ++ 1 file changed, 2 insertions(+)net/ceph/osdmap.c +0
-0
net/ceph/osdmap.c static struct crush_map *crush_decode(void *pbyval, void *end) · line 521
Quoted 4 lines
net/ceph/osdmap.c +1
-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 ==0 )
I don't like of hardcoding the constant. Do we have named constant for devices type? If we do not have, maybe, do we need to introduce some?
Thanks,
Slava.
Quoted 4 lines
net/ceph/osdmap.c +1
-0+ goto bad; b->alg =ceph_decode_8 (p);if (b->alg != alg) { b->alg =0 ;
Quoted 12 lines · Viacheslav Dubeyko
Quoted 10 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.
Quoted 7 lines
Quoted 5 lines
Reject zero bucket types while decoding the CRUSH map so the invalid state never reaches the mapper.
Fixes f24e9980eb86 ("ceph: OSD client")If I am not wrong, the correct email is [email protected].
In our previous patches submitted this way worked fine, and stable maintainers would help backport them.
To be honest, I was also debating whether I should use [email protected]. My main concern was accidentally sending an unreviewed patch to stable@ and spamming their inbox.
If you feel [email protected] is more appropriate, we will switch to it in the next version.
Quoted 8 lines
Quoted 5 lines
Reported-by Yuan Tan <[email protected]>Reported-by Zhengchuan Liang <[email protected]>Reported-by Xin Liu <[email protected]>Assisted-by Codex:GPT-5.4I am not sure that it's correct to mention it. But, maybe, my opinion is slightly outdated.
We added Assisted-by: Codex:GPT-5.4 based on.
https://www.kernel.org/doc/html/latest/process/coding-assistants.html#attribution
Please correct us if there's something wrong with our understanding :)
Quoted 7 lines
Quoted 7 lines
Signed-off-by Douya Le <[email protected]>Signed-off-by Ren Wei <[email protected]>--- net/ceph/osdmap.c | 2 ++ 1 file changed, 2 insertions(+)
Quoted 12 lines
net/ceph/osdmap.c static struct crush_map *crush_decode(void *pbyval, void *end) · line 521
Quoted 9 lines
net/ceph/osdmap.c +1
-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 ==0 )I don't like of hardcoding the constant. Do we have named constant for devices type? If we do not have, maybe, do we need to introduce some?
I'll defer to Douya Le on this point.
Quoted 9 lines
Thanks,
Slava.Quoted 4 lines
net/ceph/osdmap.c +1
-0+ goto bad; b->alg =ceph_decode_8 (p);if (b->alg != alg) { b->alg =0 ;