Skip to contentSkip to conversation

kdb: do a sanity check on the cpu in kdb_per_cpu()

PATCH In review Dan Carpenter 3 participants 4 messages May 6, 2019 – May 8, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kdb: do a sanity check on the cpu in kdb_per_cpu()

The "whichcpu" comes from argv[3]. The cpu_online() macro looks up the cpu in a bitmap of online cpus, but if the value is too high then it could read beyond the end of the bitmap and possibly Oops.

Fixes 5d5314d6795f ("kdb: core for kgdb back end (1 of 2)")
---
 kernel/debug/kdb/kdb_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/debug/kdb/kdb_main.c +1 -1
index fc96dbf8d9de..9ecfa37c7fbf 100644
@@ -2583,7 +2583,7 @@ static int kdb_per_cpu(int argc, const char **argv)
 		diag = kdbgetularg(argv[3], &whichcpu);
 		if (diag)
 			return diag;
-		if (!cpu_online(whichcpu)) {
+		if (whichcpu >= nr_cpu_ids || !cpu_online(whichcpu)) {
 			kdb_printf("cpu %ld is not online\n", whichcpu);
 			return KDB_BADCPUNUM;
 		}
Signature · 1 line
2.18.0
#1 lore raw
Quoted 6 lines · Dan Carpenter

The "whichcpu" comes from argv[3]. The cpu_online() macro looks up the cpu in a bitmap of online cpus, but if the value is too high then it could read beyond the end of the bitmap and possibly Oops.

Fixes 5d5314d6795f ("kdb: core for kgdb back end (1 of 2)")

Just out of interest... why isn't this copied to LKML? Omiting LKML makes the patch hard to find in a patchwork instance.

Daniel.

Quoted 20 lines
---
 kernel/debug/kdb/kdb_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/debug/kdb/kdb_main.c +1 -1
index fc96dbf8d9de..9ecfa37c7fbf 100644
@@ -2583,7 +2583,7 @@ static int kdb_per_cpu(int argc, const char **argv)
 		diag = kdbgetularg(argv[3], &whichcpu);
 		if (diag)
 			return diag;
-		if (!cpu_online(whichcpu)) {
+		if (whichcpu >= nr_cpu_ids || !cpu_online(whichcpu)) {
 			kdb_printf("cpu %ld is not online\n", whichcpu);
 			return KDB_BADCPUNUM;
 		}
Signature · 1 line
2.18.0
#2 lore raw
In reply to Dan Carpenter
Quoted 10 lines · Daniel Thompson
Quoted 6 lines · Dan Carpenter

The "whichcpu" comes from argv[3]. The cpu_online() macro looks up the cpu in a bitmap of online cpus, but if the value is too high then it could read beyond the end of the bitmap and possibly Oops.

Fixes 5d5314d6795f ("kdb: core for kgdb back end (1 of 2)")

Just out of interest... why isn't this copied to LKML? Omiting LKML makes the patch hard to find in a patchwork instance.

Sorry, I wasn't aware that anyone was using LKML for patchwork.

regards,
dan carpenter

reviewer Reviewed-by on v1 1/1
#3 lore raw
In reply to Dan Carpenter

Hi,

Quoted 10 lines · Dan Carpenter

The "whichcpu" comes from argv[3]. The cpu_online() macro looks up the cpu in a bitmap of online cpus, but if the value is too high then it could read beyond the end of the bitmap and possibly Oops.

Fixes 5d5314d6795f ("kdb: core for kgdb back end (1 of 2)")
---
 kernel/debug/kdb/kdb_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)