Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4365895pxj; Tue, 8 Jun 2021 12:31:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzn6tNd80smCr+zQ4dGuaqaPV+B/qSq41K0bFhOnx4anm2VEjDGKDTOMvWqvecRdRzlOxR8 X-Received: by 2002:a17:906:6dc3:: with SMTP id j3mr25337453ejt.448.1623180685026; Tue, 08 Jun 2021 12:31:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623180685; cv=none; d=google.com; s=arc-20160816; b=H4xXKxrBaoj69lhJdH+KW8tUMHEOORTsen4er2E2/8WLnrf4iHeufGbuG49THtwLT3 DMtpbHJDT0dRX+83E0RJAgon2H1sLbTPASFu7+4JDrDigy0D2r9RxYDj4XI9LOEKhuIv Yy0LoeDrp869zjPvqD59NDr/KZ37CzZIM27ts04wWmNNVSg2b2AmBxt9NGLIpoWsJlZk TtyHuaObVLzWLwcjWJu5e293XjLOUpTswEt1ic8XfCCtC2huds7hK6GkuH/nzs7kBPMu Vet0X4AD3i84J7nYWWYBPdwMTYrxO+iwE3mMJQkzfHGXTXdhBNuxE3ODElCmw26yBH+X hHKQ== 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=mBubEFbgxlugar0bYrJvJpJNVV0gILENveCqRXwwhS8=; b=rahmwv+qFR4BjsiTPXCFUugBMLRPIwk+4jfU9vli3pqTewXkUHI3w3bo8RELdBjIyF AuApPeO0tdIeKAZgfyY4k4Zsest1Pp3JB3hKmYCzqV0ZRTk6BYWARxLmbMrIXpdGYp2R twICGf5pMcYFnqluMC3Z1PZoik2iuBt+68DIiCb+SoSF8KYJOYEumLiSpPWPIW8BDt6q tEp0KpHP7lmP4ekrkIUgQ4uMNy96jatkIpoftlPBbOHfsgyDIoMD4plqVM5TQFrJwQWW XKu56mn15h3Sb9LZRUKQ8x0hBu4tu1jzYO/1WAvlw78wfOUNCHeMQ6GRYnVcJcUfY4DN USVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=PBPM0B3Z; 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 v5si526941edi.123.2021.06.08.12.31.01; Tue, 08 Jun 2021 12:31:25 -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=@linuxfoundation.org header.s=korg header.b=PBPM0B3Z; 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 S236227AbhFHT1i (ORCPT + 99 others); Tue, 8 Jun 2021 15:27:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:36962 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238343AbhFHTOq (ORCPT ); Tue, 8 Jun 2021 15:14:46 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id ECEEF61434; Tue, 8 Jun 2021 18:50:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623178223; bh=Q3LK4c37Lcc4PeoLN/dLINCVDg5mSVxY0TkKAzM5HDE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PBPM0B3ZBX0+RyeQJjlSe8eCtoH87FPmnkDU0kTW9SW3jtltQ7tHZlZKzsKd1omvb 2MpVNbpNrfScbwoPM1paYxuNXjL3T3BL3/nnU8xNZBVCF0u6NUJoyRKeJ6uF30HnZG rb+KOWE4IIg4Uq/jqTIdxESLKXM2XMAHqAIBgDU0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pavel Begunkov , Jens Axboe , Sasha Levin , syzbot+5a864149dd970b546223@syzkaller.appspotmail.com Subject: [PATCH 5.12 088/161] io_uring: fix ltout double free on completion race Date: Tue, 8 Jun 2021 20:26:58 +0200 Message-Id: <20210608175948.412603388@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210608175945.476074951@linuxfoundation.org> References: <20210608175945.476074951@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 447c19f3b5074409c794b350b10306e1da1ef4ba ] Always remove linked timeout on io_link_timeout_fn() from the master request link list, otherwise we may get use-after-free when first io_link_timeout_fn() puts linked timeout in the fail path, and then will be found and put on master's free. Cc: stable@vger.kernel.org # 5.10+ Fixes: 90cd7e424969d ("io_uring: track link timeout's master explicitly") Reported-and-tested-by: syzbot+5a864149dd970b546223@syzkaller.appspotmail.com Signed-off-by: Pavel Begunkov Link: https://lore.kernel.org/r/69c46bf6ce37fec4fdcd98f0882e18eb07ce693a.1620990121.git.asml.silence@gmail.com Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- fs/io_uring.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index dd8b3fac877c..359d1abb089c 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -6289,10 +6289,11 @@ static enum hrtimer_restart io_link_timeout_fn(struct hrtimer *timer) * We don't expect the list to be empty, that will only happen if we * race with the completion of the linked work. */ - if (prev && req_ref_inc_not_zero(prev)) + if (prev) { io_remove_next_linked(prev); - else - prev = NULL; + if (!req_ref_inc_not_zero(prev)) + prev = NULL; + } spin_unlock_irqrestore(&ctx->completion_lock, flags); if (prev) { -- 2.30.2