From patchwork Tue Jun 11 23:56:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Bates X-Patchwork-Id: 10988381 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 12B1A13AD for ; Tue, 11 Jun 2019 23:56:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 02168280B0 for ; Tue, 11 Jun 2019 23:56:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EA74828488; Tue, 11 Jun 2019 23:56:17 +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,DKIM_SIGNED, DKIM_VALID,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 75EE428389 for ; Tue, 11 Jun 2019 23:56:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405336AbfFKX4L (ORCPT ); Tue, 11 Jun 2019 19:56:11 -0400 Received: from mail-eopbgr670097.outbound.protection.outlook.com ([40.107.67.97]:63909 "EHLO CAN01-TO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2404808AbfFKX4L (ORCPT ); Tue, 11 Jun 2019 19:56:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raithlin.onmicrosoft.com; s=selector1-raithlin-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=PLgT1++JPQi0Nu33GWU22HzN/RiC/hSZKCNg3J2n85c=; b=VsLjOkbAV58pz5Ss65s2n9vGMg5+1/jAJN/UYsz2tGA3NreKD76Z398E2Q1I2AycWXmN01pIxrNIWkXvOhxox28Yox10Snu2IpZfUZ8iTHVEqCxNZ0hxqNv06Q5CSRs9vnR54wnzhZPXm+soQBVPwQuR304G4jWfdLbMpYHeom8= Received: from YTOPR0101MB0793.CANPRD01.PROD.OUTLOOK.COM (52.132.44.17) by YTOPR0101MB2250.CANPRD01.PROD.OUTLOOK.COM (52.132.50.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1965.14; Tue, 11 Jun 2019 23:56:06 +0000 Received: from YTOPR0101MB0793.CANPRD01.PROD.OUTLOOK.COM ([fe80::3535:ab58:99bd:516]) by YTOPR0101MB0793.CANPRD01.PROD.OUTLOOK.COM ([fe80::3535:ab58:99bd:516%7]) with mapi id 15.20.1965.017; Tue, 11 Jun 2019 23:56:06 +0000 From: "Stephen Bates" To: "linux-block@vger.kernel.org" , "linux-fsdevel@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Jens Axboe , "mark.rutland@arm.com" , "shhuiw@foxmail.com" , Logan Gunthorpe , "viro@zeniv.linux.org.uk" Subject: [PATCH] io_uring: fix SQPOLL cpu check Thread-Topic: [PATCH] io_uring: fix SQPOLL cpu check Thread-Index: AQHVILE8MKvlFSwx2kqc/AjEamoMkQ== Date: Tue, 11 Jun 2019 23:56:06 +0000 Message-ID: <5D2859FE-DB39-48F5-BBB5-6EDD3791B6C3@raithlin.com> Accept-Language: en-CA, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: user-agent: Microsoft-MacOutlook/10.1a.0.190609 authentication-results: spf=none (sender IP is ) smtp.mailfrom=sbates@raithlin.com; x-originating-ip: [2001:bb6:a2c:ed58:2ca3:41e6:9240:e71d] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 2759eb70-7fcd-4e28-87ee-08d6eec85eb9 x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(7021145)(8989299)(4534185)(7022145)(4603075)(4627221)(201702281549075)(8990200)(7048125)(7024125)(7027125)(7023125)(5600148)(711020)(4605104)(1401327)(2017052603328)(7193020);SRVR:YTOPR0101MB2250; x-ms-traffictypediagnostic: YTOPR0101MB2250: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:7219; x-forefront-prvs: 006546F32A x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(346002)(376002)(39830400003)(366004)(136003)(396003)(199004)(189003)(68736007)(76116006)(58126008)(486006)(54906003)(6506007)(476003)(6486002)(33656002)(256004)(99286004)(2616005)(2201001)(36756003)(110136005)(2501003)(316002)(102836004)(2906002)(71190400001)(305945005)(86362001)(6512007)(81166006)(81156014)(8676002)(71200400001)(8936002)(14454004)(508600001)(66476007)(66946007)(66556008)(64756008)(91956017)(4744005)(186003)(66446008)(73956011)(25786009)(5660300002)(4326008)(7736002)(53936002)(6116002)(6436002)(46003);DIR:OUT;SFP:1102;SCL:1;SRVR:YTOPR0101MB2250;H:YTOPR0101MB0793.CANPRD01.PROD.OUTLOOK.COM;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: raithlin.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: FUytEI66HLW7guPRGv0aVzJAUnXoyumZ84/l5JRlU5cPVraiBZGOoXnVzVnSePGt/oMTAfYOaFaE6rHFOvpn8pRzKXgrCgvj1a2NhmR4XgkeMME8npqI66Eq2gUIDZUBMM0hnPUBBBQydD/xwRpQEuoYM014Milf88wY+OWYWce5kuMpnEqt08sk+OSizTW/Yt5SZLzkAkvUppfUnRAJiAmYX6ZvvASmnGNiRoida/S5GdfQM94wJ9Fsy9m/NOFtL/Nzp78SsLshzb+dN0kUC2s7XZb++QJuJvLCT1Oh11CyFW6Aw0ifQ0yG/UHVnI06U0EYSfBrcFrj1cKnqh8hC/Atgf8Et50ytdGwEkvDiBIK1SUnFWRAJOvcyyZHg6e1QSyZpcoDOYpQjf47ZN/Q9pzK0E/PoH0BCkeBKf8eyqU= Content-ID: MIME-Version: 1.0 X-OriginatorOrg: raithlin.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2759eb70-7fcd-4e28-87ee-08d6eec85eb9 X-MS-Exchange-CrossTenant-originalarrivaltime: 11 Jun 2019 23:56:06.8641 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 18519031-7ff4-4cbb-bbcb-c3252d330f4b X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: sbates@raithlin.com X-MS-Exchange-Transport-CrossTenantHeadersStamped: YTOPR0101MB2250 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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;