Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5441179ybi; Wed, 12 Jun 2019 02:32:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqyFJLJ8dq6PG/KGau0R6DQcVJL/uR1NhhKg81rEsnWXW1v9uWSrDwWujqUIvHFJL4iCe8uk X-Received: by 2002:a17:902:7e0e:: with SMTP id b14mr56007277plm.257.1560331957437; Wed, 12 Jun 2019 02:32:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560331957; cv=none; d=google.com; s=arc-20160816; b=ZRckeRDlREDS6cALDlmsWVZFKuzNfhgqebQJHGvOsz9946/6y+6gn2+R41Al7cVqZ9 M9VJgzQwGj41yTW0TUHgWQ3DUKDdRCjW/A0wUgMztTugmScMkbBhzZGvmwITIleDtCOl CVdS67vuK5xmmBPM2qkMBcrZp75QUhqdRvNS7SaOwOOYi3Eg3O99pDsGLEthvV35SGMW 7ktcTtgv0IsUMGUR/gqUt3OWuVGoTaPwGuAth0xg9gbXdysBgBxGS7DNL+S6BIHLD8PB 7P3o2eVKDK+9nzN6TwYWYy7QZ+DLISJ12nhvoF5ph8ZZ5gCE9631HFLQNtQOfVwieSL+ mnGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=KNtZd89Zeyfh4ko46imRVka+CMjT9Xe7UzXXQe/dcHU=; b=uceFxcWHRop3aUFTyS5/8fefYLqPWvoYp7aWxexYJW/2ORboptA3/meiZ6lAmu3U/s LH7yFw/xjwRIzWJ4Fu0wQdpYg935SDQ0kIoqfHdEv7tslV+0jswZu8TmiSSep7ElPmMw nObwrgxbvyBPgW4ilVwXajthq8OsHJZFX5ZlBDRaQmzie5NrLGbgWbUb97iBLlD3f3p7 sAeZ9AGjN0cDOze3s5rKMZOchFtpHB39krsWkPj+qgp5jd8BSN57LQYqgQSCBhBjZkdT bHiQoF1IjCvrYn0nt1V774bWi1DHm9EWOz6NjRWP9OJshWwEc+P4zKHEed/TEgMjUd+Z uu7Q== 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 q14si14680358pls.327.2019.06.12.02.32.21; Wed, 12 Jun 2019 02:32:37 -0700 (PDT) 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 S1731708AbfFLJYO (ORCPT + 99 others); Wed, 12 Jun 2019 05:24:14 -0400 Received: from foss.arm.com ([217.140.110.172]:48282 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731233AbfFLJYO (ORCPT ); Wed, 12 Jun 2019 05:24:14 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4179B28; Wed, 12 Jun 2019 02:24:13 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1E54E3F246; Wed, 12 Jun 2019 02:24:12 -0700 (PDT) Date: Wed, 12 Jun 2019 10:24:04 +0100 From: Mark Rutland To: Stephen Bates Cc: "linux-block@vger.kernel.org" , "linux-fsdevel@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Jens Axboe , "shhuiw@foxmail.com" , Logan Gunthorpe , "viro@zeniv.linux.org.uk" Subject: Re: [PATCH] io_uring: fix SQPOLL cpu check Message-ID: <20190612092403.GA38578@lakrids.cambridge.arm.com> References: <5D2859FE-DB39-48F5-BBB5-6EDD3791B6C3@raithlin.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5D2859FE-DB39-48F5-BBB5-6EDD3791B6C3@raithlin.com> User-Agent: Mutt/1.11.1+11 (2f07cb52) (2018-12-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 11, 2019 at 11:56:06PM +0000, Stephen Bates wrote: > The array_index_nospec() check in io_sq_offload_start() is performed > before any checks on p->sq_thread_cpu are done. This means cpu is > clamped and therefore no error occurs when out-of-range values are > passed in from userspace. This is in violation of the specification > for io_ring_setup() and causes the io_ring_setup unit test in liburing > to regress. > > Add a new bounds check on sq_thread_cpu at the start of > io_sq_offload_start() so we can exit the function early when bad > values are passed in. > > Fixes: 975554b03edd ("io_uring: fix SQPOLL cpu validation") > Signed-off-by: Stephen Bates Aargh. My original patch [1] handled that correctly, and this case was explicitly called out in the commit message, which was retained even when the patch was "simplified". That's rather disappointing. :/ Thanks, Mark. [1] https://lore.kernel.org/lkml/20190430123451.44227-1-mark.rutland@arm.com/ > --- > fs/io_uring.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/fs/io_uring.c b/fs/io_uring.c > index 30a5687..e458470 100644 > --- a/fs/io_uring.c > +++ b/fs/io_uring.c > @@ -2316,6 +2316,9 @@ static int io_sq_offload_start(struct io_ring_ctx *ctx, > { > int ret; > > + if (p->sq_thread_cpu >= nr_cpu_ids) > + return -EINVAL; > + > init_waitqueue_head(&ctx->sqo_wait); > mmgrab(current->mm); > ctx->sqo_mm = current->mm; > -- > 2.7.4 >