From: walter harms <wharms@bfs.de>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Trond Myklebust <Trond.Myklebust@netapp.com>,
"J. Bruce Fields" <bfields@fieldses.org>,
"David S. Miller" <davem@davemloft.net>,
linux-nfs@vger.kernel.org, netdev@vger.kernel.org,
kernel-janitors@vger.kernel.org
Subject: Re: [patch -stable] svcrdma: underflow issue in decode_write_list()
Date: Fri, 12 Jul 2013 10:24:41 +0200 [thread overview]
Message-ID: <51DFBD49.7000205@bfs.de> (raw)
In-Reply-To: <20130712063903.GB29320@longonot.mountain>
Am 12.07.2013 08:39, schrieb Dan Carpenter:
> My static checker marks everything from ntohl() as untrusted and it
> complains we could have an underflow problem doing:
>
> return (u32 *)&ary->wc_array[nchunks];
>
> Also on 32 bit systems the upper bound check could overflow.
>
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
>
> diff --git a/net/sunrpc/xprtrdma/svc_rdma_marshal.c b/net/sunrpc/xprtrdma/svc_rdma_marshal.c
> index 8d2eddd..65b1462 100644
> --- a/net/sunrpc/xprtrdma/svc_rdma_marshal.c
> +++ b/net/sunrpc/xprtrdma/svc_rdma_marshal.c
> @@ -98,6 +98,7 @@ void svc_rdma_rcl_chunk_counts(struct rpcrdma_read_chunk *ch,
> */
> static u32 *decode_write_list(u32 *va, u32 *vaend)
> {
> + unsigned long start, end;
> int nchunks;
>
> struct rpcrdma_write_array *ary =
> @@ -113,9 +114,12 @@ static u32 *decode_write_list(u32 *va, u32 *vaend)
> return NULL;
> }
> nchunks = ntohl(ary->wc_nchunks);
> - if (((unsigned long)&ary->wc_array[0] +
> - (sizeof(struct rpcrdma_write_chunk) * nchunks)) >
> - (unsigned long)vaend) {
> +
> + start = (unsigned long)&ary->wc_array[0];
> + end = (unsigned long)vaend;
> + if (nchunks < 0 ||
> + nchunks > (SIZE_MAX - start) / sizeof(struct rpcrdma_write_chunk) ||
> + (start + (sizeof(struct rpcrdma_write_chunk) * nchunks)) > end) {
> dprintk("svcrdma: ary=%p, wc_nchunks=%d, vaend=%p\n",
> ary, nchunks, vaend);
i am struggling to understand what is actually checked here.
Perhaps this improves the readability a bit
if ( nchunks < 0 ||
sizeof(struct rpcrdma_write_chunk) * nchunks > (SIZE_MAX - start) ||
sizeof(struct rpcrdma_write_chunk) * nchunks > (end - start) )
with that rewrite i would say that (SIZE_MAX - start) is strange.
just my 2 cents,
wh
> return NULL;
> @@ -129,6 +133,7 @@ static u32 *decode_write_list(u32 *va, u32 *vaend)
>
> static u32 *decode_reply_array(u32 *va, u32 *vaend)
> {
> + unsigned long start, end;
> int nchunks;
> struct rpcrdma_write_array *ary =
> (struct rpcrdma_write_array *)va;
> @@ -143,9 +148,12 @@ static u32 *decode_reply_array(u32 *va, u32 *vaend)
> return NULL;
> }
> nchunks = ntohl(ary->wc_nchunks);
> - if (((unsigned long)&ary->wc_array[0] +
> - (sizeof(struct rpcrdma_write_chunk) * nchunks)) >
> - (unsigned long)vaend) {
> +
> + start = (unsigned long)&ary->wc_array[0];
> + end = (unsigned long)vaend;
> + if (nchunks < 0 ||
> + nchunks > (SIZE_MAX - start) / sizeof(struct rpcrdma_write_chunk) ||
> + (start + (sizeof(struct rpcrdma_write_chunk) * nchunks)) > end) {
> dprintk("svcrdma: ary=%p, wc_nchunks=%d, vaend=%p\n",
> ary, nchunks, vaend);
> return NULL;
> --
> To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
next prev parent reply other threads:[~2013-07-12 8:24 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-12 6:39 [patch -stable] svcrdma: underflow issue in decode_write_list() Dan Carpenter
2013-07-12 8:24 ` walter harms [this message]
2013-07-12 20:26 ` J. Bruce Fields
[not found] ` <51DFBD49.7000205-fPG8STNUNVg@public.gmane.org>
2013-07-14 19:40 ` Dan Carpenter
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=51DFBD49.7000205@bfs.de \
--to=wharms@bfs.de \
--cc=Trond.Myklebust@netapp.com \
--cc=bfields@fieldses.org \
--cc=dan.carpenter@oracle.com \
--cc=davem@davemloft.net \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=netdev@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).