Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2284614rwb; Wed, 30 Nov 2022 04:59:15 -0800 (PST) X-Google-Smtp-Source: AA0mqf7wYuFJI8748KFoPzkM0WmggsGjIOucunisKoIbqT37wXO1sKoWEiK6aO/zayf/aNOnZbv+ X-Received: by 2002:a17:902:d0d3:b0:189:86b8:bafc with SMTP id n19-20020a170902d0d300b0018986b8bafcmr16468023pln.40.1669813155236; Wed, 30 Nov 2022 04:59:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669813155; cv=none; d=google.com; s=arc-20160816; b=vJ6ozpTXHoGWrCP68ogEi+eGEua8VitR/IydNiu3JqW+jFIm/pekvsLPA3gxLhlzTW k+AKpyNFO3YsJ4/TMHzvoGQZSYGcpGiaMI7iZ4C8MqwPyPtDEI6V7Gz63uIcfO/uWpdo O8y5v6w+M6Dr8mQXix0LpYN2CfIV73C/cA5adLsgSWg1imoEqRv6xkG0gjuKFMciU8dC pG//Kjc3TBW3xir+MhwFgmcJ5LU27raWREbfY9qR/9ekTrCmCM5TLYMJIEn8VF0705I/ paKqqTQKtioYkcOlRZkzyu8dYNwYjlUbn6aVFTD5J26unVfAm97snYlV4Mwu0tkFvPLX SI0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=HXeJjLJuJELmr0eXasapdP/pvgZ1guZUOf3fefX73MI=; b=JYGD2OepMF3neo7b29EhBAigeURLPr47krbKW2W83kIK3jRkd4/Ui7lR1E3QZvyFOC S1rD1gQWWUCpmr1+/7RhWLeBGKyD6tCzrJe31g0597RtDxnKY85pAZVXnRiw/D2fR6n9 +eYrbq9LzPJyQ+z1MqvoUCxLIp3jHp4vH+prR5Rg4OE/e5ZwFu8Y3HdMvJ4FfsLl4Iz/ lVfiSVIrXbSjBbtOuRne2+L1wdgvCoD8wZ4n12ZXB4wy5eeEyog6gyPpKbJQc/4ZZKZ4 GMvj8znYW4kqFGTzOhyncgsh2z0BNWWtvsuJ3fxxmqz1TDC4Vq7iLcDcvee1lcxXRoKH 8KDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VmD+Tld7; 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=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m3-20020a170902f20300b00188763b35e1si1088504plc.424.2022.11.30.04.59.04; Wed, 30 Nov 2022 04:59:15 -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=@intel.com header.s=Intel header.b=VmD+Tld7; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234564AbiK3Mj5 (ORCPT + 84 others); Wed, 30 Nov 2022 07:39:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229515AbiK3Mjy (ORCPT ); Wed, 30 Nov 2022 07:39:54 -0500 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E70432792B; Wed, 30 Nov 2022 04:39:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1669811993; x=1701347993; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=iPuUqicRuUklAlC5NV44CDz/ub4ZDmFDWBmSCxl3Jkw=; b=VmD+Tld7VK+TKKsOLApG+zWmnWS7mdPl+tG1U9gyyz5MrCD5MqP0+i/W Mz5Qj5MvCTxwwUNyeK30kW31itd+mXLM6k+oAeK3vkFFxpDE+HMewrjQF VXh9LlvGqtNmddQfYCuMQAWCxFRXTq+7EgvCqhniM6Z5PNfNJeNmhqJ8g aDcy538050krtABGERsZGLNCIBxrLSL6ihxp5GzYeAMXIKKKNwJjUS1gf cw1jmsBa3hJJmZkzcQ5oFs7ysCv7XnyEPyyI4sSIXyYLW2tzKk1jcPfWq QvzhtCpAu6Ylp2JZ8u3McEZ7VoKxQuux8SjEcSmE1xEgLllhMaQt8k3kI w==; X-IronPort-AV: E=McAfee;i="6500,9779,10546"; a="379663970" X-IronPort-AV: E=Sophos;i="5.96,206,1665471600"; d="scan'208";a="379663970" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2022 04:39:53 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10546"; a="637977002" X-IronPort-AV: E=Sophos;i="5.96,206,1665471600"; d="scan'208";a="637977002" Received: from smile.fi.intel.com ([10.237.72.54]) by orsmga007.jf.intel.com with ESMTP; 30 Nov 2022 04:39:49 -0800 Received: from andy by smile.fi.intel.com with local (Exim 4.96) (envelope-from ) id 1p0MNO-002GIz-1o; Wed, 30 Nov 2022 14:39:46 +0200 Date: Wed, 30 Nov 2022 14:39:46 +0200 From: Andy Shevchenko To: Waiman Long 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 , Andrew Morton , Michal =?iso-8859-1?Q?Koutn=FD?= , Hillf Danton , Chaitanya Kulkarni , Bart Van Assche , Josef Bacik , Yi Zhang Subject: Re: [PATCH-block v2] bdi, blk-cgroup: Fix potential UAF of blkcg Message-ID: References: <20221129203400.1456100-1-longman@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221129203400.1456100-1-longman@redhat.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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 Tue, Nov 29, 2022 at 03:34:00PM -0500, Waiman Long wrote: > Commit 59b57717fff8 ("blkcg: delay blkg destruction until after > writeback has finished") delayed call to blkcg_destroy_blkgs() to > cgwb_release_workfn(). However, it is done after a css_put() of blkcg > which may be the final put that causes the blkcg to be freed as RCU > read lock isn't held. > > By adding a css_tryget() into blkcg_destroy_blkgs() and warning its > failure, the following stack trace was produced in a test system on > bootup. > > [ 34.254240] RIP: 0010:blkcg_destroy_blkgs+0x16a/0x1a0 > : > [ 34.339943] Call Trace: > [ 34.342395] > [ 34.344510] blkcg_unpin_online+0x38/0x60 > [ 34.348523] cgwb_release_workfn+0x6a/0x200 > [ 34.352708] process_one_work+0x1e5/0x3b0 > [ 34.356742] ? rescuer_thread+0x390/0x390 > [ 34.360758] worker_thread+0x50/0x3a0 > [ 34.364425] ? rescuer_thread+0x390/0x390 > [ 34.368447] kthread+0xd9/0x100 > [ 34.371592] ? kthread_complete_and_exit+0x20/0x20 > [ 34.376386] ret_from_fork+0x22/0x30 > [ 34.379982] https://www.kernel.org/doc/html/latest/process/submitting-patches.html#backtraces-in-commit-messages > This confirms that a potential UAF situation can happen. > > Fix that by delaying the css_put() until after the blkcg_unpin_online() > call. Also use css_tryget() in blkcg_destroy_blkgs() and issue a warning > if css_tryget() fails with no RCU read lock held. > > 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. -- With Best Regards, Andy Shevchenko