From patchwork Sat Sep 14 10:24:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yibin Ding X-Patchwork-Id: 829182 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 AED2B45025; Sat, 14 Sep 2024 10:25:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=222.66.158.135 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726309506; cv=none; b=AbhrILlMevuLZXKw6q0poWBzBWY2mxA8TCkVuR9F8qM1cefAFXNlNDRpjY4oEp83NYRGcqHOrtULIp+zR8oZAThcYI5ux/eDeYjA0tfPdIQcipNFJPeFHQK23F8d1SFB3cBL2vVdVeLTEOZ8H4ZZgEtWeZ04XU4zenzG+U7HBcs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726309506; c=relaxed/simple; bh=AtuMd6NKlG+Syp19uppr02ateM9HluJ3Gl9IuBKSOu8=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=GcJMGLOTZ17L4a62rXaDEJXw/4NhxcGmFCLpKkonqb+TewuGR9mHUHYwljAA1u75P5nIBqD86v62KrAufsziFeC5WYYFl+SyB50GWL3q4f3B3f86YRqZMOevO5jE6AZFz/J7vCInmoiWXSb5E39x/6VM+vnI1Xb4b4rllpBQMI0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unisoc.com; spf=pass smtp.mailfrom=unisoc.com; arc=none smtp.client-ip=222.66.158.135 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 48EAOesR042876; Sat, 14 Sep 2024 18:24:40 +0800 (+08) (envelope-from Yibin.Ding@unisoc.com) Received: from SHDLP.spreadtrum.com (bjmbx02.spreadtrum.com [10.0.64.8]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4X5Rtk1Hc1z2Pvl0t; Sat, 14 Sep 2024 18:17:18 +0800 (CST) Received: from tj10379pcu.spreadtrum.com (10.5.32.15) by BJMBX02.spreadtrum.com (10.0.64.8) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Sat, 14 Sep 2024 18:24:38 +0800 From: Yibin Ding To: , , CC: , , , , , Subject: [PATCH V2 1/2] interconnect: Add character pointer initialization Date: Sat, 14 Sep 2024 18:24:35 +0800 Message-ID: <20240914102435.3879355-1-Yibin.Ding@unisoc.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX02.spreadtrum.com (10.0.64.8) X-MAIL: SHSQR01.spreadtrum.com 48EAOesR042876 From: Yibin Ding When accessing a node whose data type is a character pointer and has not been initialized, a crash will occur due to accessing a null pointer. So it is necessary to add the operation of initializing the character pointer. Since the debugfs_write_file_str() function performs a kfree() operation on the node data, memory is allocated to the node pointer during initialization will be released when data is written to the node. Signed-off-by: Yibin Ding --- drivers/interconnect/debugfs-client.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/interconnect/debugfs-client.c b/drivers/interconnect/debugfs-client.c index bc3fd8a7b9eb..a1c99b9d3b9a 100644 --- a/drivers/interconnect/debugfs-client.c +++ b/drivers/interconnect/debugfs-client.c @@ -147,8 +147,13 @@ int icc_debugfs_client_init(struct dentry *icc_dir) client_dir = debugfs_create_dir("test_client", icc_dir); - debugfs_create_str("src_node", 0600, client_dir, &src_node); - debugfs_create_str("dst_node", 0600, client_dir, &dst_node); + src_node = kzalloc(sizeof(src_node), GFP_KERNEL); + dst_node = kzalloc(sizeof(dst_node), GFP_KERNEL); + + if (src_node) + debugfs_create_str("src_node", 0600, client_dir, &src_node); + if (dst_node) + debugfs_create_str("dst_node", 0600, client_dir, &dst_node); debugfs_create_file("get", 0200, client_dir, NULL, &icc_get_fops); debugfs_create_u32("avg_bw", 0600, client_dir, &avg_bw); debugfs_create_u32("peak_bw", 0600, client_dir, &peak_bw); From patchwork Sat Sep 14 10:24:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yibin Ding X-Patchwork-Id: 828781 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 411511CEAA9; Sat, 14 Sep 2024 10:25:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=222.66.158.135 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726309523; cv=none; b=uwWYjIgfdxBYsLTPv/Gq0PvIfS87dKGyL9q7Pz/R6SvulwXrMiOE3cshi4F3OTs0pd0nONjHmuB9xYhgbpNe9edWEgE3wSZP3DS2yLyPAKhiPBI5srdLbqac/G8Hwn/76iP2kKq+rEDJyxE5OXmlAXW7/cz9I+E42WiY2QB7iWA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726309523; c=relaxed/simple; bh=gPn3ocUVhQgAWNFUlaGK72RHnsXD6uEOO6+5lQ9CLRs=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=nqi/w6Ex/xZzE6dg9jbMDp3hJE5yBUGf7rqXyUj6xWb7VnRqP5cNgqjrXaQWVDMBcM+A+yHudqzgAuGvy77dz7hlfbmRc4jzAlwhOtMtC7VRVqu6ac20s3K0qlh1eRnFpPm4vUx0qYJxJF+IxykAKTz6pZ2MIB6+eoTnGUFyeVc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unisoc.com; spf=pass smtp.mailfrom=unisoc.com; arc=none smtp.client-ip=222.66.158.135 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 48EAOwcT043365; Sat, 14 Sep 2024 18:24:58 +0800 (+08) (envelope-from Yibin.Ding@unisoc.com) Received: from SHDLP.spreadtrum.com (bjmbx02.spreadtrum.com [10.0.64.8]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4X5Rv36B3rz2PTj3C; Sat, 14 Sep 2024 18:17:35 +0800 (CST) Received: from tj10379pcu.spreadtrum.com (10.5.32.15) by BJMBX02.spreadtrum.com (10.0.64.8) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Sat, 14 Sep 2024 18:24:56 +0800 From: Yibin Ding To: , , CC: , , , , , Subject: [PATCH V2 2/2] debugfs: Fix crash problem caused by accessing uninitialized nodes Date: Sat, 14 Sep 2024 18:24:53 +0800 Message-ID: <20240914102453.3879527-1-Yibin.Ding@unisoc.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX02.spreadtrum.com (10.0.64.8) X-MAIL: SHSQR01.spreadtrum.com 48EAOwcT043365 From: Yibin Ding For uninitialized nodes such as /sys/kernel/debug/interconnect/test_client/dst_node, if the cat operation is performed directly without writing content to the node, it will cause a crash due to accessing a null pointer. So it is necessary to add a null pointer check in the debugfs_read_file_str() function. Signed-off-by: Yibin Ding --- fs/debugfs/file.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c index c6f4a9a98b85..8bbe7df6dfd1 100644 --- a/fs/debugfs/file.c +++ b/fs/debugfs/file.c @@ -970,6 +970,10 @@ ssize_t debugfs_read_file_str(struct file *file, char __user *user_buf, return ret; str = *(char **)file->private_data; + if (!str) { + debugfs_file_put(dentry); + return -EINVAL; + } len = strlen(str) + 1; copy = kmalloc(len, GFP_KERNEL); if (!copy) {