Mostly clean ups but there are also a couple of out-of-bounds accesses
 (including a potential write to the byte before a static buffer).
 
 The main changes are:
 
  * Fixes those out-of-bounds access (empty string to configure
    test module could write the byte before a buffer, high cpu counts
    could read outside of per-cpu structures).
 
  * Improvements to string handling problems picked up by new compiler
    warnings and other static checks. Most are fixing benign issues that
    can't be tickled without code changes but still reduce the wtf factor
    a little.
 
  * Tidy up the terminal output.
 
 Signed-off-by: Daniel Thompson <daniel.thompson@linaro.org>
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCAAdFiEELzVBU1D3lWq6cKzwfOMlXTn3iKEFAlza6CEACgkQfOMlXTn3
 iKHkwA/8CmCq7UA3ZZsItHYn48Xa4YzxySErhpocsqa7U7tPh7f7ETv6NkfmjxEQ
 MGmQflKw/yU3avR6eHUfJcd4AO3+x0Vi5wR9fhevAVu3sfnjTjTjP0F2tDjWe+Y/
 TJob4/gSssmDp1+DtFvOQdOmGVz9C7xMQ2wZFjQcpAwesLLbwu+KPZDcBPpyRnl1
 zSOIUtTxHH6ay2PX57CNAWEmE4SFoUha7712GTHVHe3rykrC+CLYNeCRzUuyTSAz
 OaPTNzd/OFz+uLcsvTPothpc3wUfM4MUkuCkAVKpuMcB2D+/7WqqszUfHYWJ27bH
 oeYqRyeQaRa6COFkxZ4XZQRMBOYzzidVboTDjlTj391qq5L32tje75TtfHgCJ/p7
 vlg0QdbrHOFaDF9aXcmqLr7kNRi83NxNPhg4XHA75MRHFBGvRkMd3jmuZdShFKc7
 Yegr+pR0FJwivZz8+UcRPAdI5gdmSWLdpeB2GhtZqDk3975Qjvsy90ieG7GQnjR8
 /ewoYsFQ5/qXwyZzJ+kHxAmTMWpGYx8Kge77j5UMljPsuSuHU56vUt4ovzSiSzuX
 dTAxLRmrYi6Dlri76EHEoE+1mx301ymK4MXMz8WnNVQhnPnkCcEXx7P3neCB/wuX
 w1O2VvMQ8b4si1/M71QFcAgQjMcJz7z8wGwhfnnqFPgZmVT5n/8=
 =SsRX
 -----END PGP SIGNATURE-----

Merge tag 'kgdb-5.2-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/danielt/linux

Pull kgdb updates from Daniel Thompson:
 "Mostly cleanups but there are also a couple of fixes for out-of-bounds
  accesses (including a potential write to the byte before a static
  buffer).

  The main changes are:

   - Fixes to those out-of-bounds access (empty string to configure test
     module could write the byte before a buffer, high cpu counts could
     read outside of per-cpu structures).

   - Improvements to string handling problems picked up by new compiler
     warnings and other static checks. Most are fixing benign issues
     that can't be tickled without code changes but still reduce the wtf
     factor a little.

   - Tidy up the terminal output"

* tag 'kgdb-5.2-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/danielt/linux:
  kdb: Fix bound check compiler warning
  kdb: do a sanity check on the cpu in kdb_per_cpu()
  kdb: Get rid of broken attempt to print CCVERSION in kdb summary
  misc: kgdbts: fix out-of-bounds access in function param_set_kgdbts_var
  kdb: kdb_support: replace strcpy() by strscpy()
  gdbstub: Replace strcpy() by strscpy()
  gdbstub: mark expected switch fall-throughs
This commit is contained in:
Linus Torvalds 2019-05-14 13:14:10 -07:00
Родитель 280664f558 ca976bfb31
Коммит ca4b40629f
5 изменённых файлов: 8 добавлений и 9 удалений

Просмотреть файл

