Skip to contentSkip to conversation

libceph: reject zero bucket types in crush_decode

PATCH Superseded Ren Wei 3 participants 3 messages May 29 – May 30 1 message not in the archive Ceph common code (libceph)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Ren Wei

author
#1 lore raw

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.

Fixes f24e9980eb86 ("ceph: OSD client")
Assisted-by Codex:GPT-5.4
---
 net/ceph/osdmap.c | 2 ++
 1 file changed, 2 insertions(+)
net/ceph/osdmap.c +2 -0
index 8b5b0587a0cf..226c9e0b7821 100644
@@ -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
#2 lore raw
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 to is_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

I am not sure that it's correct to mention it. But, maybe, my opinion is slightly outdated.

Quoted 11 lines
---
 net/ceph/osdmap.c | 2 ++
 1 file changed, 2 insertions(+)
net/ceph/osdmap.c +0 -0
index 8b5b0587a0cf..226c9e0b7821 100644

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;
#3 lore raw
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 to is_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

I 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
---
 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
index 8b5b0587a0cf..226c9e0b7821 100644
@@ -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;