NetBSD Problem Report #56940

From www@netbsd.org  Mon Jul 25 22:30:49 2022
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 588481A921F
	for <gnats-bugs@gnats.NetBSD.org>; Mon, 25 Jul 2022 22:30:49 +0000 (UTC)
Message-Id: <20220725223048.477AD1A9239@mollari.NetBSD.org>
Date: Mon, 25 Jul 2022 22:30:48 +0000 (UTC)
From: campbell+netbsd@mumble.net
Reply-To: campbell+netbsd@mumble.net
To: gnats-bugs@NetBSD.org
Subject: libexecinfo fails to trace stack through signal trampoline for SIGSEGV call to null function pointer
X-Send-Pr-Version: www-1.0

>Number:         56940
>Category:       lib
>Synopsis:       libexecinfo fails to trace stack through signal trampoline for SIGSEGV call to null function pointer
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Jul 25 22:35:00 +0000 2022
>Last-Modified:  Mon Jul 25 22:40:01 +0000 2022
>Originator:     Taylor R Campbell
>Release:        current
>Organization:
El Fundacion NetBSD
>Environment:
being consumed by an insatiable thirst for oil
>Description:
When invoked from a signal handler for the SIGSEGV delivered due to a call to a null function pointer, the backtrace(3) functions of libexecinfo bottom out at __sigtramp_siginfo_2 or equivalent, and fail to yield return addresses for the call site of the null function pointer or its callers.

The information is available -- for example, on amd64, r15 of the signal trampoline frame points to a ucontext_t structure with process state where rsp[0] holds the return address and &rsp[1] is where parent frame lives.  But libunwind fails to find this information, and so the stack trace ends at the signal trampoline.
>How-To-Repeat:
#include <sys/cdefs.h>

#include <err.h>
#include <execinfo.h>
#include <setjmp.h>
#include <signal.h>
#include <stddef.h>
#include <stdio.h>

void (*f)(void);
jmp_buf env;
void *stack[64];
size_t stackdepth;
char **symbols;

void
sigsegv(int signo)
{

	(void)signo;

	stackdepth = backtrace(stack, __arraycount(stack));
	longjmp(env, 1);
}

int
main(void)
{
	size_t i;

	if (signal(SIGSEGV, &sigsegv) == SIG_ERR)
		err(1, "signal(SIGSEGV)");
	if (setjmp(env) == 0)
		(*f)();
	symbols = backtrace_symbols(stack, stackdepth);
	if (symbols == NULL)
		err(1, "backtrace_symbols");
	for (i = 0; i < stackdepth; i++)
		printf("%s\n", symbols[i]);
	fflush(stdout);
	return ferror(stdout);
}

>Fix:
Yes, please!

>Audit-Trail:
From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/56940 CVS commit: src/tests/lib/libexecinfo
Date: Mon, 25 Jul 2022 22:37:37 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Mon Jul 25 22:37:37 UTC 2022

 Modified Files:
 	src/tests/lib/libexecinfo: t_sig_backtrace.c

 Log Message:
 execinfo(3): Mark sig_backtrace_jump test as xfail.

 PR lib/56940


 To generate a diff of this commit:
 cvs rdiff -u -r1.4 -r1.5 src/tests/lib/libexecinfo/t_sig_backtrace.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.