[PATCH] block: reject unterminated partition names in blkdevparts
From: shao.mingyin
Date: Sat Nov 14 2026 - 11:34:40 EST
From: Shao Mingyin <shao.mingyin@xxxxxxxxxx>
When a blkdevparts entry contains an opening parenthesis without a
closing parenthesis, strsep() returns the remaining name and sets
partdef to NULL. Checking its return value therefore accepts the
malformed entry, and the subsequent strncmp() calls dereference NULL
while scanning the disk's partitions.
Check the updated cursor instead so that the parser releases the
partially allocated entry and returns -EINVAL for a missing delimiter.
Fixes: bc2e07dfd2c4 ("block: fix and simplify blkdevparts= cmdline parsing")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Shao Mingyin <shao.mingyin@xxxxxxxxxx>
---
Testing:
Tested on x86_64 Linux next-20261113 in QEMU/KVM with virtio-blk.
A blkdevparts entry with no closing parenthesis crashes the base kernel
in strncmp() during partition scanning. The fixed kernel rejects it and
boots normally. A well-formed named partition is parsed in both kernels.
Also built with W=1 for m68k and i386.
base-commit: 84abb955b1015477aa11a96e2f3ac1b938b77f48
block/partitions/cmdline.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/block/partitions/cmdline.c b/block/partitions/cmdline.c
index 4fd52ed154b4e81984cdb7119669846263446623..454a4ce9c9f0ac0b7980f626a6a5fe2d479e4490 100644
--- a/block/partitions/cmdline.c
+++ b/block/partitions/cmdline.c
@@ -73,7 +73,7 @@ static int parse_subpart(struct cmdline_subpart **subpart, char *partdef)
partdef++;
char *next = strsep(&partdef, ")");
- if (!next) {
+ if (!partdef) {
pr_warn("cmdline partition format is invalid.");
ret = -EINVAL;
goto fail;
--
2.43.0