[PATCH 1/2] unwind: accept fake files like [vdso] as map entries

Masatake YAMATO yamato at redhat.com
Wed Jun 11 18:44:53 UTC 2014


For making caches for process memory mapping, /proc/$pid/maps files
are scanned. When scanning an entry which file name is started from
`[' was ignore as fake files. As the result a system call using
[vdso] causes `unexpected_backtracing_error'.

This patch accepts the fake files as cache entries if they have
both readable and executable attributes. ([stack] and [heap] does
not have such attributes.)

Signed-off-by: Masatake YAMATO <yamato at redhat.com>
---
 unwind.c | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)

diff --git a/unwind.c b/unwind.c
index aff6c5a..788ed54 100644
--- a/unwind.c
+++ b/unwind.c
@@ -137,6 +137,7 @@ static void
 build_mmap_cache(struct tcb* tcp)
 {
 	unsigned long start_addr, end_addr, mmap_offset;
+	char rflg, xflg;
 	char filename[sizeof ("/proc/0123456789/maps")];
 	char buffer[PATH_MAX + 80];
 	char binary_path[PATH_MAX];
@@ -164,14 +165,27 @@ build_mmap_cache(struct tcb* tcp)
 		die_out_of_memory();
 
 	while (fgets(buffer, sizeof(buffer), fp) != NULL) {
-		binary_path[0] = '\0'; // 'reset' it just to be paranoid
-
-		sscanf(buffer, "%lx-%lx %*c%*c%*c%*c %lx %*x:%*x %*d %[^\n]",
-		       &start_addr, &end_addr, &mmap_offset, binary_path);
-
-		/* ignore special 'fake files' like "[vdso]", "[heap]", "[stack]", */
+		/* 'reset' it just to be paranoid */
+		binary_path[0] = '\0';
+		rflg = xflg = '-';
+
+		sscanf(buffer, "%lx-%lx %c%*c%c%*c %lx %*x:%*x %*d %[^\n]",
+		       &start_addr, &end_addr,
+		       &rflg, &xflg,
+		       &mmap_offset, binary_path);
+
+		/* ignore special 'fake files' like "[heap]", "[stack]",
+		   Normally ip should not jump into there.
+
+		   $ cat /proc/self/maps | grep '\['
+		   01105000-01126000 rw-p 00000000 00:00 0                                  [heap]
+		   7fff495a0000-7fff495c1000 rw-p 00000000 00:00 0                          [stack]
+		   7fff495fe000-7fff49600000 r-xp 00000000 00:00 0                          [vdso]
+		   ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall] */
 		if (binary_path[0] == '[') {
-			continue;
+			if (!(rflg == 'r' && xflg == 'x'))
+				continue;
+			/* [vdso] is acceptable. */
 		}
 
 		if (binary_path[0] == '\0') {
-- 
1.9.0





More information about the Strace-devel mailing list