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

Slava notifications at github.com
Sun Feb 6 01:10:05 UTC 2022


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.
#
# 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

# 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"
```

I was going to improve it a bit, so it would check cases with different `si_pkey`.

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

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


More information about the Strace-devel mailing list