From patchwork Thu Jan 17 00:50:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Moyer X-Patchwork-Id: 10767405 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 993A317FB for ; Thu, 17 Jan 2019 00:50:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8CEC42EBD9 for ; Thu, 17 Jan 2019 00:50:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 815282F70A; Thu, 17 Jan 2019 00:50:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 41A0E2F76E for ; Thu, 17 Jan 2019 00:50:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726917AbfAQAuO (ORCPT ); Wed, 16 Jan 2019 19:50:14 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39402 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726119AbfAQAuN (ORCPT ); Wed, 16 Jan 2019 19:50:13 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A35578666E; Thu, 17 Jan 2019 00:50:13 +0000 (UTC) Received: from segfault.boston.devel.redhat.com (unknown [10.18.25.74]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 035BC608E0; Thu, 17 Jan 2019 00:50:12 +0000 (UTC) From: Jeff Moyer To: axboe@kernel.dk Cc: linux-fsdevel@vger.kernel.org, linux-aio@kvack.org, linux-block@vger.kernel.org Subject: [patch] io_uring: don't allow duplicate registrations X-PGP-KeyID: 1F78E1B4 X-PGP-CertKey: F6FE 280D 8293 F72C 65FD 5A58 1FF8 A7CA 1F78 E1B4 Date: Wed, 16 Jan 2019 19:50:12 -0500 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 17 Jan 2019 00:50:13 +0000 (UTC) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi, Jens, It looks to me like calling io_uring_register more than once (for either IORING_REGISTER_BUFFERS or IORING_REGISTER_FILES) will leak the references taken in previous calls. Signed-off-by: Jeff Moyer --- If this makes sense to you, feel free to just fold this into your patches w/o any attribution. diff --git a/fs/io_uring.c b/fs/io_uring.c index 3650e8b63a32..f0492b0e23a0 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -1399,6 +1399,9 @@ static int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg, if (!nr_args) return -EINVAL; + if (ctx->user_files) + return -EINVAL; + ctx->user_files = kcalloc(nr_args, sizeof(struct file *), GFP_KERNEL); if (!ctx->user_files) return -ENOMEM; @@ -1580,6 +1583,9 @@ static int io_sqe_buffer_register(struct io_ring_ctx *ctx, void __user *arg, if (!nr_args || nr_args > UIO_MAXIOV) return -EINVAL; + if (ctx->user_bufs) + return -EINVAL; + ctx->user_bufs = kcalloc(nr_args, sizeof(struct io_mapped_ubuf), GFP_KERNEL); if (!ctx->user_bufs)