]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - drivers/block/nvme-core.c
NVMe: check for integer overflow in nvme_map_user_pages()
[karo-tx-linux.git] / drivers / block / nvme-core.c
index 310d573b9e8da38b4361542e98f88e595f02a47d..437637551d1e0eb0152398ec5157752cda305603 100644 (file)
@@ -1206,7 +1206,7 @@ struct nvme_iod *nvme_map_user_pages(struct nvme_dev *dev, int write,
 
        if (addr & 3)
                return ERR_PTR(-EINVAL);
-       if (!length)
+       if (!length || length > INT_MAX - PAGE_SIZE)
                return ERR_PTR(-EINVAL);
 
        offset = offset_in_page(addr);
@@ -1227,7 +1227,8 @@ struct nvme_iod *nvme_map_user_pages(struct nvme_dev *dev, int write,
        sg_init_table(sg, count);
        for (i = 0; i < count; i++) {
                sg_set_page(&sg[i], pages[i],
-                               min_t(int, length, PAGE_SIZE - offset), offset);
+                           min_t(unsigned, length, PAGE_SIZE - offset),
+                           offset);
                length -= (PAGE_SIZE - offset);
                offset = 0;
        }
@@ -1392,6 +1393,7 @@ static int nvme_user_admin_cmd(struct nvme_dev *dev,
        struct nvme_command c;
        int status, length;
        struct nvme_iod *uninitialized_var(iod);
+       unsigned timeout;
 
        if (!capable(CAP_SYS_ADMIN))
                return -EACCES;
@@ -1421,10 +1423,13 @@ static int nvme_user_admin_cmd(struct nvme_dev *dev,
                                                                GFP_KERNEL);
        }
 
+       timeout = cmd.timeout_ms ? msecs_to_jiffies(cmd.timeout_ms) :
+                                                               ADMIN_TIMEOUT;
        if (length != cmd.data_len)
                status = -ENOMEM;
        else
-               status = nvme_submit_admin_cmd(dev, &c, &cmd.result);
+               status = nvme_submit_sync_cmd(dev->queues[0], &c, &cmd.result,
+                                                               timeout);
 
        if (cmd.data_len) {
                nvme_unmap_user_pages(dev, cmd.opcode & 1, iod);