From nobody Wed Apr 24 14:16:04 2024 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 D7506C6FA82 for ; Fri, 23 Sep 2022 11:51:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231948AbiIWLvh (ORCPT ); Fri, 23 Sep 2022 07:51:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231346AbiIWLve (ORCPT ); Fri, 23 Sep 2022 07:51:34 -0400 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 23185138F0D for ; Fri, 23 Sep 2022 04:51:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663933893; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=LSqlKmINboHpHtUNR10HWYgYVkgSi8ssnna63UQWneM=; b=E5bDjaf39WQFRrYS9zn6lssmvG4k5AtQ/0gjHG+dmazl5tNakQ/mpy1mM4VyKC774OyAhU NF2ahbmsfkqAA3MBuqRvkCBtYXGmFy5KfUIdqECfhfrGWLB3jp/JZNF3t0tZ41bUqu5l/B FGmHmcA2RfM27yCGv+8KaqarvWQZkPs= 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-41-NhEncvQePGKBOhXkHh4LGQ-1; Fri, 23 Sep 2022 07:51:27 -0400 X-MC-Unique: NhEncvQePGKBOhXkHh4LGQ-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 AE124101245C; Fri, 23 Sep 2022 11:51:26 +0000 (UTC) Received: from localhost (ovpn-8-24.pek2.redhat.com [10.72.8.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id B130B40C6EC2; Fri, 23 Sep 2022 11:51:25 +0000 (UTC) From: Ming Lei To: Tejun Heo , linux-kernel@vger.kernel.org Cc: cgroups@vger.kernel.org, Ming Lei , Marco Patalano , Muneendra Subject: [PATCH] cgroup: fix cgroup_get_from_id Date: Fri, 23 Sep 2022 19:51:19 +0800 Message-Id: <20220923115119.2035603-1-ming.lei@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" cgroup has to be one kernfs dir, otherwise kernel panic is caused, especially cgroup id is provide from userspace. Reported-by: Marco Patalano Fixes: 6b658c4863c1 ("scsi: cgroup: Add cgroup_get_from_id()") Cc: Muneendra Signed-off-by: Ming Lei Acked-by: Mukesh Ojha --- kernel/cgroup/cgroup.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index e4bb5d57f4d1..5f2090d051ac 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -6049,6 +6049,9 @@ struct cgroup *cgroup_get_from_id(u64 id) if (!kn) goto out; =20 + if (kernfs_type(kn) !=3D KERNFS_DIR) + goto put; + rcu_read_lock(); =20 cgrp =3D rcu_dereference(*(void __rcu __force **)&kn->priv); @@ -6056,7 +6059,7 @@ struct cgroup *cgroup_get_from_id(u64 id) cgrp =3D NULL; =20 rcu_read_unlock(); - +put: kernfs_put(kn); out: return cgrp; --=20 2.31.1