New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
printsiginfo: decode si_pkey field #210
Conversation
This adds decoding of si_pkey field which is set on SIGSEGV in case of memory access violation on some modern CPUs (these have pku flag in /proc/cpuinfo). * NEWS: Mention this change. * configure.ac (AC_CHECK_MEMBERS): Check for siginfo_t.si_pkey. * src/printsiginfo.c (print_si_info) <case SIGSEGV> [HAVE_SIGINFO_T_SI_PKEY]: Decode si_pkey field.
Codecov Report
@@ Coverage Diff @@
## master #210 +/- ##
=======================================
Coverage 89.95% 89.95%
=======================================
Files 287 287
Lines 24043 24049 +6
=======================================
+ Hits 21628 21634 +6
Misses 2415 2415
Continue to review full report at Codecov.
|
* tests/segv_pkuerr.c: New file. * tests/gen_tests.in (segv_pkuerr): New test. * tests/Makefile.am (check_PROGRAMS): Add segv_pkuerr. * tests/.gitignore: Likewise. * tests/ptrace.c (main) [HAVE_SIGINFO_T_SI_PKEY]: Check decoding of SEGV_PKUERR.
On Wed, Feb 02, 2022 at 03:03:45PM +0000, codecov[bot] wrote:
> The diff coverage is `33.33%`.
| [src/printsiginfo.c](https://codecov.io/gh/strace/strace/pull/210/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=strace#diff-c3JjL3ByaW50c2lnaW5mby5j) | `98.27% <33.33%> (-1.73%)` | ⬇️ |
I wonder whether the new code could be tested?
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commit message: please change
* src/printsiginfo.c: decode si_pkey field.
to
* src/printsiginfo.c (print_si_info) [HAVE_SIGINFO_T_SI_PKEY]: Decode
si_pkey field.
NEWS
Outdated
@@ -12,6 +12,7 @@ Noteworthy changes in release ?.?? (????-??-??) | |||
* Implemented decoding of PR_SET_VMA operation of prctl syscall. | |||
* Updated lists of FAN_*, IORING_*, IOSQE_*, KVM_*, MODULE_INIT_*, TCA_ACT_*, | |||
and *_MAGIC constants. | |||
* Add decoding of si_pkey field in siginfo struct |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make sure each sentence ends with a dot.
If you have a look at the NEWS file, you'll see that almost every
"Improvements" section ends with "Updated lists of constants" line followed by
"Updated lists of ioctl commands" line.
Let's keep this tradition, please add your line before rather than after
these lines.
src/printsiginfo.c
Outdated
case SIGSEGV: case SIGBUS: | ||
tprint_struct_next(); | ||
PRINT_FIELD_PTR(*sip, si_addr); | ||
#ifdef HAVE_SIGINFO_T_SI_PKEY | ||
if (sip->si_signo == SIGSEGV && sip->si_code == SEGV_PKUERR) { | ||
tprint_struct_next(); | ||
PRINT_FIELD_D(*sip, si_pkey); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently, siginfo_t.si_pkey is not the only field that could be printed in case of SIGSEGV or SIGBUS,
so I'd suggest to separate case SIGSEG
and case SIGBUS
, and use a switch
on sip->si_code
instead of an if
statement.
Behavior is different on different platforms. On platforms that have
while on other platforms it will succeed (since these allow read access to I can try to make conditional test, that would be executed only of |
On Thu, Feb 03, 2022 at 12:14:15PM -0800, Slava wrote:
> I wonder whether the new code could be tested?
Behavior is different on different platforms.
That's OK for such platform-specific code.
puts("PKU disabled, so it isn't crashed");
Adding
```
error_msg_and_skip("PKU seems to be disabled");
```
would make the test executable exit with code 77,
this could be used to skip the whole test.
|
* tests/segv_accerr.c: New file. * tests/gen_tests.in (segv_accerr): New test. * tests/Makefile.am (check_PROGRAMS): Add segv_accerr. * tests/.gitignore: Likewise.
Hey, wanted to ask what do you think about tests like this:
and script like this:
I was going to improve it a bit, so it would check cases with different |
I've pushed my changes into another branch (to avoid overwriting your changes), you can check it here. If it's fine I can force push into this branch. |
Hey, I've replaced:
with
which is IMHO a bit simpler and generates a single |
On Sun, Feb 06, 2022 at 07:49:14AM -0800, Slava wrote:
Hey, I've replaced:
```
if (*p)
__asm__ volatile("":::"memory");
```
with
```
__asm__ volatile("":: "r" (*p));
```
which is IMHO a bit simpler and generates a single `mov` instruction (in x86 assembly), unlike trick with if (which produces 2 instructions).
Thanks.
It's clarity that's more important in the test than the number of instructions.
|
On Sat, Feb 05, 2022 at 02:48:31PM -0800, Slava wrote:
I've pushed my changes into another branch (to avoid overwriting your changes), you can check it [here](bacher09@a76c1d3). If it's fine I can force push into this branch.
I'm sorry, but github is not the place where we prefer to discuss things, see README.md
|
On Sat, Feb 05, 2022 at 05:10:02PM -0800, Slava wrote:
Hey, wanted to ask what do you think about tests like this:
```#define _GNU_SOURCE
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/prctl.h>
int main(void)
{
prctl(PR_SET_DUMPABLE, 0);
int *buf = mmap(NULL, getpagesize(), PROT_EXEC,
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
if (buf == MAP_FAILED) {
perror("mmap");
exit(EXIT_FAILURE);
}
asm volatile("":: "r" (*buf));
puts("SIGSEGV did not happen");
return 0;
}
```
and script like this:
```#!/bin/sh
#
# Check -i option.
Really? :)
#
# Copyright (c) 2015-2022 The strace developers.
# All rights reserved.
#
# SPDX-License-Identifier: GPL-2.0-or-later
. "${srcdir=.}/init.sh"
check_prog grep
check_prog sed
if [ ! "/proc/cpuinfo" ]; then
exit 0
fi
if ! grep -E -e '^flags.*pku' /proc/cpuinfo | grep ospke > /dev/null 2>&1; then
exit 0
fi
No, /proc/cpuinfo is not reliable in this respect, there are architectures
like ppc64 and ppc64le that do not have any pku mentioned in
/proc/cpuinfo at all.
# this test works only if pku is present
set -- "../$NAME"
$STRACE -e trace=none "$@" > "$LOG" 2>&1 |:
addr="$(sed -r -n 's/^--- SIGSEGV \{si_signo=SIGSEGV, si_code=SEGV_PKUERR, si_addr=(0x[[:xdigit:]]+),.*/\1/p' $LOG)" &&
[ -n "$addr" ] || dump_log_and_fail_with
cat > "$EXP" << __EOF__
--- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_PKUERR, si_addr=${addr}, si_pkey=1} ---
+++ killed by SIGSEGV +++
__EOF__
match_diff "$LOG" "$EXP"
```
Yet again, this won't play well with other architectures. For example,
on ppc64 and ppc64le for some reason it's si_pkey=2 instead of si_pkey=1,
and on mips and riscv it's SEGV_ACCERR instead of SEGV_PKUERR.
I'd rather stick with the version of this test that does all necessary
checks inside the executable.
|
This adds decoding of
si_pkey
field which is set onSIGSEGV
in caseof memory access violation on some modern CPUs (these have
pku
flag in/proc/cpuinfo
).Here's few sample outputs:
or another case: