RDMA/ucma: Limit possible option size
authorLeon Romanovsky <leonro@mellanox.com>
Wed, 7 Mar 2018 12:49:09 +0000 (14:49 +0200)
committerBen Hutchings <ben@decadent.org.uk>
Thu, 31 May 2018 23:30:20 +0000 (00:30 +0100)
commit 6a21dfc0d0db7b7e0acedce67ca533a6eb19283c upstream.

Users of ucma are supposed to provide size of option level,
in most paths it is supposed to be equal to u8 or u16, but
it is not the case for the IB path record, where it can be
multiple of struct ib_path_rec_data.

This patch takes simplest possible approach and prevents providing
values more than possible to allocate.

Reported-by: syzbot+a38b0e9f694c379ca7ce@syzkaller.appspotmail.com
Fixes: 7ce86409adcd ("RDMA/ucma: Allow user space to set service type")
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
[bwh: Backported to 3.2: adjust context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
drivers/infiniband/core/ucma.c

index 91e82b7..79d0333 100644 (file)
@@ -1000,6 +1000,9 @@ static ssize_t ucma_set_option(struct ucma_file *file, const char __user *inbuf,
        if (IS_ERR(ctx))
                return PTR_ERR(ctx);
 
+       if (unlikely(cmd.optval > KMALLOC_MAX_SIZE))
+               return -EINVAL;
+
        optval = kmalloc(cmd.optlen, GFP_KERNEL);
        if (!optval) {
                ret = -ENOMEM;