提交 f6302f1b 编写于 作者: D Dan Carpenter 提交者: Jens Axboe

relay: prevent integer overflow in relay_open()

"subbuf_size" and "n_subbufs" come from the user and they need to be
capped to prevent an integer overflow.
Signed-off-by: NDan Carpenter <dan.carpenter@oracle.com>
Cc: stable@kernel.org
Signed-off-by: NJens Axboe <axboe@kernel.dk>
上级 306df071
...@@ -164,10 +164,14 @@ static void *relay_alloc_buf(struct rchan_buf *buf, size_t *size) ...@@ -164,10 +164,14 @@ static void *relay_alloc_buf(struct rchan_buf *buf, size_t *size)
*/ */
static struct rchan_buf *relay_create_buf(struct rchan *chan) static struct rchan_buf *relay_create_buf(struct rchan *chan)
{ {
struct rchan_buf *buf = kzalloc(sizeof(struct rchan_buf), GFP_KERNEL); struct rchan_buf *buf;
if (!buf)
if (chan->n_subbufs > UINT_MAX / sizeof(size_t *))
return NULL; 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); buf->padding = kmalloc(chan->n_subbufs * sizeof(size_t *), GFP_KERNEL);
if (!buf->padding) if (!buf->padding)
goto free_buf; goto free_buf;
...@@ -574,6 +578,8 @@ struct rchan *relay_open(const char *base_filename, ...@@ -574,6 +578,8 @@ struct rchan *relay_open(const char *base_filename,
if (!(subbuf_size && n_subbufs)) if (!(subbuf_size && n_subbufs))
return NULL; return NULL;
if (subbuf_size > UINT_MAX / n_subbufs)
return NULL;
chan = kzalloc(sizeof(struct rchan), GFP_KERNEL); chan = kzalloc(sizeof(struct rchan), GFP_KERNEL);
if (!chan) if (!chan)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册