Skip to contentSkip to conversation

libceph: NULL deref on crush_decode() error path

PATCH Applied Dan Carpenter 2 participants 2 messages May 23, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libceph: NULL deref on crush_decode() error path

If there is not enough space then ceph_decode_32_safe() does a goto bad. We need to return an error code in that situation. The current code returns ERR_PTR(0) which is NULL. The callers are not expecting that and it results in a NULL dereference.

Fixes f24e9980eb86 ("ceph: OSD client")
net/ceph/osdmap.c +1 -0
index ffe9e904d4d1..55e3a477f92d 100644
@@ -317,6 +317,7 @@ static struct crush_map *crush_decode(void *pbyval, void *end)
 		u32 yes;
 		struct crush_rule *r;
 
+		err = -EINVAL;
 		ceph_decode_32_safe(p, end, yes, bad);
 		if (!yes) {
 			dout("crush_decode NO rule %d off %x %p to %p\n",
maintainer Applied
#1 lore raw
Quoted 13 lines · Dan Carpenter

If there is not enough space then ceph_decode_32_safe() does a goto bad. We need to return an error code in that situation. The current code returns ERR_PTR(0) which is NULL. The callers are not expecting that and it results in a NULL dereference.

Fixes f24e9980eb86 ("ceph: OSD client")
net/ceph/osdmap.c +0 -0
index ffe9e904d4d1..55e3a477f92d 100644

net/ceph/osdmap.c static struct crush_map *crush_decode(void *pbyval, void *end) · line 323

Quoted 7 lines
net/ceph/osdmap.c +1 -0
@@ -317,6 +317,7 @@ static struct crush_map *crush_decode(void *pbyval, void *end)
                u32 yes;
                struct crush_rule *r;
 
+               err = -EINVAL;
                ceph_decode_32_safe(p, end, yes, bad);
                if (!yes) {
                        dout("crush_decode NO rule %d off %x %p to %p\n",

Applied.

Thanks,

Ilya