From patchwork Thu Dec 15 03:31:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Waiman Long X-Patchwork-Id: 13073878 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 55171C4332F for ; Thu, 15 Dec 2022 03:32:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DED528E0006; Wed, 14 Dec 2022 22:32:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DC4988E0002; Wed, 14 Dec 2022 22:32:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C8C1F8E0006; Wed, 14 Dec 2022 22:32:01 -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 BB97E8E0002 for ; Wed, 14 Dec 2022 22:32:01 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 8AA2F160316 for ; Thu, 15 Dec 2022 03:32:01 +0000 (UTC) X-FDA: 80243116842.20.0A0A0B9 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf06.hostedemail.com (Postfix) with ESMTP id 1661C180009 for ; Thu, 15 Dec 2022 03:31:59 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=cyar9C8s; spf=pass (imf06.hostedemail.com: domain of longman@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=longman@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1671075120; 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: references:dkim-signature; bh=veCyvm43EvJLg9G9hhu4AmM7THRxqVqHEQtr8ufuCSo=; b=31RQUUohhLAJ6JiZCRqbuMCaf35ks1GkOdy8hdKCL3q+t1Jj+wosKXWo1bubesdSA5yapL 3bh+/X/vBAa9ffXNPIbTDd0XWvKl5BZ5X3s3L23PU/mc0b3E7cF5cwE83MlBVYOKNs+r98 bjUXzPjnA0WFRhavaxmi4G8jfjoBqDI= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=cyar9C8s; spf=pass (imf06.hostedemail.com: domain of longman@redhat.com designates 170.10.133.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=1671075120; a=rsa-sha256; cv=none; b=dp8QxFp1sG/XLRuClI9MoTk7U60RJWoHK+9RXG+DpskqewonTQKa6aCOjmJRpuHeF6SHuM HvTVMZwCrXuQfYhBzQ8f9XYcdj2CAiTIEKg739dBH8RBnI9YUQFMTnf/yFu1Kdo0ji/Q4E /69rKJA2f3yD1d2uc/WrXkVXFaLHm4E= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671075119; 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=veCyvm43EvJLg9G9hhu4AmM7THRxqVqHEQtr8ufuCSo=; b=cyar9C8sKUCLsk/74yQrXxd82gHQkXIylhVRYwAtdDhkMVUZJYcocmxXzN2So+27Qsz807 GmwZ6bXeRJNjicu3MCOxGC783MNLrsFOTVYArZNukIbyClmnOLjFoxXIneO+hj/lk7SqOX 1hRXjo3Fa7wCZ6FTtXWb/mcsYRzT5f8= 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-496-tg69kkZDM-O1mkTEYK98qg-1; Wed, 14 Dec 2022 22:31:45 -0500 X-MC-Unique: tg69kkZDM-O1mkTEYK98qg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 99C9F185A78B; Thu, 15 Dec 2022 03:31:44 +0000 (UTC) Received: from llong.com (unknown [10.22.16.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id AA9B240ED76E; Thu, 15 Dec 2022 03:31:43 +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 v4 0/2] blk-cgroup: Fix potential UAF & flush rstat at blkgs destruction path Date: Wed, 14 Dec 2022 22:31:30 -0500 Message-Id: <20221215033132.230023-1-longman@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 1661C180009 X-Stat-Signature: 1i6o6tyadd79z5u16zzox93mfof4uf93 X-Rspam-User: X-HE-Tag: 1671075119-984999 X-HE-Meta: U2FsdGVkX1+rlYOt9wk6AGBE/OQ05I54z9ZeTeRs5NO8+wU44yBUdxi9xNlUNnrkmBAqYhCbClmhoN41cLtKEz5iUTrwg2hmSBO54EzrCn+/ty/Ht8QL5rR4U58ygI2avMD5RD4EaWCsCIHz5qv6uvoZseZQqh4KkWNmcThEXVQSeo+sgEFOBeTT6CpNOj5WRZVMU/OMMcpVsMFe3KolQ33VzlNIbgXKHG0JFFHry2vL2K0Tr52Zod6HOuFGFtBO9f+lo+A4RdviAV6D9moJgEAE7d/P0XdYVq51tyMiSwpHizxPMA7gj9R5cPxFD0q7MHJeSM6nbS0sxBJ2hnPA0IW/hT8Y+FAFMn0ruvJaBsu8a0wN7Mcrq51E5Znln3i7VblE+wIzLET6e8gPuTtPq9rGMuDVvR5m8wPAq2AOM13aZRK+KQC+AbpHCma2MPbvi2gLyco1+7ZSSfTnvvbqg2bR55NR83VKUGeOq8+HXDnaKUebs+LOoVAEDEMk+3Qfzoph50NIsymz/0HjY8b4w5C1HmwF3piFUV0Ye0sbetkSD/Yq4ZJV0Xu/fj7X2+0eJM5Z/VAU7K3qpc2CIZxI+cfFSIYMEHHFt17z4SUh6+dQWxt8kMcJsPBRiYYw2C5uL4Gfy9vSbpjFHRB3fkfkSsFJTzE7HhXgrmro85kYt+Xr0jvn0UATnGsot/9WGBcSGFoybYeFB7BCHeEROLWtDEeKLTRmdFJRkpX4mn3dKQPdGVdgRRkJcCNfTaMKdVNjuUbfaKBd+IbbKmnejuQXjBuhKwHDlEOnh+teYslpGTFpKf0fncDwDxnl6VeU6ZSntK5VQ/hU2uoYgYXIuGiIPmXOi5rna9x4wujQnX8+PdCpIxK70n66svyxX8z8Zhpe 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: v4: - Update comment and commit logs for both patches. 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 calling 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 | 23 +++++++++++++++++++++++ include/linux/cgroup.h | 1 + kernel/cgroup/rstat.c | 18 ++++++++++++++++++ mm/backing-dev.c | 8 ++++++-- 4 files changed, 48 insertions(+), 2 deletions(-)