Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp13956770pxu; Mon, 4 Jan 2021 08:57:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJxSEhALOA8/rdbjvzJzR3mlzE2NRuw8fn5R2VQ+iOG3IfKuLm8W85585/TnPP4XLYpFEWdu X-Received: by 2002:a50:bf4a:: with SMTP id g10mr70386780edk.201.1609779476965; Mon, 04 Jan 2021 08:57:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609779476; cv=none; d=google.com; s=arc-20160816; b=NcLRfL6kiAhqQiQRfsPn5Ns0huhHatqOqC/ugIBty0ZFi01dvtWsv8V1M/lRMIkUFU jq5X7gvKa+A55V9zFWJyuSgthydYV0pjRsb3JFKa4SV1WAc5pU9BHiXLvZjcEvyJN0dy eUIjErrYqKPpUztFcidE+EBhtOVHf+/AxOZ0S5tqKBeSnrIpY2sJSKLD1i6nx7Pj3deC GdRcYdSqBhEG8+IIxBreTZcdUZDquVpP9J3upJQLq1EyrwFI2twXB+IselQVY7HIA64D oYM4iMM2BW3wPXI0TDKay6+8yegCLe5Bmzc6kFZeKXvi5KsNtabWT40LbY5pioLRYDmD WhUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=VpQ9dbszSuixN1h5FH1W9GAW9WgpicPp8sVdzKwEgss=; b=hB+ZgnnfRj7ljyI62/bFBpq4p0sfozfiKtWNQ1edhxyfdn21lt9nYRNt6CZ2m+B4Lk 5NEfDHBzTYBgAD5IekP4WuK1QjyM5E7T7zZWxLWfdx4MCkek6uwQSkuUmEb0oYQen5h7 oMzZueW4R8N/SvjtP0SF9BzMdbi7AHdhU6eqKwc0Qfk2exYz5RplSiTppVosW+QC7hAo mBYQoQtwfnjXFRwdv/KYjeLdy/3Ow6fidHEIAF5Oy2jabeJmV27uEMLLPgGasZcsuHou /gcM+j2HamBORXRMTHiS6HpSlkaiGIVZEeYtNa97w1egp6kRrhAGGxgok8j3ETahdGLO QrKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=WqcRg1nN; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bd1si31295608edb.168.2021.01.04.08.57.33; Mon, 04 Jan 2021 08:57:56 -0800 (PST) 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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=WqcRg1nN; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729287AbhADQGb (ORCPT + 99 others); Mon, 4 Jan 2021 11:06:31 -0500 Received: from mail.kernel.org ([198.145.29.99]:40346 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728948AbhADQC4 (ORCPT ); Mon, 4 Jan 2021 11:02:56 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9A79522473; Mon, 4 Jan 2021 16:02:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609776136; bh=Ny1A5XdaJPEyUXhWYxlde/SXbDrlL4EpOPW8Cwta6Lk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WqcRg1nN8BKruzYGWnDTvzp4ou7aPg415MP3A0csNGUwKfY2gc3mLni8SpZtvvwg5 1SNlTW0pZ5O7hzWmz3pVNR1Qy5744vTaZg/qIhpqSyYRwHm9BqlzH0xtvzXbtOvDMA 75BUn3aHtJxmaaQQXQWZvOEUPbxdOfXPxPjBaXPo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pavel Begunkov , Jens Axboe Subject: [PATCH 5.10 07/63] io_uring: close a small race gap for files cancel Date: Mon, 4 Jan 2021 16:57:00 +0100 Message-Id: <20210104155709.164282473@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210104155708.800470590@linuxfoundation.org> References: <20210104155708.800470590@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pavel Begunkov commit dfea9fce29fda6f2f91161677e0e0d9b671bc099 upstream. The purpose of io_uring_cancel_files() is to wait for all requests matching ->files to go/be cancelled. We should first drop files of a request in io_req_drop_files() and only then make it undiscoverable for io_uring_cancel_files. First drop, then delete from list. It's ok to leave req->id->files dangling, because it's not dereferenced by cancellation code, only compared against. It would potentially go to sleep and be awaken by following in io_req_drop_files() wake_up(). Fixes: 0f2122045b946 ("io_uring: don't rely on weak ->files references") Cc: # 5.5+ Signed-off-by: Pavel Begunkov Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- fs/io_uring.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -5861,15 +5861,15 @@ static void io_req_drop_files(struct io_ struct io_ring_ctx *ctx = req->ctx; unsigned long flags; + put_files_struct(req->work.identity->files); + put_nsproxy(req->work.identity->nsproxy); spin_lock_irqsave(&ctx->inflight_lock, flags); list_del(&req->inflight_entry); - if (waitqueue_active(&ctx->inflight_wait)) - wake_up(&ctx->inflight_wait); spin_unlock_irqrestore(&ctx->inflight_lock, flags); req->flags &= ~REQ_F_INFLIGHT; - put_files_struct(req->work.identity->files); - put_nsproxy(req->work.identity->nsproxy); req->work.flags &= ~IO_WQ_WORK_FILES; + if (waitqueue_active(&ctx->inflight_wait)) + wake_up(&ctx->inflight_wait); } static void __io_clean_op(struct io_kiocb *req)