Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2241192pxb; Thu, 11 Feb 2021 07:44:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJzzIRH4iVlBHZHGrD1ZuxEpepKljhkQKOp6b0g3dthua7Wzm0+gMryn+pa8q75qACIc50fv X-Received: by 2002:a17:907:7346:: with SMTP id dq6mr8858245ejc.230.1613058296455; Thu, 11 Feb 2021 07:44:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613058296; cv=none; d=google.com; s=arc-20160816; b=T2OFURIs+268Zd5+BoOGpxv6CnmEfuw26Uhdl5h5K3tBSzJW/7zDQ3L15mDsSojeEl dm/9FyRg8j/UfeoYclRXE9j/R3zppK0YBSksCbDrfntIcfnuV6t6N9ip6XagpMKOogoa 38fuq6sulppmBsXNRcRTLl2+mMgazis3lxE9zRWSZLm+nGRJ8KN4eq7lxTPDFbp2A2Rw 29dSR+7doWP1f2sDSFscxPGeE6hjxrRb/oQKw1VcFf53vIF1S7F8bCBQxD9+merkhFa7 RWw8ZVNYvHF3lgTX02x2MTeg3Sh9BhQUM+X7G0zQkiHboPJMQXG3vm8g0HV591BshTw0 1fLw== 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=QdgMOxlC6FVlnDTb41NWYy2B7cQfIXONKW3xuWyX1go=; b=c/BXw3Juu4AxWkHGPOBZpf4EIrV/vwYFreoL16C87AASS+gdexwnmMX5MwCrQZt1mK 9CQU2k7LAO16emIcMacJYrCZjqLCrDZL+zY7dhtR8rG6l78kBGoaK6DqKxPrAsQI2lWl 2uLomJY2hQu6Zr+pB5hRiGdBYWsh2BqYtzLg5EnUSvH4TUcx3a5phH/XTnrMXUv2V71/ 0QY97pYoUDI+QuIX0D8FdKlLq24ql4M7vHWveipQDqWG5jjww3UVvieLLD8GvkYwK3i6 4odP/Xpqwmswz1X5fE5ByW2Au+o4soF3/umsIoK7Yi48chFNDYPlhmaBvky+6dr+fFJL X+Mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sv8X69y4; 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 u6si4001470ejg.478.2021.02.11.07.44.17; Thu, 11 Feb 2021 07:44: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=sv8X69y4; 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 S231216AbhBKPkm (ORCPT + 99 others); Thu, 11 Feb 2021 10:40:42 -0500 Received: from mail.kernel.org ([198.145.29.99]:52050 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229994AbhBKPNT (ORCPT ); Thu, 11 Feb 2021 10:13:19 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6FA9A64EE0; Thu, 11 Feb 2021 15:04:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1613055854; bh=gkjjU0cWn6r6mUnqxWF0zNwercMq0Vi2f+VeWqVeNkw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sv8X69y4nkCg9uV0NJpVq1p5jcRD9VwTqem0FIUiUoMlLvy93OdT0jwuMp4y2dzmY 0PZYsO+knQcM01bhQ2voMghz+NiyAB2yIX+euOsfXrOfmjTSNaenVo7/6+/FP0znY3 +c+xH9w+F4DTb7uBHY3MB9gLGqx45615xLYL4d9A= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , syzbot+c0d52d0b3c0c3ffb9525@syzkaller.appspotmail.com, Pavel Begunkov , Jens Axboe Subject: [PATCH 5.10 06/54] io_uring: fix files cancellation Date: Thu, 11 Feb 2021 16:01:50 +0100 Message-Id: <20210211150153.157105213@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210211150152.885701259@linuxfoundation.org> References: <20210211150152.885701259@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 [ Upstream commit bee749b187ac57d1faf00b2ab356ff322230fce8 ] io_uring_cancel_files()'s task check condition mistakenly got flipped. 1. There can't be a request in the inflight list without IO_WQ_WORK_FILES, kill this check to keep the whole condition simpler. 2. Also, don't call the function for files==NULL to not do such a check, all that staff is already handled well by its counter part, __io_uring_cancel_task_requests(). With that just flip the task check. Also, it iowq-cancels all request of current task there, don't forget to set right ->files into struct io_task_cancel. Fixes: c1973b38bf639 ("io_uring: cancel only requests of current task") Reported-by: syzbot+c0d52d0b3c0c3ffb9525@syzkaller.appspotmail.com 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 @@ -8571,15 +8571,14 @@ static void io_uring_cancel_files(struct struct files_struct *files) { while (!list_empty_careful(&ctx->inflight_list)) { - struct io_task_cancel cancel = { .task = task, .files = NULL, }; + struct io_task_cancel cancel = { .task = task, .files = files }; struct io_kiocb *req; DEFINE_WAIT(wait); bool found = false; spin_lock_irq(&ctx->inflight_lock); list_for_each_entry(req, &ctx->inflight_list, inflight_entry) { - if (req->task == task && - (req->work.flags & IO_WQ_WORK_FILES) && + if (req->task != task || req->work.identity->files != files) continue; found = true; @@ -8665,10 +8664,11 @@ static void io_uring_cancel_task_request io_cancel_defer_files(ctx, task, files); io_cqring_overflow_flush(ctx, true, task, files); - io_uring_cancel_files(ctx, task, files); if (!files) __io_uring_cancel_task_requests(ctx, task); + else + io_uring_cancel_files(ctx, task, files); if ((ctx->flags & IORING_SETUP_SQPOLL) && ctx->sq_data) { atomic_dec(&task->io_uring->in_idle);