Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp296373pxk; Fri, 11 Sep 2020 07:12:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxw+Er3Vk/cdbnwON681W9GON7yxP1RTMtpkGELXO+SmSH1VZIBPuejFWNyK2HgrFmhprkE X-Received: by 2002:a05:6402:1d93:: with SMTP id dk19mr2228608edb.198.1599833572576; Fri, 11 Sep 2020 07:12:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599833572; cv=none; d=google.com; s=arc-20160816; b=qpkwqQtMdQr7omeSaAySJ1jdftP216oQIBMYa0gtM/WGNH4ejio68SSQ7h15BSxwqO CoriZJUTEoaxM436aW3BMCxjolo9XT4N87uQ+ygzMIHM4s488j/d6AWOYMPXOqrI2oNe AxWuBYKEmNvTUHFLnizH0jYm2TPbGHgTaFqP1tUgJF4sXtAs13juEXeAtmOmL3fqnZV5 Q7aqcFDnxKu8dzWHpPVC2E+J/cSXog6MH2UfS6HNalBKgxqjiwd81fOKX/vq4ts0JAPO dowDqEEsRkiuGp8XJIj5NL+Ks+DdyQssWEFWJMbdFN5g5SFjnoV+6bIbcs3AyyHdqksk R+8g== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=7FW32oeERm0ENCWcfw2ufeAd3nAFiKoNCAY78A7xgI4=; b=yYjpJ7q+jPVZ2+ZiqrACB+oeQ6WAcWNjPXjtPchhMyBPY9KTCSRXRBWhRqmKjlBvUh 9w8c14K+IFuvMFkmUBWdZf+0xhjIYAeF2bvbADxDU2nNX1JHVll92spNIYV6Hits0eCD xQex9mjJ8TF4XL2f5waskHPi7mYiAradL6jLQehsDLInnJ8vCJICsUWdn05qBAnhjAaR NgDUBHdv53WwjrFT3R3wsJq1olwsS5fRY0b+W0fk2wOvl6hLE/xqVQgLqxsuw77WyBoN wTztEt5rfibZ777fwDpi2XxJI58qzLIZwA6tXWkHMQrO5QJiyEmS2azqmHTMJgOVe90I Uh0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="MwFL+i/D"; 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=fail (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 a9si1343969ejx.166.2020.09.11.07.12.28; Fri, 11 Sep 2020 07:12:52 -0700 (PDT) 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=@kernel.org header.s=default header.b="MwFL+i/D"; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726205AbgIKOJf (ORCPT + 99 others); Fri, 11 Sep 2020 10:09:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:35740 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726282AbgIKN3X (ORCPT ); Fri, 11 Sep 2020 09:29:23 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F3E3E2245D; Fri, 11 Sep 2020 12:59:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599829188; bh=RV6uXMAPMOa5KZMYxcVcnmRvi9ObHug+YNzLU1eB/PI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MwFL+i/DY7mteBn340vV9gwEiOG79RAhPLVs6XC/c/rrZDfHQcMrFQm6QaHrXmJIT doD7bPd1l2/RM9L5HERvAqlWLGWZGKNx+bwcL45laOUDnTtB2yVLOvoScv4yGo4vDj f1K3Rh0HsgvIJ+vk8394DOLvGQ0e0vHub7OtCzO8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pavel Begunkov , Jens Axboe , Sasha Levin Subject: [PATCH 5.8 02/16] io_uring: fix linked deferred ->files cancellation Date: Fri, 11 Sep 2020 14:47:19 +0200 Message-Id: <20200911122459.714236078@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200911122459.585735377@linuxfoundation.org> References: <20200911122459.585735377@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pavel Begunkov [ Upstream commit c127a2a1b7baa5eb40a7e2de4b7f0c51ccbbb2ef ] While looking for ->files in ->defer_list, consider that requests there may actually be links. Signed-off-by: Pavel Begunkov Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- fs/io_uring.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 5f627194d0920..d05023ca74bdc 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -7601,6 +7601,28 @@ static bool io_match_link(struct io_kiocb *preq, struct io_kiocb *req) return false; } +static inline bool io_match_files(struct io_kiocb *req, + struct files_struct *files) +{ + return (req->flags & REQ_F_WORK_INITIALIZED) && req->work.files == files; +} + +static bool io_match_link_files(struct io_kiocb *req, + struct files_struct *files) +{ + struct io_kiocb *link; + + if (io_match_files(req, files)) + return true; + if (req->flags & REQ_F_LINK_HEAD) { + list_for_each_entry(link, &req->link_list, link_list) { + if (io_match_files(link, files)) + return true; + } + } + return false; +} + /* * We're looking to cancel 'req' because it's holding on to our files, but * 'req' could be a link to another request. See if it is, and cancel that @@ -7683,8 +7705,7 @@ static void io_cancel_defer_files(struct io_ring_ctx *ctx, spin_lock_irq(&ctx->completion_lock); list_for_each_entry_reverse(req, &ctx->defer_list, list) { - if ((req->flags & REQ_F_WORK_INITIALIZED) - && req->work.files == files) { + if (io_match_link_files(req, files)) { list_cut_position(&list, &ctx->defer_list, &req->list); break; } -- 2.25.1