From: walter harms <wharms@bfs.de>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Jens Axboe <axboe@kernel.dk>,
Paul Gortmaker <paul.gortmaker@windriver.com>,
Al Viro <viro@zeniv.linux.org.uk>,
linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [patch] relay: prevent integer overflow in relay_open()
Date: Thu, 09 Feb 2012 11:55:52 +0000 [thread overview]
Message-ID: <4F33B448.1040207@bfs.de> (raw)
In-Reply-To: <20120209104433.GA5540@elgon.mountain>
Am 09.02.2012 11:44, schrieb Dan Carpenter:
> "subbuf_size" and "n_subbufs" come from the user and they need to be
> capped to prevent an integer overflow.
>
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
>
> diff --git a/kernel/relay.c b/kernel/relay.c
> index 4335e1d..ab56a17 100644
> --- a/kernel/relay.c
> +++ b/kernel/relay.c
> @@ -164,10 +164,14 @@ depopulate:
> */
> static struct rchan_buf *relay_create_buf(struct rchan *chan)
> {
> - struct rchan_buf *buf = kzalloc(sizeof(struct rchan_buf), GFP_KERNEL);
> - if (!buf)
> + struct rchan_buf *buf;
> +
> + if (chan->n_subbufs > UINT_MAX / sizeof(size_t *))
> return NULL;
>
> + buf = kzalloc(sizeof(struct rchan_buf), GFP_KERNEL);
> + if (!buf)
> + return NULL;
> buf->padding = kmalloc(chan->n_subbufs * sizeof(size_t *), GFP_KERNEL);
> if (!buf->padding)
> goto free_buf;
> @@ -574,6 +578,8 @@ struct rchan *relay_open(const char *base_filename,
>
> if (!(subbuf_size && n_subbufs))
> return NULL;
> + if (subbuf_size > UINT_MAX / n_subbufs)
> + return NULL;
>
> chan = kzalloc(sizeof(struct rchan), GFP_KERNEL);
> if (!chan)
> --
numerical this is ok, but ...
maybe it is better to cap the chan->n_subbufs at a useful number ?
The user can still allocate an insane number of bytes.
Restricting subbuf_size*n_subbufs seems more logical (otherwise is this a real problem ?)
re,
wh
next prev parent reply other threads:[~2012-02-09 11:55 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <4F323388.7040902@kernel.dk>
2012-02-09 10:44 ` [patch] relay: prevent integer overflow in relay_open() Dan Carpenter
2012-02-09 11:55 ` walter harms [this message]
2012-02-09 12:36 ` 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=4F33B448.1040207@bfs.de \
--to=wharms@bfs.de \
--cc=axboe@kernel.dk \
--cc=dan.carpenter@oracle.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=paul.gortmaker@windriver.com \
--cc=viro@zeniv.linux.org.uk \
/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