Forwarded: [PATCH] mtd: phram: fix memory leak in phram_setup()
From: syzbot
Date: Sat Oct 17 2026 - 19:32:34 EST
For archival purposes, forwarding an incoming command email to
linux-kernel@xxxxxxxxxxxxxxx, syzkaller-bugs@xxxxxxxxxxxxxxxx.
***
Subject: [PATCH] mtd: phram: fix memory leak in phram_setup()
Author: kartikey406@xxxxxxxxx
#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
phram_setup() allocates the device name with kstrdup() in
parse_name(). The error paths that follow (illegal start address,
illegal device length, illegal erasesize, illegal erasesize or len,
and len not a multiple of erasesize) use the parse_err() macro, which
expands to pr_err() followed by an immediate "return 1". The
"goto error" statements after it are therefore never reached, and
kfree(name) at the error label is skipped, leaking the name.
Replace parse_err() with pr_err() at those sites so control reaches
the error label and frees the name. Leave the parse_err() calls that
run before parse_name() alone, since nothing has been allocated yet.
As a side effect, these paths now return a negative errno instead of
1, which is the correct convention for a module parameter setter.
Reported-by: syzbot+c9d8bc9f8ccc03799e1f@xxxxxxxxxxxxxxxxxxxxxxxxx
Closes: https://syzkaller.appspot.com/bug?extid=c9d8bc9f8ccc03799e1f
Signed-off-by: Deepanshu Kartikey <kartikey406@xxxxxxxxx>
---
drivers/mtd/devices/phram.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/mtd/devices/phram.c b/drivers/mtd/devices/phram.c
index b42cadcd76b1..7aed57b31967 100644
--- a/drivers/mtd/devices/phram.c
+++ b/drivers/mtd/devices/phram.c
@@ -289,34 +289,34 @@ static int phram_setup(const char *val)
ret = parse_num64(&start, token[1]);
if (ret) {
- parse_err("illegal start address\n");
+ pr_err("illegal start address\n");
goto error;
}
ret = parse_num64(&len, token[2]);
if (ret) {
- parse_err("illegal device length\n");
+ pr_err("illegal device length\n");
goto error;
}
if (token[3]) {
ret = parse_num64(&erasesize, token[3]);
if (ret) {
- parse_err("illegal erasesize\n");
+ pr_err("illegal erasesize\n");
goto error;
}
}
if (len == 0 || erasesize == 0 || erasesize > len
|| erasesize > UINT_MAX) {
- parse_err("illegal erasesize or len\n");
+ pr_err("illegal erasesize or len\n");
ret = -EINVAL;
goto error;
}
div_u64_rem(len, (uint32_t)erasesize, &rem);
if (rem) {
- parse_err("len is not multiple of erasesize\n");
+ pr_err("len is not multiple of erasesize\n");
ret = -EINVAL;
goto error;
}
--
2.43.0