From patchwork Tue Dec 13 18:44:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Waiman Long X-Patchwork-Id: 13072331 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA114C4167B for ; Tue, 13 Dec 2022 18:45:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236595AbiLMSpp (ORCPT ); Tue, 13 Dec 2022 13:45:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235461AbiLMSpn (ORCPT ); Tue, 13 Dec 2022 13:45:43 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6539024BE3 for ; Tue, 13 Dec 2022 10:45:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670957101; 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; bh=gC79KdPgX8meWkHV6kEH9PpY7k/sykKi+3gQfcC9IOQ=; b=EO1YF/o7PQ+hB9WKFyom9FG2siln3GP/cxPd+WgwJt9JtWH6bQNmVu1AqhwY2qiUr6FzbI Y9wpgwi1psOxjrCPJ3fakQtD+tGN6j3mkluuvrn6y8Ag7/wun8OKPHGinR/Ow/3gnvCHDd APZPjIAFYZbkvpHdnccFDNZAfy2BHVw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-20-BvYR3lxsNKWZAZOxPDL65Q-1; Tue, 13 Dec 2022 13:44:58 -0500 X-MC-Unique: BvYR3lxsNKWZAZOxPDL65Q-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E6381185A78F; Tue, 13 Dec 2022 18:44:57 +0000 (UTC) Received: from llong.com (unknown [10.22.32.205]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2E9CCC15BA0; Tue, 13 Dec 2022 18:44:57 +0000 (UTC) From: Waiman Long To: Jens Axboe , Tejun Heo , Josef Bacik , Zefan Li , Johannes Weiner , Andrew Morton Cc: cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, =?utf-8?q?Michal_Koutn?= =?utf-8?q?=C3=BD?= , "Dennis Zhou (Facebook)" , Waiman Long Subject: [PATCH-block v3 0/2] blk-cgroup: Fix potential UAF & flush rstat at blkgs destruction path Date: Tue, 13 Dec 2022 13:44:44 -0500 Message-Id: <20221213184446.50181-1-longman@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org v3: - Drop v2 patch 2 as it may not be needed. - Replace css_tryget() with percpu_ref_is_zero() in patch 1 as suggested by Tejun. - Expand comment on patch 2 to elaborate the reason for this patch. v2: - Remove unnecessary rcu_read_{lock|unlock} from cgroup_rstat_css_cpu_flush() in patch 3. It was found that blkcg_destroy_blkgs() may be called with all blkcg references gone. This may potentially cause user-after-free and so should be fixed. The second patch flushes rstat when blkcg_destroy_blkgs(). Waiman Long (2): bdi, blk-cgroup: Fix potential UAF of blkcg blk-cgroup: Flush stats at blkgs destruction path block/blk-cgroup.c | 22 ++++++++++++++++++++++ include/linux/cgroup.h | 1 + kernel/cgroup/rstat.c | 18 ++++++++++++++++++ mm/backing-dev.c | 8 ++++++-- 4 files changed, 47 insertions(+), 2 deletions(-)