From patchwork Tue Jun 16 15:34:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 224434 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D4709C433DF for ; Tue, 16 Jun 2020 15:58:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B25DF207C4 for ; Tue, 16 Jun 2020 15:58:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592323126; bh=v0CSC7d6WhJ2bIpIBAu+WGTgul81sAmDxaMiaZ1+04c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=xBJbvBy7mwPZ34bSc8/eQhFy1kmIt3nzI0JKqSrkHfSqxysuuGQjh0xU5I36CHxiD vuu15DBDBonjHaGHtCu6885KNeN280W1wbtfdTzOKHIi8Rw8rl/pzMhOtPU+jYWS0r cQEC4Fzdl6k+ex0J+AP8vyTFpOnDEvD6xCImWinQ= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732581AbgFPPyR (ORCPT ); Tue, 16 Jun 2020 11:54:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:53316 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732963AbgFPPyQ (ORCPT ); Tue, 16 Jun 2020 11:54:16 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 95C2821527; Tue, 16 Jun 2020 15:54:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592322856; bh=v0CSC7d6WhJ2bIpIBAu+WGTgul81sAmDxaMiaZ1+04c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Vmju6KLnDmEJx10WHyJar9QMwzw2YwD068apcYi/zy79yDf9CN6MkavvWskHAhsyY m4uIKoDIlr+J2Jeox5Ku0mwdmQWS6819Y+vcJpmzQhAtSeeYuIJOCT3pS+8hZOx0wl 5rkvrZPCKN/vXVeZauEr1iZm91C+3Q44M4otsGn8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xiaoguang Wang , Jens Axboe Subject: [PATCH 5.6 101/161] io_uring: fix mismatched finish_wait() calls in io_uring_cancel_files() Date: Tue, 16 Jun 2020 17:34:51 +0200 Message-Id: <20200616153111.172048635@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200616153106.402291280@linuxfoundation.org> References: <20200616153106.402291280@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Xiaoguang Wang commit d8f1b9716cfd1a1f74c0fedad40c5f65a25aa208 upstream. The prepare_to_wait() and finish_wait() calls in io_uring_cancel_files() are mismatched. Currently I don't see any issues related this bug, just find it by learning codes. Signed-off-by: Xiaoguang Wang Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- fs/io_uring.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -6488,11 +6488,9 @@ static int io_uring_release(struct inode static void io_uring_cancel_files(struct io_ring_ctx *ctx, struct files_struct *files) { - struct io_kiocb *req; - DEFINE_WAIT(wait); - while (!list_empty_careful(&ctx->inflight_list)) { - struct io_kiocb *cancel_req = NULL; + struct io_kiocb *cancel_req = NULL, *req; + DEFINE_WAIT(wait); spin_lock_irq(&ctx->inflight_lock); list_for_each_entry(req, &ctx->inflight_list, inflight_entry) { @@ -6532,6 +6530,7 @@ static void io_uring_cancel_files(struct */ if (refcount_sub_and_test(2, &cancel_req->refs)) { io_put_req(cancel_req); + finish_wait(&ctx->inflight_wait, &wait); continue; } } @@ -6539,8 +6538,8 @@ static void io_uring_cancel_files(struct io_wq_cancel_work(ctx->io_wq, &cancel_req->work); io_put_req(cancel_req); schedule(); + finish_wait(&ctx->inflight_wait, &wait); } - finish_wait(&ctx->inflight_wait, &wait); } static int io_uring_flush(struct file *file, void *data)