From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 31A55C352A1 for ; Wed, 30 Nov 2022 15:44:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8896C6B0074; Wed, 30 Nov 2022 10:44:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8123B6B0075; Wed, 30 Nov 2022 10:44:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6B3156B0078; Wed, 30 Nov 2022 10:44:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 584AA6B0074 for ; Wed, 30 Nov 2022 10:44:45 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 1A74BA03F2 for ; Wed, 30 Nov 2022 15:44:45 +0000 (UTC) X-FDA: 80190531330.03.6E6F64E Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf20.hostedemail.com (Postfix) with ESMTP id 686BE1C000E for ; Wed, 30 Nov 2022 15:44:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669823083; 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=B659+WyQTZQWUYvew+qtY9Bc6M/g0fWy7UXPeUD3VHSmxh+JnRe7aJEM0WcTRTkSOvPSRr 2u9j11+X1BEcc8gZqkkOZvp1ZlEh4VaPDYuIDcd+zU/RNE4BmFm+1b4JFE0QcpDTT/AjMG NgmRlsDXdMHxGxaN1x4d8lE1xrZ+f6s= 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 ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=B659+WyQ; spf=pass (imf20.hostedemail.com: domain of longman@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=longman@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669823084; a=rsa-sha256; cv=none; b=rD2LTeAuO5SAskh1CueTbvWa9wI4sDkrVfsXQNFuRYWw/JEYzwV0XsQUQkUC8L6U8mALWH kzZE4XdZoXnqJit6N0zA/H607issbp2LZpwD6wlIOYwietO6Hf8eQE5e+kIWl/cEfTJiSE R3QISBXlnY5hUJLWs6cB758h72e+5jM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669823084; h=from:from:sender: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:dkim-signature; bh=lHWzy0FM79r3PLFfRwF2L7xXZGTYCWGH6Me/ph3/zE0=; b=BTI1ZJt8rR/a1KGlbB97i8A+7OWZ+nKz5/OgM10pi4MEEbjLqagFz/z/kI+E2mwLsyPKQ0 Ll6lQpPkf3b7MLZLHZ+qb12tv/DKhBmWgK16QpT6ilpTLa582MLMV+tOQ50cZPAER/Y+B0 a6DOlhN0xWNcVuDCWKrB2KP5EyhYY2U= Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=B659+WyQ; spf=pass (imf20.hostedemail.com: domain of longman@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=longman@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 686BE1C000E X-Stat-Signature: phs3wq3adkbuzf3utrcrc54p6fqaheox X-Rspam-User: X-HE-Tag: 1669823084-778597 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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