Skip to content

Commit

Permalink
ceph: fix bounds check in ceph_decode_need and ceph_encode_need
Browse files Browse the repository at this point in the history
Given a large n, the bounds check (*p + n > end) can be bypassed due to
pointer wraparound.  A safer check is (n > end - *p).

[[email protected]: inverted test and renamed ceph_has_room()]

Signed-off-by: Xi Wang <[email protected]>
Reviewed-by: Alex Elder <[email protected]>
  • Loading branch information
xiw authored and Alex Elder committed May 14, 2012
1 parent 065a68f commit 76aa542
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions include/linux/ceph/decode.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,14 @@ static inline void ceph_decode_copy(void **p, void *pv, size_t n)
/*
* bounds check input.
*/
static inline int ceph_has_room(void **p, void *end, size_t n)
{
return end >= *p && n <= end - *p;
}

#define ceph_decode_need(p, end, n, bad) \
do { \
if (unlikely(*(p) + (n) > (end))) \
if (!likely(ceph_has_room(p, end, n))) \
goto bad; \
} while (0)

Expand Down Expand Up @@ -166,7 +171,7 @@ static inline void ceph_encode_string(void **p, void *end,

#define ceph_encode_need(p, end, n, bad) \
do { \
if (unlikely(*(p) + (n) > (end))) \
if (!likely(ceph_has_room(p, end, n))) \
goto bad; \
} while (0)

Expand Down

0 comments on commit 76aa542

Please sign in to comment.