Skip to content

Commit a0cbc2d

Browse files
Dan Carpentergregkh
authored andcommitted
relay: prevent integer overflow in relay_open()
commit f6302f1 upstream. "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> Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 7360202 commit a0cbc2d

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

‎kernel/relay.c‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,14 @@ static void *relay_alloc_buf(struct rchan_buf *buf, size_t *size)
164164
*/
165165
static struct rchan_buf *relay_create_buf(struct rchan *chan)
166166
{
167-
struct rchan_buf *buf = kzalloc(sizeof(struct rchan_buf), GFP_KERNEL);
168-
if (!buf)
167+
struct rchan_buf *buf;
168+
169+
if (chan->n_subbufs > UINT_MAX / sizeof(size_t *))
169170
return NULL;
170171

172+
buf = kzalloc(sizeof(struct rchan_buf), GFP_KERNEL);
173+
if (!buf)
174+
return NULL;
171175
buf->padding = kmalloc(chan->n_subbufs * sizeof(size_t *), GFP_KERNEL);
172176
if (!buf->padding)
173177
goto free_buf;
@@ -574,6 +578,8 @@ struct rchan *relay_open(const char *base_filename,
574578

575579
if (!(subbuf_size && n_subbufs))
576580
return NULL;
581+
if (subbuf_size > UINT_MAX / n_subbufs)
582+
return NULL;
577583

578584
chan = kzalloc(sizeof(struct rchan), GFP_KERNEL);
579585
if (!chan)

0 commit comments

Comments
 (0)