]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
cxl/mem: Fix potential memory leak
authorBen Widawsky <ben.widawsky@intel.com>
Sun, 21 Feb 2021 03:58:46 +0000 (19:58 -0800)
committerDan Williams <dan.j.williams@intel.com>
Mon, 22 Feb 2021 22:44:39 +0000 (14:44 -0800)
When submitting a command for userspace, input and output payload bounce
buffers are allocated. For a given command, both input and output
buffers may exist and so when allocation of the input buffer fails, the
output buffer must be freed too.

As far as I can tell, userspace can't easily exploit the leak to OOM a
machine unless the machine was already near OOM state.

Fixes: 583fa5e71cae ("cxl/mem: Add basic IOCTL interface")
Reported-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Signed-off-by: Ben Widawsky <ben.widawsky@intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Link: https://lore.kernel.org/r/20210221035846.680145-1-ben.widawsky@intel.com
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
drivers/cxl/mem.c

index df895bcca63a632a94c7c44321e0d395bc38ae66..244cb7d89678b24a9cd21de12e2142530fd553ec 100644 (file)
@@ -514,8 +514,10 @@ static int handle_mailbox_cmd_from_user(struct cxl_mem *cxlm,
        if (cmd->info.size_in) {
                mbox_cmd.payload_in = vmemdup_user(u64_to_user_ptr(in_payload),
                                                   cmd->info.size_in);
-               if (IS_ERR(mbox_cmd.payload_in))
+               if (IS_ERR(mbox_cmd.payload_in)) {
+                       kvfree(mbox_cmd.payload_out);
                        return PTR_ERR(mbox_cmd.payload_in);
+               }
        }
 
        rc = cxl_mem_mbox_get(cxlm);