Skip to contentSkip to conversation

libceph: reject zero bucket types in crush_decode

PATCH Superseded Ren Wei 2 participants 2 messages May 31 – Jun 1 Ceph common code (libceph)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Ren Wei

author
#0 lore raw

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.

Fixes f24e9980eb86 ("ceph: OSD client")

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
index 30dba392b..eb469972f 100644
@@ -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
index 8b5b0587a..21cdd33f2 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 == 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
#1 lore raw
Quoted 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
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")

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 +0 -0
index 30dba392b..eb469972f 100644

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 -0
  	CRUSH_BUCKET_UNIFORM = 1,
  	CRUSH_BUCKET_LIST = 2,
  	CRUSH_BUCKET_TREE = 3,
net/ceph/osdmap.c +2 -0
index 8b5b0587a..21cdd33f2 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 == CRUSH_ITEM_TYPE_DEVICE)
+			goto bad;
  		b->alg = ceph_decode_8(p);
  		if (b->alg != alg) {

  b->alg = 0;