|
|
6543d1 |
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
|
|
|
6543d1 |
From: Keith Seitz <keiths@redhat.com>
|
|
|
6543d1 |
Date: Mon, 27 Jul 2020 19:21:54 -0400
|
|
|
6543d1 |
Subject: gdb-rhbz1842691-corefile-mem-access-9of15.patch
|
|
|
6543d1 |
|
|
|
6543d1 |
;; Add test for accessing read-only mmapped data in a core file
|
|
|
6543d1 |
;; Kevin Buettner, RH BZ 1842691
|
|
|
6543d1 |
|
|
|
6543d1 |
Author: Kevin Buettner <kevinb@redhat.com>
|
|
|
6543d1 |
Date: Tue Jun 16 11:39:22 2020 -0700
|
|
|
6543d1 |
|
|
|
6543d1 |
Add test for accessing read-only mmapped data in a core file
|
|
|
6543d1 |
|
|
|
6543d1 |
This test passes when run using a GDB with my corefile patches. When
|
|
|
6543d1 |
run against a GDB without my patches, I see the following failures,
|
|
|
6543d1 |
the first of which is due to the test added by this commit:
|
|
|
6543d1 |
|
|
|
6543d1 |
FAIL: gdb.base/corefile.exp: accessing read-only mmapped data in core file (
|
|
|
6543d1 |
FAIL: gdb.base/corefile.exp: accessing anonymous, unwritten-to mmap data
|
|
|
6543d1 |
|
|
|
6543d1 |
gdb/testsuite/ChangeLog:
|
|
|
6543d1 |
|
|
|
6543d1 |
* gdb.base/corefile.exp: Add test "accessing read-only mmapped
|
|
|
6543d1 |
data in core file".
|
|
|
6543d1 |
* gdb.base/coremaker.c (buf2ro): New global.
|
|
|
6543d1 |
(mmapdata): Add a read-only mmap mapping.
|
|
|
6543d1 |
|
|
|
6543d1 |
diff --git a/gdb/testsuite/gdb.base/corefile.exp b/gdb/testsuite/gdb.base/corefile.exp
|
|
|
6543d1 |
--- a/gdb/testsuite/gdb.base/corefile.exp
|
|
|
6543d1 |
+++ b/gdb/testsuite/gdb.base/corefile.exp
|
|
|
6543d1 |
@@ -34,7 +34,10 @@ if {[build_executable $testfile.exp $testfile $srcfile debug] == -1} {
|
|
|
6543d1 |
return -1
|
|
|
6543d1 |
}
|
|
|
6543d1 |
|
|
|
6543d1 |
-set corefile [core_find $binfile {coremmap.data}]
|
|
|
6543d1 |
+# Do not delete coremap.data when calling core_find. This file is
|
|
|
6543d1 |
+# required for GDB to find mmap'd data in the "accessing read-only
|
|
|
6543d1 |
+# mmapped data in core file" test.
|
|
|
6543d1 |
+set corefile [core_find $binfile {}]
|
|
|
6543d1 |
if {$corefile == ""} {
|
|
|
6543d1 |
return 0
|
|
|
6543d1 |
}
|
|
|
6543d1 |
@@ -175,6 +178,19 @@ gdb_test_multiple "x/8bd buf2" "$test" {
|
|
|
6543d1 |
}
|
|
|
6543d1 |
}
|
|
|
6543d1 |
|
|
|
6543d1 |
+set test "accessing read-only mmapped data in core file"
|
|
|
6543d1 |
+gdb_test_multiple "x/8bd buf2ro" "$test" {
|
|
|
6543d1 |
+ -re ".*:.*0.*1.*2.*3.*4.*5.*6.*7.*$gdb_prompt $" {
|
|
|
6543d1 |
+ pass "$test"
|
|
|
6543d1 |
+ }
|
|
|
6543d1 |
+ -re "0x\[f\]*:.*Cannot access memory at address 0x\[f\]*.*$gdb_prompt $" {
|
|
|
6543d1 |
+ fail "$test (mapping failed at runtime)"
|
|
|
6543d1 |
+ }
|
|
|
6543d1 |
+ -re "0x.*:.*Cannot access memory at address 0x.*$gdb_prompt $" {
|
|
|
6543d1 |
+ fail "$test (mapping address not found in core file)"
|
|
|
6543d1 |
+ }
|
|
|
6543d1 |
+}
|
|
|
6543d1 |
+
|
|
|
6543d1 |
# Test ability to read anonymous and, more importantly, unwritten-to
|
|
|
6543d1 |
# mmap'd data.
|
|
|
6543d1 |
|
|
|
6543d1 |
diff --git a/gdb/testsuite/gdb.base/coremaker.c b/gdb/testsuite/gdb.base/coremaker.c
|
|
|
6543d1 |
--- a/gdb/testsuite/gdb.base/coremaker.c
|
|
|
6543d1 |
+++ b/gdb/testsuite/gdb.base/coremaker.c
|
|
|
6543d1 |
@@ -38,6 +38,7 @@
|
|
|
6543d1 |
|
|
|
6543d1 |
char *buf1;
|
|
|
6543d1 |
char *buf2;
|
|
|
6543d1 |
+char *buf2ro;
|
|
|
6543d1 |
char *buf3;
|
|
|
6543d1 |
|
|
|
6543d1 |
int coremaker_data = 1; /* In Data section */
|
|
|
6543d1 |
@@ -90,16 +91,25 @@ mmapdata ()
|
|
|
6543d1 |
return;
|
|
|
6543d1 |
}
|
|
|
6543d1 |
|
|
|
6543d1 |
+ /* Map in another copy, read-only. We won't write to this copy so it
|
|
|
6543d1 |
+ will likely not end up in the core file. */
|
|
|
6543d1 |
+ buf2ro = (char *) mmap (0, MAPSIZE, PROT_READ, MAP_PRIVATE, fd, 0);
|
|
|
6543d1 |
+ if (buf2ro == (char *) -1)
|
|
|
6543d1 |
+ {
|
|
|
6543d1 |
+ perror ("mmap failed");
|
|
|
6543d1 |
+ return;
|
|
|
6543d1 |
+ }
|
|
|
6543d1 |
+
|
|
|
6543d1 |
/* Verify that the original data and the mapped data are identical.
|
|
|
6543d1 |
If not, we'd rather fail now than when trying to access the mapped
|
|
|
6543d1 |
data from the core file. */
|
|
|
6543d1 |
|
|
|
6543d1 |
for (j = 0; j < MAPSIZE; ++j)
|
|
|
6543d1 |
{
|
|
|
6543d1 |
- if (buf1[j] != buf2[j])
|
|
|
6543d1 |
+ if (buf1[j] != buf2[j] || buf1[j] != buf2ro[j])
|
|
|
6543d1 |
{
|
|
|
6543d1 |
fprintf (stderr, "mapped data is incorrect");
|
|
|
6543d1 |
- buf2 = (char *) -1;
|
|
|
6543d1 |
+ buf2 = buf2ro = (char *) -1;
|
|
|
6543d1 |
return;
|
|
|
6543d1 |
}
|
|
|
6543d1 |
}
|