Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp293490ybt; Thu, 9 Jul 2020 23:16:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyG2e8O8Y8RS/zVshqafXgH6utjohuCUL+kTyI6ChpDTrJ/Y7ZGV41uADcLwA3dm6SiT8Kv X-Received: by 2002:a17:906:ef2:: with SMTP id x18mr57942187eji.547.1594361819273; Thu, 09 Jul 2020 23:16:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594361819; cv=none; d=google.com; s=arc-20160816; b=vRbdBWX66YgRxy5cPIjfkPDu1pSmfITnwSwSP1mPYWqx9aHgQeC1ByjzyzUS2L7mZe rLBXlqHcC4qUg4J7hqmty+E1OgKXIywhEquecAcV8Q8rWi8AKx6M5gwLQXfmmiPv0iMh 5SJ1FeTuHa6Mv3SAveN4z/VYIUSNBqvC2a6/GfF7mcWHdtXmCUWsZvnSc2F5YGedWDZt 6JGLXPqXxpVxHmlXgmkfa2J0sybbOI6VXNoQ3AJBaR3oLz43mhJqwntbGCuPqAXh9P0d c6OpU+0VVIHdAr7GsKK/8oIaKb3eQpJRtTw0Xu4hD6CNFb7Yn7Ts83mrAzhKczwnA4Yx atwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=/nCgncPMpeqDgQJx2zYHABO2R59RbmIJPPNpnxTYk/g=; b=nvfAhJ+A16vt0LtT2O4JTKW6Npp0ZjNNLkHkc7PeTOjkMzzej6i7d570nnMCXTioSo dEFroHGoaS/7BuLO5EYeikZnVBv815+OopRRInjHdOFxFCxkugMN1SnleFWclOLFDCLi lZoXstepuoNkE7m+YTFRa8EyLQH+75yKThRSgDdNl8fCQBeZb4Yy0J5ss98rDAyLG4Ef AVOYQxYxBWjIrQ3wTNic1W+6oU8+zsixfnSkd8Y0qhrdlSg3U7d/0GCGWPcedxafBaLs 8ckBrLXsuBE71b00eUiZMyIhSXzrFZjC4G3F/9p0vbUCTjFOZTdEDkUOmcwCldqXswwD XAOw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h23si3467594ejd.485.2020.07.09.23.16.36; Thu, 09 Jul 2020 23:16:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726908AbgGJGPQ (ORCPT + 99 others); Fri, 10 Jul 2020 02:15:16 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:7830 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725851AbgGJGPP (ORCPT ); Fri, 10 Jul 2020 02:15:15 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id F20893357126DAC07796; Fri, 10 Jul 2020 14:15:09 +0800 (CST) Received: from huawei.com (10.175.124.27) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.487.0; Fri, 10 Jul 2020 14:15:04 +0800 From: Yang Yingliang To: , CC: Subject: [PATCH] io_uring: fix memleak in io_sqe_files_register() Date: Fri, 10 Jul 2020 14:14:20 +0000 Message-ID: <20200710141420.3987063-1-yangyingliang@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.124.27] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I got a memleak report when doing some fuzz test: BUG: memory leak unreferenced object 0x607eeac06e78 (size 8): comm "test", pid 295, jiffies 4294735835 (age 31.745s) hex dump (first 8 bytes): 00 00 00 00 00 00 00 00 ........ backtrace: [<00000000932632e6>] percpu_ref_init+0x2a/0x1b0 [<0000000092ddb796>] __io_uring_register+0x111d/0x22a0 [<00000000eadd6c77>] __x64_sys_io_uring_register+0x17b/0x480 [<00000000591b89a6>] do_syscall_64+0x56/0xa0 [<00000000864a281d>] entry_SYSCALL_64_after_hwframe+0x44/0xa9 Call percpu_ref_exit() on error path to avoid refcount memleak. Fixes: 05f3fb3c5397 ("io_uring: avoid ring quiesce for fixed file set unregister and update") Reported-by: Hulk Robot Signed-off-by: Yang Yingliang --- fs/io_uring.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/io_uring.c b/fs/io_uring.c index d37d7ea5ebe5..ea81be3c14af 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -6693,6 +6693,7 @@ static int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg, for (i = 0; i < nr_tables; i++) kfree(ctx->file_data->table[i].files); + percpu_ref_exit(&ctx->file_data->refs); kfree(ctx->file_data->table); kfree(ctx->file_data); ctx->file_data = NULL; -- 2.25.1