<p></p>
On Sat, Feb 05, 2022 at 05:10:02PM -0800, Slava wrote:<br>
> Hey, wanted to ask what do you think about tests like this:<br>
> <br>
> ```#define _GNU_SOURCE<br>
> #include <stdio.h><br>
> #include <unistd.h><br>
> #include <stdlib.h><br>
> #include <sys/mman.h><br>
> #include <sys/prctl.h><br>
> <br>
> int main(void)<br>
> {<br>
>         prctl(PR_SET_DUMPABLE, 0);<br>
>         int *buf = mmap(NULL, getpagesize(), PROT_EXEC,<br>
>                                         MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);<br>
> <br>
>         if (buf == MAP_FAILED) {<br>
>            perror("mmap");<br>
>            exit(EXIT_FAILURE);<br>
>         }<br>
>         asm volatile("":: "r" (*buf));<br>
>         puts("SIGSEGV did not happen");<br>
>         return 0;<br>
> }<br>
> ```<br>
> <br>
> <br>
> and script like this:<br>
> <br>
> ```#!/bin/sh<br>
> #<br>
> # Check -i option.<br>
<br>
Really? :)<br>
<br>
> #<br>
> # Copyright (c) 2015-2022 The strace developers.<br>
> # All rights reserved.<br>
> #<br>
> # SPDX-License-Identifier: GPL-2.0-or-later<br>
> <br>
> . "${srcdir=.}/init.sh"<br>
> <br>
> check_prog grep<br>
> check_prog sed<br>
> <br>
> <br>
> if [ ! "/proc/cpuinfo" ]; then<br>
>         exit 0<br>
> fi<br>
> <br>
> if ! grep -E -e '^flags.*pku' /proc/cpuinfo | grep ospke > /dev/null 2>&1; then<br>
>         exit 0<br>
> fi<br>
<br>
No, /proc/cpuinfo is not reliable in this respect, there are architectures<br>
like ppc64 and ppc64le that do not have any pku mentioned in<br>
/proc/cpuinfo at all.<br>
<br>
> # this test works only if pku is present<br>
> set -- "../$NAME"<br>
> $STRACE -e trace=none "$@" > "$LOG"  2>&1 |:<br>
> addr="$(sed -r -n 's/^--- SIGSEGV \{si_signo=SIGSEGV, si_code=SEGV_PKUERR, si_addr=(0x[[:xdigit:]]+),.*/\1/p' $LOG)" &&<br>
> [ -n "$addr" ] || dump_log_and_fail_with<br>
> cat > "$EXP" << __EOF__<br>
> --- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_PKUERR, si_addr=${addr}, si_pkey=1} ---<br>
> +++ killed by SIGSEGV +++<br>
> __EOF__<br>
> <br>
> match_diff "$LOG" "$EXP"<br>
> ```<br>
<br>
Yet again, this won't play well with other architectures.  For example,<br>
on ppc64 and ppc64le for some reason it's si_pkey=2 instead of si_pkey=1,<br>
and on mips and riscv it's SEGV_ACCERR instead of SEGV_PKUERR.<br>
<br>
I'd rather stick with the version of this test that does all necessary<br>
checks inside the executable.<br>


<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />Reply to this email directly, <a href="https://github.com/strace/strace/pull/210#issuecomment-1030897867">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AOVBTR4NM46QVOJ5CMTT22TUZ3DVHANCNFSM5NL4DJ6Q">unsubscribe</a>.<br />Triage notifications on the go with GitHub Mobile for <a href="https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675">iOS</a> or <a href="https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub">Android</a>.
<br />You are receiving this because you are subscribed to this thread.<img src="https://github.com/notifications/beacon/AOVBTR7Q34BUT7WZ7PEYYP3UZ3DVHA5CNFSM5NL4DJ62YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOHVZEBSY.gif" height="1" width="1" alt="" /><span style="color: transparent; font-size: 0; display: none; visibility: hidden; overflow: hidden; opacity: 0; width: 0; height: 0; max-width: 0; max-height: 0; mso-hide: all">Message ID: <span><strace/strace/pull/210/c1030897867</span><span>@</span><span>github</span><span>.</span><span>com></span></span></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/strace/strace/pull/210#issuecomment-1030897867",
"url": "https://github.com/strace/strace/pull/210#issuecomment-1030897867",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>