From: Alex Elder <elder@dreamhost.com>
To: Xi Wang <xi.wang@gmail.com>
Cc: Sage Weil <sage@newdream.net>, ceph-devel@vger.kernel.org
Subject: Re: [PATCH 2/3] ceph: fix bounds check macros ceph_decode_need and ceph_encode_need
Date: Wed, 18 Apr 2012 09:13:11 -0500 [thread overview]
Message-ID: <4F8ECBF7.7060509@dreamhost.com> (raw)
In-Reply-To: <1323894273-13904-3-git-send-email-xi.wang@gmail.com>
On 12/14/2011 02:24 PM, Xi Wang wrote:
> Given a large n, the bounds check (*p + n> end) can be bypassed due to
> pointer wraparound. A safer check is (n> end - *p).
>
> Signed-off-by: Xi Wang<xi.wang@gmail.com>
I noticed this proposed change never got committed.
It looks good, but I don't like the name "ceph_need()".
I am planning to pull this in soon, modified like this:
static inline int ceph_need_ok(void **p, void *end, size_t n)
{
return end >= *p && n <= end - *p;
}
And then used like this:
if (!likely(ceph_need_ok(p, end, n)))
If you have an objection to that, please say so soon
(and if you have no objection, please ACK).
Reviewed-by: Alex Elder <elder@dreamhost.com>
> ---
> include/linux/ceph/decode.h | 9 +++++++--
> 1 files changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/ceph/decode.h b/include/linux/ceph/decode.h
> index c5b6939..ea6db7b 100644
> --- a/include/linux/ceph/decode.h
> +++ b/include/linux/ceph/decode.h
> @@ -12,6 +12,11 @@
> * void *end pointer to end of buffer (last byte + 1)
> */
>
> +static inline int ceph_need(void **p, void *end, size_t n)
> +{
> + return ((end< *p) || (n> end - *p));
> +}
> +
> static inline u64 ceph_decode_64(void **p)
> {
> u64 v = get_unaligned_le64(*p);
> @@ -47,7 +52,7 @@ static inline void ceph_decode_copy(void **p, void *pv, size_t n)
> */
> #define ceph_decode_need(p, end, n, bad) \
> do { \
> - if (unlikely(*(p) + (n)> (end))) \
> + if (unlikely(ceph_need(p, end, n))) \
> goto bad; \
> } while (0)
>
> @@ -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 (unlikely(ceph_need(p, end, n))) \
> goto bad; \
> } while (0)
>
next prev parent reply other threads:[~2012-04-18 14:13 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-14 20:24 [PATCH 0/3] ceph: fix multiple out-of-bounds checks Xi Wang
2011-12-14 20:24 ` [PATCH 1/3] ceph: fix out-of-bounds pointers in parse_reply_info() Xi Wang
2011-12-14 20:24 ` [PATCH 2/3] ceph: fix bounds check macros ceph_decode_need and ceph_encode_need Xi Wang
2012-04-18 14:13 ` Alex Elder [this message]
2012-04-18 17:53 ` Sage Weil
2012-04-18 18:41 ` Alex Elder
2011-12-14 20:24 ` [PATCH 3/3] ceph: avoid panic with mismatched symbolic link sizes in fill_inode() Xi Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4F8ECBF7.7060509@dreamhost.com \
--to=elder@dreamhost.com \
--cc=ceph-devel@vger.kernel.org \
--cc=sage@newdream.net \
--cc=xi.wang@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox