Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9105864pxu; Mon, 28 Dec 2020 06:47:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJyaeQiFuuUb97aXG4vblb6UF+BoCNlJu0VWiROAgdivbFYnFr/hfCFqipuphfCU5sT7Eg+Q X-Received: by 2002:a17:907:c05:: with SMTP id ga5mr40146492ejc.32.1609166837542; Mon, 28 Dec 2020 06:47:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609166837; cv=none; d=google.com; s=arc-20160816; b=liwOVcZJN4EtfFhVYTWgPIWGsWgecr2xKlg3ON5i8/ILNNoBCH55zLEZ5wkFYbmS0V B7WNUyLFCwxjG7zWZpHbPH5NwcShsK+ar/N97vuz8/44dQ8qKmZGhIxUZ/4qwXiRBBhH GhPCESzWrfsBXb13ktEUC0gF770vGIy0eP20/IxMKPmBRWYApMQrpPPXmssZpP/ynOLG nXc+0hggGfDU9WCj26GC6XIUoU/aREWUcX8eqF6c4LdRi4Qk8C6faF0Q9QgxnroTrCoG 1jy9WXMDRdvrn/HxkoDK7F6EfteUGpwhaQbWnGm62hnQx2henYMlWUCGHozroaIxjBu0 vQnA== 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=MbyQBNv4IpN5nGnHB0XSQMG4ebS3F50aFTF1gtQaJeQ=; b=M3ZTFzQL5aI9c1mJsW2J06FWWGjukWtSE0VmBT48Uonn5XPek9KqmlkhhXjRPQn1Mj SrEN1Pj2QC0Xbw6regVDDxCmAmqTL5byCwHPiHNlgkfGXRCVuDD3k2bxMRa1OuYFf96i Xx94dHbhysn6u5tsL6lWZKePSbARWJH0ElyfsjsESSqFH37RBlmg0mSMHxoj1r2LRKQe DmwIJePREfRjR6YbFYm4884g/S1hEYVZ8w0skrPc4Bc88y26tjZ9U1IY7El4so9t9C+1 9an+BsFhujuN5t/EAfPabQAZCg4ZXdUtJ1XZLet7fvNZnoF4pWCYWeaQb5+0g/jN0mWM 4dAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lriEL4bP; 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 v3si17950305eje.650.2020.12.28.06.46.54; Mon, 28 Dec 2020 06:47:17 -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=lriEL4bP; 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 S2392073AbgL1Oom (ORCPT + 99 others); Mon, 28 Dec 2020 09:44:42 -0500 Received: from mail.kernel.org ([198.145.29.99]:32850 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2503162AbgL1OY5 (ORCPT ); Mon, 28 Dec 2020 09:24:57 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id A387422AEC; Mon, 28 Dec 2020 14:24:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609165457; bh=pMvmUkbPIgx+8nGnsq2F0E4jxQfgWmKkiJllS1egw94=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lriEL4bP3RTKKZfCh4aRBHoZRECLZ3g+La2y2Mde9h/gyW2tnxo5In37wnjPjAJlz q4qgVzXF7CLdfuieew36MvkMWGVIY2H8oRN9XsOJGhs12PztJsgkpIvAMIW3EBaLzA YhP2/mdPiw7qdWuIZ5Tj7CJpYgVxMDBWs8QjRJa4= 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 511/717] io_uring: fix racy IOPOLL completions Date: Mon, 28 Dec 2020 13:48:29 +0100 Message-Id: <20201228125045.447543868@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228125020.963311703@linuxfoundation.org> References: <20201228125020.963311703@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 31bff9a51b264df6d144931a6a5f1d6cc815ed4b upstream. IOPOLL allows buffer remove/provide requests, but they doesn't synchronise by rules of IOPOLL, namely it have to hold uring_lock. Cc: # 5.7+ Signed-off-by: Pavel Begunkov Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- fs/io_uring.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -3944,11 +3944,17 @@ static int io_remove_buffers(struct io_k head = idr_find(&ctx->io_buffer_idr, p->bgid); if (head) ret = __io_remove_buffers(ctx, head, p->bgid, p->nbufs); - - io_ring_submit_lock(ctx, !force_nonblock); if (ret < 0) req_set_fail_links(req); - __io_req_complete(req, ret, 0, cs); + + /* need to hold the lock to complete IOPOLL requests */ + if (ctx->flags & IORING_SETUP_IOPOLL) { + __io_req_complete(req, ret, 0, cs); + io_ring_submit_unlock(ctx, !force_nonblock); + } else { + io_ring_submit_unlock(ctx, !force_nonblock); + __io_req_complete(req, ret, 0, cs); + } return 0; } @@ -4033,10 +4039,17 @@ static int io_provide_buffers(struct io_ } } out: - io_ring_submit_unlock(ctx, !force_nonblock); if (ret < 0) req_set_fail_links(req); - __io_req_complete(req, ret, 0, cs); + + /* need to hold the lock to complete IOPOLL requests */ + if (ctx->flags & IORING_SETUP_IOPOLL) { + __io_req_complete(req, ret, 0, cs); + io_ring_submit_unlock(ctx, !force_nonblock); + } else { + io_ring_submit_unlock(ctx, !force_nonblock); + __io_req_complete(req, ret, 0, cs); + } return 0; }