Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp3109461pxm; Mon, 28 Feb 2022 12:12:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJyXlp0Rf0uLgGJiQo3hWgLmXiVGsMzdYbh2tw08KsK2AS194CLJxi6jEMD+7SXoiawaIopv X-Received: by 2002:a17:902:6841:b0:150:9b8c:3a67 with SMTP id f1-20020a170902684100b001509b8c3a67mr17331175pln.151.1646079124368; Mon, 28 Feb 2022 12:12:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646079124; cv=none; d=google.com; s=arc-20160816; b=HAURbLulUEzxVwvUq6j2fCHKgbrDx4UbSbhLPpMwV3k/M5H6QuDGvSzSwhrazo5Cnh /MWQJSzTQHJWwr0Qh7jEyN6S/SZiGO1doIBEGH6PrI2R05HPAAjqXleqGUZFFKsyFHbH AmcbDsNCBcm1cZ0QBElyuZ7O/RzLbYIkh7/qmekeIyx9c9TiGmIngr3Qt2jb5L9pYVFo l9o+OzP07z1XHjoJ47ToNKaGnRFlFLJyF68Au4Bpi+JMcCmi/jLMpfsW4W0dDodEfW7b hgXSL8+yTWlHmBjhvRONmDYU1tO3YYNwHe4vqd0K9SHdCJLQdMDHmc1UiT3WBk7uiaBp qtjQ== 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=hJCgUG7Tt5jLrjX4FfPCXbi7ccM+cnN0OEReEFkIUqo=; b=Vt3Pm0rJl7i5BokauTK24/opHTXxTEKovl24GAgnphImVJ5EEd7mLGGK928UKMdR6z QJCbaYuP3cA8TCQ4A9GHmbLrStmG/hPVKltkeRslZReJ0Zhw29IlJrftnafgAiqgsg8v Kay7fL524JnwVI7oGuwpM7L7mswhcahCoxSCGtJ6LxsoEduZj6XEa4tjauIW4Fz9reM1 lyvElG/f8ghi1DE0em/m5Ok6eL83kEfI9I0M4tBkW8Mk3DVr+5lS2Pou+uioNl5P0n3Y 7EQUz1X12eTByjQIfCMBinpdX8nTcf6RsCE5Krpt3GcXm9glJIAlGHNYvGMIn+WnwWti 6WZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=s1kkw2G+; 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 m193-20020a633fca000000b00365926640dfsi10907068pga.779.2022.02.28.12.12.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 12:12:04 -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=s1kkw2G+; 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 BE364156979; Mon, 28 Feb 2022 11:35:20 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238616AbiB1Rs5 (ORCPT + 99 others); Mon, 28 Feb 2022 12:48:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239893AbiB1Rov (ORCPT ); Mon, 28 Feb 2022 12:44:51 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3398DE011; Mon, 28 Feb 2022 09:37:20 -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 AF296B815B3; Mon, 28 Feb 2022 17:37:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0E8EBC340F1; Mon, 28 Feb 2022 17:37:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1646069828; bh=ZEnR+GAjDBZjpE+14yGb57cpNm+jGAGr0eqfvMrPavQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s1kkw2G+I/F8qqz1dMSKCzeH3W22Qdnb8Bzur+M0EzZtBB7DohwDK8gyvCHIvMOJz 7BC4teh0YnTzczNPl+Z6kGHbOJjVOAufe0v/63r4KmL1uQPDaD+CIL+a14fIfyh3SB A5ts2JIrN0h77BrRb83Nj/+V1lCKfS4jsv7untik= 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.15 009/139] io_uring: disallow modification of rsrc_data during quiesce Date: Mon, 28 Feb 2022 18:23:03 +0100 Message-Id: <20220228172348.662485432@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220228172347.614588246@linuxfoundation.org> References: <20220228172347.614588246@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 @@ -7818,7 +7818,15 @@ static int io_rsrc_ref_quiesce(struct io 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);