Skip to content

Commit

Permalink
libceph: fix overflow check in crush_decode()
Browse files Browse the repository at this point in the history
The existing overflow check (n > ULONG_MAX / b) didn't work, because
n = ULONG_MAX / b would both bypass the check and still overflow the
allocation size a + n * b.

The correct check should be (n > (ULONG_MAX - a) / b).

Signed-off-by: Xi Wang <[email protected]>
Signed-off-by: Sage Weil <[email protected]>
  • Loading branch information
xiw authored and Alex Elder committed Mar 22, 2012
1 parent 810339e commit 6448669
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion net/ceph/osdmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,8 @@ static struct crush_map *crush_decode(void *pbyval, void *end)
ceph_decode_32_safe(p, end, yes, bad);
#if BITS_PER_LONG == 32
err = -EINVAL;
if (yes > ULONG_MAX / sizeof(struct crush_rule_step))
if (yes > (ULONG_MAX - sizeof(*r))
/ sizeof(struct crush_rule_step))
goto bad;
#endif
r = c->rules[i] = kmalloc(sizeof(*r) +
Expand Down

0 comments on commit 6448669

Please sign in to comment.