From patchwork Fri Aug 30 10:22:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yibin Ding X-Patchwork-Id: 824663 Received: from SHSQR01.spreadtrum.com (unknown [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 6BD1218F2C3; Fri, 30 Aug 2024 10:24:34 +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=1725013477; cv=none; b=salSplvbBEvEynAEpeJcr0lV8Z9s5BvtYvggW5dF99PXeu0j0LGCeXfYvZgrEX204zkdoSOCvMOB1XizUWx2q+TCJuW7c92UbYg3HtFqSiIqTisXRPy6r0KhDhZN55INOdBzeTyIirmn2OfYu1V30Zm+M4BNMWfDN5ys/AL1aCg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725013477; c=relaxed/simple; bh=Y5AZNuvvj1CyJkOhIAY6s+QK+ZUYCcxTrKP89Vs3CGk=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=cSfd6rPSTWBS2Y3w2qpUgkZOLs+Q+HJZzsxKlMCa4H7BSp2WulmbJ5sArYKt5vD6XF9iQVVeZqdizPSCW+eOCxZ38Ji2zyHinFihqv3U4nJtJG3Li1oNxRXERqOldrszGDeCCOuJnTva1ahWdewXKy0SCqr7anSkz2CuVh/h7gE= 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 47UAMm7u031638; Fri, 30 Aug 2024 18:22:48 +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 4WwDZ36m2wz2N5cJc; Fri, 30 Aug 2024 18:15:55 +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; Fri, 30 Aug 2024 18:22:46 +0800 From: Yibin Ding To: , , CC: , , , , , Subject: [PATCH 1/2] interconnect: Add character pointer initialization Date: Fri, 30 Aug 2024 18:22:44 +0800 Message-ID: <20240830102244.409058-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 47UAMm7u031638 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 | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/interconnect/debugfs-client.c b/drivers/interconnect/debugfs-client.c index bc3fd8a7b9eb..d62ba56b7bbe 100644 --- a/drivers/interconnect/debugfs-client.c +++ b/drivers/interconnect/debugfs-client.c @@ -16,6 +16,7 @@ #undef INTERCONNECT_ALLOW_WRITE_DEBUGFS #if defined(INTERCONNECT_ALLOW_WRITE_DEBUGFS) && defined(CONFIG_DEBUG_FS) +#define INITNODE_SIZE 1 static LIST_HEAD(debugfs_paths); static DEFINE_MUTEX(debugfs_lock); @@ -147,8 +148,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(INITNODE_SIZE, GFP_KERNEL); + dst_node = kzalloc(INITNODE_SIZE, 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 Fri Aug 30 10:23:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yibin Ding X-Patchwork-Id: 824664 Received: from SHSQR01.spreadtrum.com (unknown [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 CB16D17B4F5; Fri, 30 Aug 2024 10:23:51 +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=1725013434; cv=none; b=AWVcaKOYsW9cqObQh6DX7UvISOo+Gc3PSjd5hXN3kNCBidvashnWgaEIbH9LDKd6XmrWF4ZqY2gb1MdJn34CQso8YzPoqyytaSzECNOpBkneW0ZaKo9pyMNlCotN5ybl+slISsKmuyB5L8r4LCvwqWQWpqcXXna0W9laJCS6bTQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725013434; c=relaxed/simple; bh=gPn3ocUVhQgAWNFUlaGK72RHnsXD6uEOO6+5lQ9CLRs=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=U0QIbG4EUvkjVtnLvm/20uJAVuzhiVCGyowOSAJaiCvnz4vC0u9NuSLRXe0aYECVIEw0+Iq19PjKzp/SRJXsGPK6o4awqAjxMytqvJvgkq1pXA7tWUiXIJ0E2Br15OkW9BPGws2Z9jnvurBT3e6iIhCadC+5QQJ0lgV3GVSpAJg= 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 47UANJ0U032921; Fri, 30 Aug 2024 18:23:19 +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 4WwDZg3DD0z2N5cJc; Fri, 30 Aug 2024 18:16:27 +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; Fri, 30 Aug 2024 18:23:17 +0800 From: Yibin Ding To: , , CC: , , , , , Subject: [PATCH 2/2] debugfs: Fix crash problem caused by accessing uninitialized nodes Date: Fri, 30 Aug 2024 18:23:14 +0800 Message-ID: <20240830102314.409307-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 47UANJ0U032921 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) {