Bug 106109

Summary: amd64: si_addr is not set when sending a signal
Product: Base System Reporter: NIIMI Satoshi <sa2c>
Component: amd64Assignee: freebsd-amd64 (Nobody) <amd64>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: Unspecified   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
amd64-machdep.diff none

Description NIIMI Satoshi 2006-12-01 04:20:03 UTC
POSIX style signal handers expect that the faulting address is stored
in si_addr member of siginfo_t.

But the address is passed to signal handler only as non-portable
fourth argument on FreeBSD/amd64.

How-To-Repeat: Following program produces
i386: &main=0x80485e8, si_addr=0x80485e8, fourth_arg=0x0
amd64: &main=0x400780, si_addr=0x0, fourth_arg=0x400780

#include <signal.h>
#include <stdio.h>
#include <stdlib.h>

int main();

void
handler(int sig, siginfo_t *siginfo, void *context, void *addr)
{
	fprintf(stderr, "&main=%p, si_addr=%p, fourth_arg=%p\n",
		&main, siginfo->si_addr, addr);
	exit(1);
}

int
main()
{
	struct sigaction sa;

	sa.sa_flags = SA_SIGINFO;
	sigemptyset(&sa.sa_mask);
	sa.sa_sigaction = (void (*)(int, siginfo_t *, void *))handler;

	sigaction(SIGBUS, &sa, NULL);
	sigaction(SIGSEGV, &sa, NULL);
	*(int *)main = 1;

	return 0;
}
Comment 1 David Xu freebsd_committer freebsd_triage 2006-12-01 05:21:09 UTC
On Friday 01 December 2006 12:11, NIIMI Satoshi wrote:
> >Number:         106109
> >Category:       amd64
> >Synopsis:       amd64: si_addr is not set when sending a signal
> >Confidential:   no
> >Severity:       serious
> >Priority:       low
> >Responsible:    freebsd-amd64
> >State:          open
> >Quarter:
> >Keywords:
> >Date-Required:
> >Class:          sw-bug
> >Submitter-Id:   current-users
> >Arrival-Date:   Fri Dec 01 04:20:03 GMT 2006
> >Closed-Date:
> >Last-Modified:
> >Originator:     NIIMI Satoshi
> >Release:        FreeBSD 6.2-RC1 i386
> >Organization:
> >Environment:
>
> System: FreeBSD berkeley.l.sa2c.net 6.2-RC1 FreeBSD 6.2-RC1 #0: Thu Nov 30
> 10:03:58 JST 2006 root@berkeley.l.sa2c.net:/usr/obj/usr/src/sys/GENERIC
> i386
>
> >Description:
>
> POSIX style signal handers expect that the faulting address is stored
> in si_addr member of siginfo_t.
>
> But the address is passed to signal handler only as non-portable
> fourth argument on FreeBSD/amd64.
>
> >How-To-Repeat:
>
> Following program produces
> i386: &main=0x80485e8, si_addr=0x80485e8, fourth_arg=0x0
> amd64: &main=0x400780, si_addr=0x0, fourth_arg=0x400780
>
> #include <signal.h>
> #include <stdio.h>
> #include <stdlib.h>
>
> int main();
>
> void
> handler(int sig, siginfo_t *siginfo, void *context, void *addr)
> {
> 	fprintf(stderr, "&main=%p, si_addr=%p, fourth_arg=%p\n",
> 		&main, siginfo->si_addr, addr);
> 	exit(1);
> }
>
> int
> main()
> {
> 	struct sigaction sa;
>
> 	sa.sa_flags = SA_SIGINFO;
> 	sigemptyset(&sa.sa_mask);
> 	sa.sa_sigaction = (void (*)(int, siginfo_t *, void *))handler;
>
> 	sigaction(SIGBUS, &sa, NULL);
> 	sigaction(SIGSEGV, &sa, NULL);
> 	*(int *)main = 1;
>
> 	return 0;
> }
>
> >Fix:
>
> --- amd64-machdep.diff begins here ---
> Index: machdep.c
> ===================================================================
> RCS file: /home/ncvs/src/sys/amd64/amd64/machdep.c,v
> retrieving revision 1.664
> diff -u -r1.664 machdep.c
> --- machdep.c	19 Nov 2006 20:54:57 -0000	1.664
> +++ machdep.c	1 Dec 2006 03:36:54 -0000
> @@ -304,6 +304,7 @@
>  		/* Fill in POSIX parts */
>  		sf.sf_si = ksi->ksi_info;
>  		sf.sf_si.si_signo = sig; /* maybe a translated signal */
> +		sf.sf_si.si_addr = ksi->ksi_addr;
>  		regs->tf_rcx = (register_t)ksi->ksi_addr; /* arg 4 in %rcx */
>  	} else {
>  		/* Old FreeBSD-style arguments. */
> --- amd64-machdep.diff ends here ---

I reviewed the sendsig() in RELENG_6 for AMD64, the si_addr is not set,
but is set in i386 version of sendsig(), the originator's patch is wrong,
it copied some code from HEAD which is not valid for RELENG_6, the
HEAD has fully working siginfo_t in kernel while RELENG_6 does not, 
the patch should be changed to:

> +		sf.sf_si.si_addr = regs->tf_addr;


David Xu
Comment 2 dfilter service freebsd_committer freebsd_triage 2006-12-01 08:34:54 UTC
davidxu     2006-12-01 08:34:39 UTC

  FreeBSD src repository

  Modified files:        (Branch: RELENG_6)
    sys/amd64/amd64      machdep.c 
  Log:
  MFC: Store fault address into POSIX siginfo.
  
  PR: amd64/106109
  
  Revision    Changes    Path
  1.638.2.11  +1 -0      src/sys/amd64/amd64/machdep.c
_______________________________________________
cvs-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/cvs-all
To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
Comment 3 David Xu freebsd_committer freebsd_triage 2006-12-01 08:35:19 UTC
State Changed
From-To: open->patched

Patch is applied.
Comment 4 NIIMI Satoshi 2007-05-06 03:14:22 UTC
It seems that my mail on 2006-12-02 was missed.

I confirmed that the problem was fixed.  Please close this PR.

Thanks,
-- 
NIIMI Satoshi
Comment 5 Mark Linimon freebsd_committer freebsd_triage 2007-05-06 04:42:59 UTC
State Changed
From-To: patched->closed

Submitter notes that this problem is now solved.