@ -1033,13 +1033,14 @@ int gdb_serial_stub(struct kgdb_state *ks)
return DBG_PASS_EVENT; return DBG_PASS_EVENT;
} }
#endif #endif
/* Fall through */
case 'C': /* Exception passing */ case 'C': /* Exception passing */
tmp = gdb_cmd_exception_pass(ks); tmp = gdb_cmd_exception_pass(ks);
if (tmp > 0) if (tmp > 0)
goto default_handle; goto default_handle;
if (tmp == 0) if (tmp == 0)
break; break;
/* Fall through on tmp < 0 */ /* Fall through - on tmp < 0 */
case 'c': /* Continue packet */ case 'c': /* Continue packet */
case 's': /* Single step packet */ case 's': /* Single step packet */
if (kgdb_contthread && kgdb_contthread != current) { if (kgdb_contthread && kgdb_contthread != current) {
@ -1048,7 +1049,7 @@ int gdb_serial_stub(struct kgdb_state *ks)
break; break;
} }
dbg_activate_sw_breakpoints(); dbg_activate_sw_breakpoints();
/* Fall through to default processing */ /* Fall through - to default processing */
default: default:
default_handle: default_handle:
error = kgdb_arch_handle_exception(ks->ex_vector, error = kgdb_arch_handle_exception(ks->ex_vector,
@ -1094,10 +1095,10 @@ int gdbstub_state(struct kgdb_state *ks, char *cmd)
return error; return error;
case 's': case 's':
case 'c': case 'c':
strcpy(remcom_in_buffer, cmd); strscpy(remcom_in_buffer, cmd, sizeof(remcom_in_buffer));
return 0; return 0;
case '$': case '$':
strcpy(remcom_in_buffer, cmd); strscpy(remcom_in_buffer, cmd, sizeof(remcom_in_buffer));
gdbstub_use_prev_in_buf = strlen(remcom_in_buffer); gdbstub_use_prev_in_buf = strlen(remcom_in_buffer);
gdbstub_prev_in_buf_pos = 0; gdbstub_prev_in_buf_pos = 0;
return 0; return 0;

Просмотреть файл

@ -6,7 +6,6 @@
# Copyright (c) 2009 Wind River Systems, Inc. All Rights Reserved. # Copyright (c) 2009 Wind River Systems, Inc. All Rights Reserved.
# #
CCVERSION := $(shell $(CC) -v 2>&1 | sed -ne '$$p')
obj-y := kdb_io.o kdb_main.o kdb_support.o kdb_bt.o gen-kdb_cmds.o kdb_bp.o kdb_debugger.o obj-y := kdb_io.o kdb_main.o kdb_support.o kdb_bt.o gen-kdb_cmds.o kdb_bp.o kdb_debugger.o
obj-$(CONFIG_KDB_KEYBOARD) += kdb_keyboard.o obj-$(CONFIG_KDB_KEYBOARD) += kdb_keyboard.o

Просмотреть файл

@ -446,7 +446,7 @@ poll_again:
char *kdb_getstr(char *buffer, size_t bufsize, const char *prompt) char *kdb_getstr(char *buffer, size_t bufsize, const char *prompt)
{ {
if (prompt && kdb_prompt_str != prompt) if (prompt && kdb_prompt_str != prompt)
strncpy(kdb_prompt_str, prompt, CMD_BUFLEN); strscpy(kdb_prompt_str, prompt, CMD_BUFLEN);
kdb_printf(kdb_prompt_str); kdb_printf(kdb_prompt_str);
kdb_nextline = 1; /* Prompt and input resets line number */ kdb_nextline = 1; /* Prompt and input resets line number */
return kdb_read(buffer, bufsize); return kdb_read(buffer, bufsize);

Просмотреть файл

@ -2522,7 +2522,6 @@ static int kdb_summary(int argc, const char **argv)
kdb_printf("machine %s\n", init_uts_ns.name.machine); kdb_printf("machine %s\n", init_uts_ns.name.machine);
kdb_printf("nodename %s\n", init_uts_ns.name.nodename); kdb_printf("nodename %s\n", init_uts_ns.name.nodename);
kdb_printf("domainname %s\n", init_uts_ns.name.domainname); kdb_printf("domainname %s\n", init_uts_ns.name.domainname);
kdb_printf("ccversion %s\n", __stringify(CCVERSION));
now = __ktime_get_real_seconds(); now = __ktime_get_real_seconds();
time64_to_tm(now, 0, &tm); time64_to_tm(now, 0, &tm);
@ -2584,7 +2583,7 @@ static int kdb_per_cpu(int argc, const char **argv)
diag = kdbgetularg(argv[3], &whichcpu); diag = kdbgetularg(argv[3], &whichcpu);
if (diag) if (diag)
return diag; return diag;
if (!cpu_online(whichcpu)) { if (whichcpu >= nr_cpu_ids || !cpu_online(whichcpu)) {
kdb_printf("cpu %ld is not online\n", whichcpu); kdb_printf("cpu %ld is not online\n", whichcpu);
return KDB_BADCPUNUM; return KDB_BADCPUNUM;
} }

Просмотреть файл

@ -192,7 +192,7 @@ int kallsyms_symbol_complete(char *prefix_name, int max_len)
while ((name = kdb_walk_kallsyms(&pos))) { while ((name = kdb_walk_kallsyms(&pos))) {
if (strncmp(name, prefix_name, prefix_len) == 0) { if (strncmp(name, prefix_name, prefix_len) == 0) {
strcpy(ks_namebuf, name); strscpy(ks_namebuf, name, sizeof(ks_namebuf));
/* Work out the longest name that matches the prefix */ /* Work out the longest name that matches the prefix */
if (++number == 1) { if (++number == 1) {
prev_len = min_t(int, max_len-1, prev_len = min_t(int, max_len-1,