arm64: kexec_file: fix memory leakage in create_dtb() when fdt_open_into() fails
authorqiuguorui1 <qiuguorui1@huawei.com>
Thu, 18 Feb 2021 12:59:00 +0000 (20:59 +0800)
committerWill Deacon <will@kernel.org>
Fri, 19 Feb 2021 17:57:40 +0000 (17:57 +0000)
in function create_dtb(), if fdt_open_into() fails, we need to vfree
buf before return.

Fixes: 52b2a8af7436 ("arm64: kexec_file: load initrd and device-tree")
Cc: stable@vger.kernel.org # v5.0
Signed-off-by: qiuguorui1 <qiuguorui1@huawei.com>
Link: https://lore.kernel.org/r/20210218125900.6810-1-qiuguorui1@huawei.com
Signed-off-by: Will Deacon <will@kernel.org>
arch/arm64/kernel/machine_kexec_file.c

index 03210f6..0cde47a 100644 (file)
@@ -182,8 +182,10 @@ static int create_dtb(struct kimage *image,
 
                /* duplicate a device tree blob */
                ret = fdt_open_into(initial_boot_params, buf, buf_size);
-               if (ret)
+               if (ret) {
+                       vfree(buf);
                        return -EINVAL;
+               }
 
                ret = setup_dtb(image, initrd_load_addr, initrd_len,
                                cmdline, buf);