Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp3060992imj; Mon, 18 Feb 2019 18:50:06 -0800 (PST) X-Google-Smtp-Source: AHgI3IaGUq8SF0p0Qw8XelirmtBGaJeJPG00ityYNRsJRQMPYD94N6RqYQGRRyaSeoMeeUes2oc5 X-Received: by 2002:a17:902:1a2:: with SMTP id b31mr28873537plb.87.1550544606290; Mon, 18 Feb 2019 18:50:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550544606; cv=none; d=google.com; s=arc-20160816; b=klkN7xmKKU4933lC8AAMdCLEKLQxSoOryu7WMshxVjY8Dl0mwHRFHrA2UruE+DC0sH GrDl8xskZpOd9CilvWspna5NjH4zCtc9d2o6Xd+M2N+/ey58yfeHFY/X/ymrkFO7fC5g nXhBksFQs9cFBXCSK0i/vKVZ0Qb015MKi0Hi8XKWtcpJZIjtmHJiMVV0ueoYrnhTPpn8 RJDdWYqAS24sqfF7Zsgzq7iiKPUXxfBjV2SiczbFacy65TV6g8akvbNXYD37EswV0miJ 2K8y7EdRaZObZFrE2vV9EkLZInQ7Lt9xue+oKHEN7c5/UfwpA4VqiNcX1W3rpHB9/GAL VOzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=mU84DFcUbjfbs86Q7USWrZ3mB7+zE3DC4hA/ei1hxJ4=; b=Uw/8LEMBNuxcHumM4nrroT8iQSZYg9ukccmdjmiPkTWlOEzpFO1UlmfH07sng9YIaQ FNG7UnQdP22gBpZ/44KQXLeCc/jWP3hqTViIWTtg6NziY6eEyzb8XoSTB/FbEp5YKu/e CIQl9tmrgMMOTPhlxcmhlAyk3OuQL3ZcHAFjT5z3uNo/ZMv1ZBZwYGFOVyiB9GtC+rZV 3A+tVu4LjJ/0uDobr+OBSD2mEVZ1qp8LzNjNGFk0P8y4EXxqjPF3+Xc8LtGvohtaHOXF fYg+gZ22qh4ehFYPxZK9QChZ1nHEfgpms9wzV1n/ZyC6vI4JGKLscYh/Ua9W2yADJDgj tvpw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i63si14797613pfi.58.2019.02.18.18.49.51; Mon, 18 Feb 2019 18:50:06 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727496AbfBSCKy (ORCPT + 99 others); Mon, 18 Feb 2019 21:10:54 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:60042 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727030AbfBSCKx (ORCPT ); Mon, 18 Feb 2019 21:10:53 -0500 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id C192C49B561BC8D7F47D; Tue, 19 Feb 2019 10:10:51 +0800 (CST) Received: from localhost (10.177.31.96) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.408.0; Tue, 19 Feb 2019 10:10:43 +0800 From: YueHaibing To: CC: , , , , YueHaibing Subject: [PATCH -next] exec: Fix mem leak in kernel_read_file Date: Tue, 19 Feb 2019 10:10:38 +0800 Message-ID: <20190219021038.11340-1-yuehaibing@huawei.com> X-Mailer: git-send-email 2.10.2.windows.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.177.31.96] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org syzkaller report this: BUG: memory leak unreferenced object 0xffffc9000488d000 (size 9195520): comm "syz-executor.0", pid 2752, jiffies 4294787496 (age 18.757s) hex dump (first 32 bytes): ff ff ff ff ff ff ff ff a8 00 00 00 01 00 00 00 ................ 02 00 00 00 00 00 00 00 80 a1 7a c1 ff ff ff ff ..........z..... backtrace: [<000000000863775c>] __vmalloc_node mm/vmalloc.c:1795 [inline] [<000000000863775c>] __vmalloc_node_flags mm/vmalloc.c:1809 [inline] [<000000000863775c>] vmalloc+0x8c/0xb0 mm/vmalloc.c:1831 [<000000003f668111>] kernel_read_file+0x58f/0x7d0 fs/exec.c:924 [<000000002385813f>] kernel_read_file_from_fd+0x49/0x80 fs/exec.c:993 [<0000000011953ff1>] __do_sys_finit_module+0x13b/0x2a0 kernel/module.c:3895 [<000000006f58491f>] do_syscall_64+0x147/0x600 arch/x86/entry/common.c:290 [<00000000ee78baf4>] entry_SYSCALL_64_after_hwframe+0x49/0xbe [<00000000241f889b>] 0xffffffffffffffff It should goto 'out_free' lable to free allocated buf while kernel_read fails. Fixes: 39d637af5aa7 ("vfs: forbid write access when reading a file into memory") Signed-off-by: YueHaibing --- fs/exec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/exec.c b/fs/exec.c index 7a4b5ef..2e00333 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -932,7 +932,7 @@ int kernel_read_file(struct file *file, void **buf, loff_t *size, bytes = kernel_read(file, *buf + pos, i_size - pos, &pos); if (bytes < 0) { ret = bytes; - goto out; + goto out_free; } if (bytes == 0) -- 2.7.0