[strace/strace] printsiginfo: decode si_pkey field (PR #210)

Dmitry V. Levin notifications at github.com
Sun Feb 6 19:28:19 UTC 2022


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.


-- 
Reply to this email directly or view it on GitHub:
https://github.com/strace/strace/pull/210#issuecomment-1030897867
You are receiving this because you are subscribed to this thread.

Message ID: <strace/strace/pull/210/c1030897867 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20220206/89f78c9a/attachment.htm>


More information about the Strace-devel mailing list