Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp4530041imb; Wed, 6 Mar 2019 16:05:15 -0800 (PST) X-Google-Smtp-Source: APXvYqx9e1WBFCHyA29YEvFWResk6oLU7LSMcawDA88457cHqLyyhsvNbvOXUd0wRfdK84fKZD6k X-Received: by 2002:a63:6ecb:: with SMTP id j194mr9021606pgc.250.1551917115408; Wed, 06 Mar 2019 16:05:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551917115; cv=none; d=google.com; s=arc-20160816; b=O1Sw4o/PbCsbE5wGrR++oAdFa6JVxzsOvbVtHrK7CzBkatVXzAR4JEfQjnYgamy0cC +hdlwSHSEEh/+Uu2sRiGgAxJCYae8cPAdchYJESq2jF742P7DRufmPcxwVeWP6+P9B0a CiD3O7Z8rgeZgaWBhUsOKgORENnREuAvcCSrZb7cKnUAlnkzEVwGQuIzu8znPNm0cv0r otfqwLoUB3k8uutWq4fcmOaGYyzzUIdQtq0nQa5Ko3VXrvMvS3coiDVMN4TWmqCODngN 5paYs43PUPadh1LoyFFIrW+//edhEPpsE1UQ8zZKvWVmP+CQr8BIkHgH6hf5XtrgHtMW Agrg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=xpKWAEH3v31GxRqpBcuGzdzBniyKhTpg0DFrdIP7PzQ=; b=z5MHc9rSDGor01DGCmjQ2lDEBOR4fiUK92udzrsorV7ddyNgW1tLVUVfSjIR0Yyb0g kzVZ4XpptlcRhblgTnyb/tCCFThzv6u7JeSx5+HQyCCxykeb0MHszD8LZtKpBT5DSKjo dEjYsJRutQ3cZvkbveWFTuuvrDVQwuiHSzQcxYAW3oYTIn0GDVF/R2RMe/LWoXcpKive xao5wevre5MaO00YsF/WpOcYYZBcWFLIILJ4M1hhWhjaaHGxknDoP8+5rpituIRcuhrY AFXQBNJMpYEeVH0IAs/xvQVPqYDuzGRewk8DfArAUWBHRjHQ0/WmrjF4bvFyAh7kiNtK Z/kg== 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 u11si2630500plr.227.2019.03.06.16.05.00; Wed, 06 Mar 2019 16:05:15 -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 S1726727AbfCGADb (ORCPT + 99 others); Wed, 6 Mar 2019 19:03:31 -0500 Received: from zeniv.linux.org.uk ([195.92.253.2]:39972 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726299AbfCGAD3 (ORCPT ); Wed, 6 Mar 2019 19:03:29 -0500 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92 #3 (Red Hat Linux)) id 1h1gVJ-00087C-N4; Thu, 07 Mar 2019 00:03:17 +0000 From: Al Viro To: Linus Torvalds Cc: Eric Dumazet , David Miller , Jason Baron , kgraul@linux.ibm.com, ktkhai@virtuozzo.com, kyeongdon.kim@lge.com, Linux List Kernel Mailing , Netdev , pabeni@redhat.com, syzkaller-bugs@googlegroups.com, xiyou.wangcong@gmail.com, Christoph Hellwig , zhengbin , bcrl@kvack.org, linux-fsdevel@vger.kernel.org, linux-aio@kvack.org, houtao1@huawei.com, yi.zhang@huawei.com Subject: [PATCH 8/8] aio: move sanity checks and request allocation to io_submit_one() Date: Thu, 7 Mar 2019 00:03:16 +0000 Message-Id: <20190307000316.31133-8-viro@ZenIV.linux.org.uk> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190307000316.31133-1-viro@ZenIV.linux.org.uk> References: <20190307000316.31133-1-viro@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Al Viro makes for somewhat cleaner control flow in __io_submit_one() Signed-off-by: Al Viro --- fs/aio.c | 86 +++++++++++++++++++++++++++++++--------------------------------- 1 file changed, 42 insertions(+), 44 deletions(-) diff --git a/fs/aio.c b/fs/aio.c index af51b1360305..6993581b77b2 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -1788,36 +1788,15 @@ static int aio_poll(struct aio_kiocb *aiocb, const struct iocb *iocb) } static int __io_submit_one(struct kioctx *ctx, const struct iocb *iocb, - struct iocb __user *user_iocb, bool compat) + struct iocb __user *user_iocb, struct aio_kiocb *req, + bool compat) { - struct aio_kiocb *req; struct file *file; int ret; - /* enforce forwards compatibility on users */ - if (unlikely(iocb->aio_reserved2)) { - pr_debug("EINVAL: reserve field set\n"); - return -EINVAL; - } - - /* prevent overflows */ - if (unlikely( - (iocb->aio_buf != (unsigned long)iocb->aio_buf) || - (iocb->aio_nbytes != (size_t)iocb->aio_nbytes) || - ((ssize_t)iocb->aio_nbytes < 0) - )) { - pr_debug("EINVAL: overflow check\n"); - return -EINVAL; - } - - req = aio_get_req(ctx); - if (unlikely(!req)) - return -EAGAIN; - req->ki_filp = fget(iocb->aio_fildes); - ret = -EBADF; if (unlikely(!req->ki_filp)) - goto out_put_req; + return -EBADF; if (iocb->aio_flags & IOCB_FLAG_RESFD) { struct eventfd_ctx *eventfd; @@ -1828,17 +1807,15 @@ static int __io_submit_one(struct kioctx *ctx, const struct iocb *iocb, * event using the eventfd_signal() function. */ eventfd = eventfd_ctx_fdget((int) iocb->aio_resfd); - if (IS_ERR(eventfd)) { - ret = PTR_ERR(eventfd); - goto out_put_req; - } + if (IS_ERR(eventfd)) + return PTR_ERR(req->ki_eventfd); + req->ki_eventfd = eventfd; } - ret = put_user(KIOCB_KEY, &user_iocb->aio_key); - if (unlikely(ret)) { + if (unlikely(put_user(KIOCB_KEY, &user_iocb->aio_key))) { pr_debug("EFAULT: aio_key\n"); - goto out_put_req; + return -EFAULT; } req->ki_user_iocb = user_iocb; @@ -1873,30 +1850,51 @@ static int __io_submit_one(struct kioctx *ctx, const struct iocb *iocb, break; } fput(file); - - /* - * If ret is 0, we'd either done aio_complete() ourselves or have - * arranged for that to be done asynchronously. Anything non-zero - * means that we need to destroy req ourselves. - */ - if (ret) - goto out_put_req; - return 0; -out_put_req: - iocb_put(req); - put_reqs_available(ctx, 1); return ret; } static int io_submit_one(struct kioctx *ctx, struct iocb __user *user_iocb, bool compat) { + struct aio_kiocb *req; struct iocb iocb; + int err; if (unlikely(copy_from_user(&iocb, user_iocb, sizeof(iocb)))) return -EFAULT; - return __io_submit_one(ctx, &iocb, user_iocb, compat); + /* enforce forwards compatibility on users */ + if (unlikely(iocb.aio_reserved2)) { + pr_debug("EINVAL: reserve field set\n"); + return -EINVAL; + } + + /* prevent overflows */ + if (unlikely( + (iocb.aio_buf != (unsigned long)iocb.aio_buf) || + (iocb.aio_nbytes != (size_t)iocb.aio_nbytes) || + ((ssize_t)iocb.aio_nbytes < 0) + )) { + pr_debug("EINVAL: overflow check\n"); + return -EINVAL; + } + + req = aio_get_req(ctx); + if (unlikely(!req)) + return -EAGAIN; + + err = __io_submit_one(ctx, &iocb, user_iocb, req, compat); + + /* + * If err is 0, we'd either done aio_complete() ourselves or have + * arranged for that to be done asynchronously. Anything non-zero + * means that we need to destroy req ourselves. + */ + if (unlikely(err)) { + iocb_put(req); + put_reqs_available(ctx, 1); + } + return err; } /* sys_io_submit: -- 2.11.0