Skip to content

Commit 88913bd

Browse files
rientjestorvalds
authored andcommitted
kernel/relay.c: limit kmalloc size to KMALLOC_MAX_SIZE
chan->n_subbufs is set by the user and relay_create_buf() does a kmalloc() of chan->n_subbufs * sizeof(size_t *). kmalloc_slab() will generate a warning when this fails if chan->subbufs * sizeof(size_t *) > KMALLOC_MAX_SIZE. Limit chan->n_subbufs to the maximum allowed kmalloc() size. Link: http://lkml.kernel.org/r/alpine.DEB.2.10.1802061216100.122576@chino.kir.corp.google.com Fixes: f6302f1 ("relay: prevent integer overflow in relay_open()") Signed-off-by: David Rientjes <rientjes@google.com> Reviewed-by: Andrew Morton <akpm@linux-foundation.org> Cc: Jens Axboe <axboe@kernel.dk> Cc: Dave Jiang <dave.jiang@intel.com> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 9c4e6b1 commit 88913bd

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

‎kernel/relay.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ static struct rchan_buf *relay_create_buf(struct rchan *chan)
163163
{
164164
struct rchan_buf *buf;
165165

166-
if (chan->n_subbufs > UINT_MAX / sizeof(size_t *))
166+
if (chan->n_subbufs > KMALLOC_MAX_SIZE / sizeof(size_t *))
167167
return NULL;
168168

169169
buf = kzalloc(sizeof(struct rchan_buf), GFP_KERNEL);

0 commit comments

Comments
 (0)