binutils-gdb/gdb/common
Jan Kratochvil 184cd07257 Fix crash on process name "(sd-pam)" (PR 16594).
info os processes -fsanitize=address error
https://sourceware.org/bugzilla/show_bug.cgi?id=16594

info os processes
=================================================================
==5795== ERROR: AddressSanitizer: heap-use-after-free on address
0x600600214974 at pc 0x757a92 bp 0x7fff95dd9f00 sp 0x7fff95dd9ef0
READ of size 4 at 0x600600214974 thread T0
    #0 0x757a91 in get_cores_used_by_process (.../gdb/gdb+0x757a91)

At least Fedora 20 has process(es):
 6678 ?        Ss     0:00 /usr/lib/systemd/systemd --user
 6680 ?        S      0:00  \_ (sd-pam)

and GDB "info os processes" crashes on it as /proc/6680/stat contains:

6680 ((sd-pam)) S 6678 6678 6678 0 -1 1077961024 33 0 0 0 0 0 0 0 20 0 1 0 18568 73768960 120 18446744073709551615 1 1
0 0 0 0 0 4096 0 18446744073709551615 0 0 17 6 0 0 0 0 0 0 0 0 0 0 0 0 0

and GDB fails to find the proper end of the process name "((sd-pam))".
Therefore it reads core number off-by-one (it reads 17 instead of 6) and
overruns the array.

(1) Make the process name parsing more foolproof.

(2) Do not trust the parsed number from /proc/PID/stat and verify it against
    the array size.

I noticed that 'ps' gets this right, so I've peeked at its
sources, and it just looks for the first ')' starting at
the end.

dc072aced7:proc/readproc.c

Look for stat2proc.

Given ps does that, I believe the kernel won't ever be changed
in a way that would break it.  So it sounds like could do strrchr
from the end of stat just as well without worry, which is simpler.

gdb/
2014-02-21  Jan Kratochvil  <jan.kratochvil@redhat.com>

	PR gdb/16594
	* common/linux-osdata.c (linux_common_core_of_thread): Find the end of
	process name.
	(get_cores_used_by_process): New parameter num_cores, use it.
	(linux_xfer_osdata_processes): Pass num_cores to it.
	* linux-tdep.c (linux_info_proc, linux_fill_prpsinfo): Find the end of
	process name.

Message-ID: <20140217212826.GA15080@host2.jankratochvil.net>
2014-02-21 18:39:40 +01:00
..
agent.c Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
agent.h Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
ax.def Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
break-common.h Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
btrace-common.h btrace, gdbserver: read branch trace incrementally 2014-01-16 13:11:42 +01:00
buffer.c Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
buffer.h Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
common-utils.c Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
common-utils.h Add ARI (ok) marker for __func__ reference in common-utils.h 2014-01-22 09:03:31 +04:00
common.m4 Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
create-version.sh Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
filestuff.c Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
filestuff.h Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
format.c Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
format.h Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
gdb_assert.h Move ASSERT_FUNCTION to FUNCTION_NAME. 2014-01-17 10:00:07 -08:00
gdb_locale.h Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
gdb_signals.h Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
gdb_thread_db.h Move fallback thread_db.h to a separate file. 2013-04-16 18:14:55 +00:00
gdb_vecs.c Add delim_string_to_char_ptr_vec. 2014-01-17 10:23:29 -08:00
gdb_vecs.h Add delim_string_to_char_ptr_vec. 2014-01-17 10:23:29 -08:00
gdb_wait.h Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
glibc_thread_db.h Update glibc_thread_db.h from upstream. 2013-04-16 18:17:11 +00:00
host-defs.h Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
i386-cpuid.h Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
i386-gcc-cpuid.h Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
i386-xstate.h Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
linux-btrace.c convert to_supports_btrace 2014-02-19 07:45:26 -07:00
linux-btrace.h convert to_supports_btrace 2014-02-19 07:45:26 -07:00
linux-osdata.c Fix crash on process name "(sd-pam)" (PR 16594). 2014-02-21 18:39:40 +01:00
linux-osdata.h Change 'len' of linux_common_xfer_osdata to ULONGEST. 2014-01-14 22:20:51 +08:00
linux-procfs.c Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
linux-procfs.h Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
linux-ptrace.c Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
linux-ptrace.h Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mips-linux-watch.c Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mips-linux-watch.h Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
print-utils.c share "cell" code 2014-02-12 09:59:13 -07:00
print-utils.h share "cell" code 2014-02-12 09:59:13 -07:00
ptid.c Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
ptid.h common/ptid.h: Mention that process_stratum targets should prefer ptid.lwp. 2014-02-19 18:27:01 +00:00
queue.h Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
rsp-low.c update rsp-low comments 2014-02-12 09:59:20 -07:00
rsp-low.h update rsp-low comments 2014-02-12 09:59:20 -07:00
signals.c Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
vec.c Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
vec.h Move ASSERT_FUNCTION to FUNCTION_NAME. 2014-01-17 10:00:07 -08:00
version.h Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
xml-utils.c Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
xml-utils.h Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00