Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2609012rwb; Wed, 30 Nov 2022 08:37:26 -0800 (PST) X-Google-Smtp-Source: AA0mqf5Er3YaX1905PyUql70eOYSfneYkCY+nynbv7Hd3Q7bzc/exGoVFm7oyhG9COyCcyY7GI35 X-Received: by 2002:a17:907:c081:b0:78b:5182:7ffa with SMTP id st1-20020a170907c08100b0078b51827ffamr42067702ejc.244.1669826246352; Wed, 30 Nov 2022 08:37:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669826246; cv=none; d=google.com; s=arc-20160816; b=l6Bg5spuIy/ogAsI6OqKuybXFSnRM59qGvBE9HjgqGMRLRTAh2/C4hO1CElsBgO3cZ C8fu3cl+eal8C3S0lWcVfXZH84RbNLReom/e7nEyQIt8KPSkL1Chz0v+XlBUIKJ7OUwe ZK1cAZ4dNoTh2v6Zz3fBrAOp0OR5u1hWl5SFnWJR3mkwWayhla3REEWqRRbTlP+y4xgD 0WVpC2VDhAuLpzhiKcw/Vf4GHmOSTzgVHNCXU7hdZHmetA0w52nAmkeNuWylzGq3XdHx esxG2h6yfeYjjTM3CAzvWVZk7hDZwSBuAi/PiTccUWdYrCaKlm8GZwj8NTHBLI2hyB3m xvnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=lHWzy0FM79r3PLFfRwF2L7xXZGTYCWGH6Me/ph3/zE0=; b=BxqJUOUkGP9K71brXYW3OlwVsidjrP5LNIabFuWRyNcvleEv7CdnkVhauErhD8Q7Xv 7Me/aetoIg1JYqjNGOUzfT/O8gvxGaiv+/NiMmnF5p9pE8LJpAQRKEPDPM5GxoK24Ghf r+OCsyMZaqxhY3wnF61a4iR0vt/c1CvItfKzittk4OAJMBAeKIzBgJrewHhcBF7F4F+R lsxijNBQhJrLbKJBheRHNfExJ4ZCUnfD3mXaro4FpT8RkvMjpjl17rpMyMfT4HNVyNyP bcru7fjntvyYXU/VBje5XkoKsrOGDUMOG2emkz8+hRTu9xSi0/JOizH4SxL8+e0csbB7 Mdmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=f3+8D26U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b2-20020aa7d482000000b0046b0dcc24dasi1547886edr.403.2022.11.30.08.37.05; Wed, 30 Nov 2022 08:37:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=f3+8D26U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229997AbiK3Ppk (ORCPT + 83 others); Wed, 30 Nov 2022 10:45:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229821AbiK3Ppj (ORCPT ); Wed, 30 Nov 2022 10:45:39 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A825E813A7 for ; Wed, 30 Nov 2022 07:44:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669823084; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lHWzy0FM79r3PLFfRwF2L7xXZGTYCWGH6Me/ph3/zE0=; b=f3+8D26UfBV/qh3C1IDF4Xsb/KrmQ1goY32XuHC3xAzc9XnlCJN+vFooThJy+YEv+0L/FR DrImlRLRMmk86tuSf57Ypec2K13R296YIAxYqMGWYdB5Fljg5DC/IleQvkJjSkJxnIS8da 3Falher+ZJja3uiZJDnil0gFPJ0Axuc= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-503-ykxiv1TXOwGZ2tocqAhH0A-1; Wed, 30 Nov 2022 10:44:41 -0500 X-MC-Unique: ykxiv1TXOwGZ2tocqAhH0A-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9A4F13C0F437; Wed, 30 Nov 2022 15:44:39 +0000 (UTC) Received: from [10.22.17.5] (unknown [10.22.17.5]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5DE741415119; Wed, 30 Nov 2022 15:44:38 +0000 (UTC) Message-ID: Date: Wed, 30 Nov 2022 10:44:36 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.0 Subject: Re: [PATCH-block v2] bdi, blk-cgroup: Fix potential UAF of blkcg Content-Language: en-US To: =?UTF-8?Q?Michal_Koutn=c3=bd?= Cc: Jens Axboe , Tejun Heo , cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Ming Lei , Andy Shevchenko , Andrew Morton , Hillf Danton , Chaitanya Kulkarni , Bart Van Assche , Josef Bacik , Yi Zhang References: <20221129203400.1456100-1-longman@redhat.com> <20221130151639.GE27838@blackbody.suse.cz> From: Waiman Long In-Reply-To: <20221130151639.GE27838@blackbody.suse.cz> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham 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 On 11/30/22 10:16, Michal Koutný wrote: > On Tue, Nov 29, 2022 at 03:34:00PM -0500, Waiman Long wrote: >> The reproducing system can no longer produce a warning with this patch. >> All the runnable block/0* tests including block/027 were run successfully >> without failure. > Thanks for the test! > >> @@ -1088,7 +1088,15 @@ static void blkcg_destroy_blkgs(struct blkcg *blkcg) >> >> might_sleep(); >> >> - css_get(&blkcg->css); >> + /* >> + * blkcg_destroy_blkgs() shouldn't be called with all the blkcg >> + * references gone and rcu_read_lock not held. >> + */ >> + if (!css_tryget(&blkcg->css)) { >> + WARN_ON_ONCE(!rcu_read_lock_held()); >> + return; >> + } > As I followed the previous discussion, the principle is that obtaining a > reference or being inside an RCU read section is sufficient. > > Consequently, I'd expect the two situations handled equally but here the > no-ref but RCU bails out. (Which is OK because blkg_list must be empty?) > > However, the might_sleep() in (non-sleepable) RCU reader section combo > makes me wary anyway (not with the early return but tools would likely > complain). > > All in all, can't the contract of blkcg_destroy_blkgs() declare that > a caller must pass blkcg with a valid reference? (The body of > blkcg_destroy_blkgs then wouldn't need to get neither put the inner > reference). You are right. I should have pushed the might_sleep down(). Will post a new version to fix that. Thanks, Longman