Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp3112711pxm; Mon, 28 Feb 2022 12:16:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJxDvRTvkSNkndcvE/CS+R/dt6IazuIaX0lZkf83iN0WCmHv0c9PFItxmRc4KjnAWLopiX/t X-Received: by 2002:a17:90a:800b:b0:1bc:1954:9640 with SMTP id b11-20020a17090a800b00b001bc19549640mr18335966pjn.89.1646079385339; Mon, 28 Feb 2022 12:16:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646079385; cv=none; d=google.com; s=arc-20160816; b=ll/Qh2yvHioJ9YDjrB8O+652tzp5s5KPob3dF7iyGNRZ3DKyI+8viIAoN/hJ0fTs92 3JCY+QCQFVZVghrqZeyYOsAdQlDpM26E9QXI1wLSsSjjBqTICFWjLH8KoyOO2tDqy2nz CSC4Bt4hpHhfgJcsNK9b9czutxM5Q8+Y//CkyOvnrth3lCgQS5zfmQmnaG6XQDzUHz0Q 5mYyYV+msG0kU9cuFTR6IlmyczLxCZEfG4zb9ByNzOGJ7eslzpKxq6d8Q4qWxcSjnLH0 LefEtl6L7NlOc0aeTBT3Nt/y6IdKmWonF74+yEo34kE6/ZeKaOarx7XoEv5z1M3VpgY4 vfFQ== 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=96ptYS7X6JzlP3eanOaOXWaaaEiOhAlam36sgdD3gPY=; b=UhwC+WP9b1oWtXU+bl2tpdFisuWSI9gfoTuF3/f/Ez+G8VEZM6hD6YKeJv+tbORXb/ PgyVHM+2sAheim5jXNX1HvqafbaLfw7qyIddMfHv4/TdRN3yRYUfMRdSSE4TDzmE57Ps yzKZs4LgVoS+qRbbvVRcWiKnxzlHtlR87kW37WobisNSgjl4/ezuqhJhqTT20f8SjgFi M/cQyRdMNklFOozWE9Kg+fo0KxQm2DXjOA8bAeFrakuqLqx5zwyXJOllK+ZsmVVG2vKk 48yxv7uUJTqZFrvJx+sLAhZSah2Sm644SwsxjJdrm83r3n4IYA5+gvN7zl36goR6Hxcc hzgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1r5m++GO; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id t191-20020a6378c8000000b00378dbeea808si797035pgc.124.2022.02.28.12.16.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 12:16:25 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1r5m++GO; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6B4CC187B9F; Mon, 28 Feb 2022 11:38:32 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239552AbiB1SBT (ORCPT + 99 others); Mon, 28 Feb 2022 13:01:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240788AbiB1Ryp (ORCPT ); Mon, 28 Feb 2022 12:54:45 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36412532CF; Mon, 28 Feb 2022 09:43:30 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E1A1FB815B8; Mon, 28 Feb 2022 17:43:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4BAFDC340F0; Mon, 28 Feb 2022 17:43:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1646070207; bh=8wWpISkZyJgiArA4xVbREKZImf0BuW/NQ7Py7TDMWyU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1r5m++GOXtzQI6QVc81dkFgi0fIx08n/o8txDG0/WaPk0CgV85UKEAGs1O/syj3/l Zmlgf2qDwsZKwRkYQK8OLRvSWbRiXiH15iTbj+O/FUpbJ07pMU4c5czx9dBuS+dyMm bWYKXrCH1sBsNlyBX9TDfRUNzv93uAxR3R1wgkGU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+ca8bf833622a1662745b@syzkaller.appspotmail.com, Dylan Yudaken , Jens Axboe Subject: [PATCH 5.16 009/164] io_uring: disallow modification of rsrc_data during quiesce Date: Mon, 28 Feb 2022 18:22:51 +0100 Message-Id: <20220228172400.614445343@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220228172359.567256961@linuxfoundation.org> References: <20220228172359.567256961@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dylan Yudaken commit 80912cef18f16f8fe59d1fb9548d4364342be360 upstream. io_rsrc_ref_quiesce will unlock the uring while it waits for references to the io_rsrc_data to be killed. There are other places to the data that might add references to data via calls to io_rsrc_node_switch. There is a race condition where this reference can be added after the completion has been signalled. At this point the io_rsrc_ref_quiesce call will wake up and relock the uring, assuming the data is unused and can be freed - although it is actually being used. To fix this check in io_rsrc_ref_quiesce if a resource has been revived. Reported-by: syzbot+ca8bf833622a1662745b@syzkaller.appspotmail.com Cc: stable@vger.kernel.org Signed-off-by: Dylan Yudaken Link: https://lore.kernel.org/r/20220222161751.995746-1-dylany@fb.com Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- fs/io_uring.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -7865,7 +7865,15 @@ static __cold int io_rsrc_ref_quiesce(st ret = wait_for_completion_interruptible(&data->done); if (!ret) { mutex_lock(&ctx->uring_lock); - break; + if (atomic_read(&data->refs) > 0) { + /* + * it has been revived by another thread while + * we were unlocked + */ + mutex_unlock(&ctx->uring_lock); + } else { + break; + } } atomic_inc(&data->refs);