Received: by 2002:a05:7412:b112:b0:f9:3106:f1c0 with SMTP id az18csp19045rdb; Sun, 17 Dec 2023 18:48:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IFSVHqFhvftcRRGukDF8LryupFH22x4hdQDVff3bFCCjAoR2nOVZUePExuqCRCH8oQOCFE2 X-Received: by 2002:a05:6808:640f:b0:3b9:f10f:b69f with SMTP id fg15-20020a056808640f00b003b9f10fb69fmr18309008oib.11.1702867726511; Sun, 17 Dec 2023 18:48:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702867726; cv=none; d=google.com; s=arc-20160816; b=NphVFbwKE9B5zGMHtOyHC/Rnvydulnqa/7gHoZi5knzh0QH4OpyokaWo41folFvUfL f6wp5bCsip4MFa+vzuBc4kSVSonyHpTm+lay8ZuFRNfg7jullBCEVds1z/ExVLB1ajAK zOwI/3WNgASg626nMrmHwSnPrrig2mmehxfpR1+fRT6S0XLau23D9RTlN3b/BDYIwhMu vWKGfokxAKc8W8Qvid6+FrVLmmWze4jjz+c51FZgNxUWEX6yprBnDJhz1LwIgW9RunzC 8EX5w0IZvbBu2yffr5m459yu6I9Y5w28pQxBo/DI1Imi/gtDFSFtCszlxTGH4sO3mGYo T5Ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=+e1YcBTgmwUnYCbcSPzTJsF2eJBj/0YAkhPcD4K09r0=; fh=2zmp9Z3M8+JCsYhbZs/eLWB0R5VnMLqaL2V0xifnO88=; b=nQGWpK2m7j/cHl8ME84whPKIvCqZ8zFAhLHeB1SZt4C7VDa4B0l9D6HJ2hccNgXk9v XTiRq8hR1vSGcl/jVk01AN6WvH6HFcme1UXxf51AcAueFBag9CjAW0m26Xcq4CBCZU1j 321UNrAyCWlWkgsKXj091P0mAs/RcSXIdbTL1KAs/4T9rjRCJyUUV3KTGOXbuZdH+4J4 AF6jan0LCWGMjVTioOvlsd+i3Gz57kdBdzcaG5ZYjDkpIIEkF6r3hAOr6AppJc/2fnuk qVzycLEdDj2TesTO+Ep63H9TRQToSe7AE+s05XFhtAMWOK3r3fjkzZSoYzj3ZW+OHYj7 btdw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-2941-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-2941-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id fb30-20020a056a002d9e00b006d808ac1cc9si496957pfb.127.2023.12.17.18.48.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Dec 2023 18:48:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-2941-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-2941-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-2941-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 55DEBB21F05 for ; Mon, 18 Dec 2023 02:48:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4C0436D19; Mon, 18 Dec 2023 02:45:24 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from SHSQR01.spreadtrum.com (mx1.unisoc.com [222.66.158.135]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1D89263BA for ; Mon, 18 Dec 2023 02:45:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unisoc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=unisoc.com Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 3BI2iYgH059906; Mon, 18 Dec 2023 10:44:34 +0800 (+08) (envelope-from Chunyan.Zhang@unisoc.com) Received: from SHDLP.spreadtrum.com (bjmbx02.spreadtrum.com [10.0.64.8]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4StkXG6kQ4z2PhV8G; Mon, 18 Dec 2023 10:38:22 +0800 (CST) Received: from ubt.spreadtrum.com (10.0.73.88) by BJMBX02.spreadtrum.com (10.0.64.8) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Mon, 18 Dec 2023 10:44:32 +0800 From: Chunyan Zhang To: Greg Kroah-Hartman , "Rafael J . Wysocki" CC: LKML , Jing Xia , Jing Xia , Xuewen Yan , Ke Wang , Chunyan Zhang Subject: [PATCH] class: fix use-after-free in class_register() Date: Mon, 18 Dec 2023 10:44:03 +0800 Message-ID: <20231218024403.1076134-1-chunyan.zhang@unisoc.com> X-Mailer: git-send-email 2.41.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX02.spreadtrum.com (10.0.64.8) X-MAIL:SHSQR01.spreadtrum.com 3BI2iYgH059906 From: Jing Xia The lock_class_key is still registered and can be found in lock_keys_hash hlist after subsys_private is freed in error handler path.A task who iterate over the lock_keys_hash later may cause use-after-free.So fix that up and unregister the lock_class_key before kfree(cp). Signed-off-by: Jing Xia Signed-off-by: Xuewen Yan --- drivers/base/class.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/base/class.c b/drivers/base/class.c index 7e78aee0fd6c..7b38fdf8e1d7 100644 --- a/drivers/base/class.c +++ b/drivers/base/class.c @@ -213,6 +213,7 @@ int class_register(const struct class *cls) return 0; err_out: + lockdep_unregister_key(key); kfree(cp); return error; } -- 2.25.1