[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20250609134511.1342999-19-sashal@kernel.org>
Date: Mon, 9 Jun 2025 09:45:00 -0400
From: Sasha Levin <sashal@...nel.org>
To: patches@...ts.linux.dev,
stable@...r.kernel.org
Cc: Chenyuan Yang <chenyuan0y@...il.com>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Sasha Levin <sashal@...nel.org>,
richardcochran@...il.com,
netdev@...r.kernel.org
Subject: [PATCH AUTOSEL 6.14 19/29] misc: tps6594-pfsm: Add NULL pointer check in tps6594_pfsm_probe()
From: Chenyuan Yang <chenyuan0y@...il.com>
[ Upstream commit a99b598d836c9c6411110c70a2da134c78d96e67 ]
The returned value, pfsm->miscdev.name, from devm_kasprintf()
could be NULL.
A pointer check is added to prevent potential NULL pointer dereference.
This is similar to the fix in commit 3027e7b15b02
("ice: Fix some null pointer dereference issues in ice_ptp.c").
This issue is found by our static analysis tool.
Signed-off-by: Chenyuan Yang <chenyuan0y@...il.com>
Link: https://lore.kernel.org/r/20250311010511.1028269-1-chenyuan0y@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Signed-off-by: Sasha Levin <sashal@...nel.org>
---
**YES**
This commit should be backported to stable kernel trees. Here's my
detailed analysis:
## Analysis
### 1. Bug Fix Nature
This commit fixes a clear NULL pointer dereference vulnerability. The
`devm_kasprintf()` function can return NULL on memory allocation
failure, and the code was not checking this return value before using
`pfsm->miscdev.name`. This would lead to a NULL pointer dereference when
`misc_register(&pfsm->miscdev)` is called at line 302.
### 2. Code Analysis
Looking at the specific changes in `drivers/misc/tps6594-pfsm.c`:
**Before the fix (lines 282-283):**
```c
pfsm->miscdev.name = devm_kasprintf(dev, GFP_KERNEL, "pfsm-%ld-0x%02x",
tps->chip_id, tps->reg);
```
**After the fix (lines 282-286):**
```c
pfsm->miscdev.name = devm_kasprintf(dev, GFP_KERNEL, "pfsm-%ld-0x%02x",
tps->chip_id, tps->reg);
+if (!pfsm->miscdev.name)
+ return -ENOMEM;
```
The fix adds essential NULL pointer checking that prevents potential
kernel crashes.
### 3. Comparison with Similar Commits
This fix follows the exact same pattern as the reference commits marked
as "Backport Status: YES":
- **Similar Commit #1 (ipmi)**: Same issue with `devm_kasprintf()` not
being checked
- **Similar Commit #2 (mfd: tps6594)**: Same issue, even in the same
TPS6594 subsystem
- **Similar Commit #4 (ice)**: Same issue, explicitly referenced in the
commit message
All these similar commits were deemed suitable for backporting because
they fix the same fundamental issue.
### 4. Risk Assessment
- **Minimal risk**: The fix is a simple 2-line addition that only adds
error checking
- **No side effects**: The change doesn't alter functionality, only
prevents crashes
- **Contained scope**: Only affects the TPS6594 PFSM driver
initialization path
- **No architectural changes**: Doesn't modify any interfaces or major
logic
### 5. Stability Criteria Met
- ✅ **Important bug fix**: Prevents kernel NULL pointer dereference
crashes
- ✅ **Minimal and contained**: Only 2 lines added for error checking
- ✅ **Low regression risk**: Cannot introduce new issues, only prevents
crashes
- ✅ **Clear fix**: Addresses a well-defined problem with obvious
solution
### 6. Driver Context
The TPS6594 PFSM driver was introduced in kernel v6.10, making it a
relatively recent addition. The driver handles power management for TI
PMIC devices, making reliability crucial for system stability.
### 7. Static Analysis Tool Finding
The commit message mentions this was found by static analysis, which
indicates it's a real potential issue that could manifest under memory
pressure conditions.
This commit clearly meets all the criteria for stable tree backporting:
it's a small, contained fix for an important potential crash bug with
minimal risk of regression.
drivers/misc/tps6594-pfsm.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/misc/tps6594-pfsm.c b/drivers/misc/tps6594-pfsm.c
index 0a24ce44cc37c..6db1c9d48f8fc 100644
--- a/drivers/misc/tps6594-pfsm.c
+++ b/drivers/misc/tps6594-pfsm.c
@@ -281,6 +281,9 @@ static int tps6594_pfsm_probe(struct platform_device *pdev)
pfsm->miscdev.minor = MISC_DYNAMIC_MINOR;
pfsm->miscdev.name = devm_kasprintf(dev, GFP_KERNEL, "pfsm-%ld-0x%02x",
tps->chip_id, tps->reg);
+ if (!pfsm->miscdev.name)
+ return -ENOMEM;
+
pfsm->miscdev.fops = &tps6594_pfsm_fops;
pfsm->miscdev.parent = dev->parent;
pfsm->chip_id = tps->chip_id;
--
2.39.5
Powered by blists - more mailing lists