Skip to contentSkip to conversation

kdb: fix strncpy warning

PATCH In review Olof Johansson 3 participants 4 messages Nov 2, 2018 – Nov 5, 2018 KGDB / KDB /debug_core

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kdb: fix strncpy warning

kdb does a strncpy(a, b, strlen(b)+1), which makes no sense. Might as well do a strcpy at this point.

Fixes this warning:

In function 'strncpy', inlined from 'kallsyms_symbol_next' at kernel/debug/kdb/kdb_support.c:239:4:
./include/linux/string.h:253:9: warning: '__builtin_strncpy' specified bound depends on the length of the source argument [-Wstringop-overflow=]

---
 kernel/debug/kdb/kdb_support.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/debug/kdb/kdb_support.c +1 -1
index 990b3cc526c8..d5af8b38b84d 100644
@@ -236,7 +236,7 @@ int kallsyms_symbol_next(char *prefix_name, int flag)
 
 	while ((name = kdb_walk_kallsyms(&pos))) {
 		if (strncmp(name, prefix_name, prefix_len) == 0) {
-			strncpy(prefix_name, name, strlen(name)+1);
+			strcpy(prefix_name, name);
 			return 1;
 		}
 	}
Signature · 1 line
2.11.0
#1 lore raw
Quoted 7 lines · Olof Johansson

kdb does a strncpy(a, b, strlen(b)+1), which makes no sense. Might as well do a strcpy at this point.

Fixes this warning:

In function 'strncpy', inlined from 'kallsyms_symbol_next' at kernel/debug/kdb/kdb_support.c:239:4:
./include/linux/string.h:253:9: warning: '__builtin_strncpy' specified bound depends on the length of the source argument [-Wstringop-overflow=]

I think we already have a pending patch for this:
https://lore.kernel.org/patchwork/patch/989013/

When we looked into this there actually is an unchecked overflow here so Prarit's fix adds infrastructure to keep track of the remaining length.

Daniel.

Quoted 22 lines
---
 kernel/debug/kdb/kdb_support.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/debug/kdb/kdb_support.c +1 -1
index 990b3cc526c8..d5af8b38b84d 100644
@@ -236,7 +236,7 @@ int kallsyms_symbol_next(char *prefix_name, int flag)
 
 	while ((name = kdb_walk_kallsyms(&pos))) {
 		if (strncmp(name, prefix_name, prefix_len) == 0) {
-			strncpy(prefix_name, name, strlen(name)+1);
+			strcpy(prefix_name, name);
 			return 1;
 		}
 	}
Signature · 1 line
2.11.0
#2 lore raw
Quoted 7 lines · Daniel Thompson
Quoted 5 lines · Olof Johansson

kdb does a strncpy(a, b, strlen(b)+1), which makes no sense. Might as well do a strcpy at this point.

Fixes this warning:

Quoted 8 lines
Quoted 2 lines

In function 'strncpy', inlined from 'kallsyms_symbol_next' at kernel/debug/kdb/kdb_support.c:239:4:
./include/linux/string.h:253:9: warning: '__builtin_strncpy' specified bound depends on the length of the source argument [-Wstringop-overflow=]

I think we already have a pending patch for this:
https://lore.kernel.org/patchwork/patch/989013/

When we looked into this there actually is an unchecked overflow here so Prarit's fix adds infrastructure to keep track of the remaining length.

I'm not surprised that there are more bugs.

The above patch was posted a month and a half ago though, why is it not yet merged? Can we get it in by -rc2, please?

-Olof

#3 lore raw
Quoted 15 lines · Olof Johansson
Quoted 13 lines · Daniel Thompson
Quoted 7 lines · Olof Johansson

kdb does a strncpy(a, b, strlen(b)+1), which makes no sense. Might as well do a strcpy at this point.

Fixes this warning:

In function 'strncpy', inlined from 'kallsyms_symbol_next' at kernel/debug/kdb/kdb_support.c:239:4:
./include/linux/string.h:253:9: warning: '__builtin_strncpy' specified bound depends on the length of the source argument [-Wstringop-overflow=]

I think we already have a pending patch for this:
https://lore.kernel.org/patchwork/patch/989013/

Quoted 9 lines
Quoted 2 lines

When we looked into this there actually is an unchecked overflow here so Prarit's fix adds infrastructure to keep track of the remaining length.

I'm not surprised that there are more bugs.

The above patch was posted a month and a half ago though, why is it not yet merged? Can we get it in by -rc2, please?

Jason? ping? Just making sure the above patch is in your queue.

P.

Quoted 2 lines

-Olof