[PATCH] tests/pc: try to avoid creating a coredump

Dmitry V. Levin ldv at altlinux.org
Mon Oct 11 23:42:54 UTC 2021


On Wed, Oct 06, 2021 at 08:29:27PM +0200, Renaud Métrich wrote:
> The small patch attached tries to avoid having the SEGV signal create a 
> coredump which is then stored in /var/lib/systemd/coredump/ directory on 
> systemd enabled systems.
> 
> Also available as a PR: https://github.com/strace/strace/pull/196
> 
> The code coverage indicates a false positive since the patch only deals 
> with tests/ directory, not src/, hence IMHO it's not possible that 
> src/pidns.c gets affected or I'm missing something here.
> 
> 
> Renaud.
> 

> From f4050e08e6abd406ad6cdef912dc962f31686de2 Mon Sep 17 00:00:00 2001
> From: =?UTF-8?q?Renaud=20M=C3=A9trich?= <rmetrich at redhat.com>
> Date: Wed, 6 Oct 2021 16:07:15 +0200
> Subject: [PATCH] tests/pc: avoid program from creating a coredump
> 
> ---
>  tests/pc.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/tests/pc.c b/tests/pc.c
> index 342169f5d..0ffefa771 100644
> --- a/tests/pc.c
> +++ b/tests/pc.c
> @@ -14,6 +14,8 @@
>  #include <sys/mman.h>
>  #include <sys/wait.h>
>  #include <sys/sendfile.h>
> +#include <sys/time.h>
> +#include <sys/resource.h>
>  
>  int main(void)
>  {
> @@ -27,6 +29,10 @@ int main(void)
>  	error_msg_and_skip("s390: si_addr is unreliable");
>  #endif
>  
> +	/* Avoid creating core dumps for real, if possible */
> +	struct rlimit rlim = { 0 };
> +	(void) setrlimit(RLIMIT_CORE, &rlim);
> +
>  	/* write instruction pointer length to the log */
>  	assert(syscall(__NR_write, -1, (void *) 8UL, 2 * sizeof(void *)) < 0);
>  

I don't think <sys/time.h> is needed here, and this still allows dumping
core e.g. to pipes.  Wouldn't we better off clearing the dumpable attribute
by invoking PR_SET_DUMPABLE right before raising SIGSEGV?


-- 
ldv


More information about the Strace-devel mailing list