NetBSD Problem Report #45327

From www@NetBSD.org  Sat Sep  3 15:40:21 2011
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by www.NetBSD.org (Postfix) with ESMTP id 4F58F63C0E2
	for <gnats-bugs@gnats.NetBSD.org>; Sat,  3 Sep 2011 15:40:21 +0000 (UTC)
Message-Id: <20110903154020.63CD963BBA1@www.NetBSD.org>
Date: Sat,  3 Sep 2011 15:40:20 +0000 (UTC)
From: jmcneill@invisible.ca
Reply-To: jmcneill@invisible.ca
To: gnats-bugs@NetBSD.org
Subject: ptrace: siginfo doesn't work with traced processes
X-Send-Pr-Version: www-1.0

>Number:         45327
>Category:       kern
>Synopsis:       ptrace: siginfo doesn't work with traced processes
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Sep 03 15:45:00 +0000 2011
>Closed-Date:    Sun Jun 17 19:46:59 +0000 2012
>Last-Modified:  Sun Jun 17 19:46:59 +0000 2012
>Originator:     Jared McNeill
>Release:        5.99.55
>Organization:
>Environment:
>Description:
When an application is being traced, siginfo data gets lost somewhere. This can be observed when trying to debug an application that uses aio:


$ ./aio
io_callback: sig=23 code=-3
done


$ gdb ./aio
[...]

(gdb) run
Starting program: /home/jmcneill/aio
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
waiting...
io_callback: sig=23 code=32767
assertion "info->si_code == SI_ASYNCIO" failed: file "aio.c", line 20, function "io_callback"

Program received signal SIGABRT, Aborted.
0xabe12df7 in aio_read () from /usr/lib/librt.so.0

>How-To-Repeat:
#include <sys/types.h>
#include <sys/signal.h>

#include <aio.h>
#include <assert.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

static struct aiocb aio;
static uint8_t data[64];

int done = 0;

void
io_callback(int sig, siginfo_t *info, void *priv)
{
        printf("%s: sig=%d code=%d\n", __func__, sig, info->si_code);
        assert(info->si_code == SI_ASYNCIO);
        done = 1;
}


int
main(void)
{
        struct sigaction sa;
        int fd, error;

        fd = open("/dev/zero", O_RDONLY);
        assert(fd != -1);

        memset(&sa, 0, sizeof(sa));
        sigemptyset(&sa.sa_mask);
        sa.sa_flags = SA_RESTART|SA_SIGINFO;
        sa.sa_sigaction = io_callback;
        error = sigaction(SIGIO, &sa, NULL);
        assert(error != -1);

        memset(&aio, 0, sizeof(aio));
        aio.aio_fildes = fd;
        aio.aio_buf = data;
        aio.aio_nbytes = sizeof(data);
        aio.aio_offset = 0;
        aio.aio_sigevent.sigev_notify = SIGEV_SIGNAL;
        aio.aio_sigevent.sigev_signo = SIGIO;
        aio.aio_sigevent.sigev_value.sival_ptr = NULL;

        error = aio_read(&aio);
        assert(error != -1);

        while (done == 0) {
                printf("waiting...\n");
                sleep(1);
        }
        printf("done\n");

        close(fd);

        return 0;
}

>Fix:

>Release-Note:

>Audit-Trail:
From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/45327 CVS commit: src/sys/kern
Date: Sat, 3 Sep 2011 15:33:40 -0400

 Module Name:	src
 Committed By:	christos
 Date:		Sat Sep  3 19:33:40 UTC 2011

 Modified Files:
 	src/sys/kern: kern_sig.c

 Log Message:
 PR/45327: Jared McNeill: ptrace: siginfo doesn't work with traced processes
 When saving the signal in p->p_xstat, clear it from the pending mask, but
 don't remove it from the siginfo queue, so that next time the debugger
 delivers it, the original information is found.
 When posting a signal from the debugger l->l_sigpendset is not set, so we
 use the process pending signal and add it back to the process pending set.


 To generate a diff of this commit:
 cvs rdiff -u -r1.312 -r1.313 src/sys/kern/kern_sig.c

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

From: "Jared D. McNeill" <jmcneill@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/45327 CVS commit: src/sys/arch/usermode/dev
Date: Sat, 3 Sep 2011 20:02:34 +0000

 Module Name:	src
 Committed By:	jmcneill
 Date:		Sat Sep  3 20:02:34 UTC 2011

 Modified Files:
 	src/sys/arch/usermode/dev: ld_thunkbus.c

 Log Message:
 Now that pr45327 is fixed, remove BROKEN_SIGINFO code.


 To generate a diff of this commit:
 cvs rdiff -u -r1.8 -r1.9 src/sys/arch/usermode/dev/ld_thunkbus.c

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

State-Changed-From-To: open->pending-pullups
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Sat, 05 Nov 2011 16:33:01 +0000
State-Changed-Why:
this is or should be part of pullup-5 #1668


From: "Manuel Bouyer" <bouyer@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/45327 CVS commit: [netbsd-5] src/sys
Date: Sat, 4 Feb 2012 16:58:00 +0000

 Module Name:	src
 Committed By:	bouyer
 Date:		Sat Feb  4 16:58:00 UTC 2012

 Modified Files:
 	src/sys/arch/amd64/amd64 [netbsd-5]: syscall.c
 	src/sys/arch/i386/i386 [netbsd-5]: syscall.c trap.c
 	src/sys/kern [netbsd-5]: kern_sig.c kern_sleepq.c kern_subr.c
 	    sys_process.c
 	src/sys/secmodel/bsd44 [netbsd-5]: secmodel_bsd44_suser.c
 	src/sys/sys [netbsd-5]: proc.h ptrace.h

 Log Message:
 Apply patch, requested by jmcneill in ticket #1668:
 	sys/arch/amd64/amd64/syscall.c			patch
 	sys/arch/i386/i386/syscall.c			patch
 	sys/arch/i386/i386/trap.c			patch
 	sys/kern/kern_sig.c				patch
 	sys/kern/kern_sleepq.c				patch
 	sys/kern/kern_subr.c				patch
 	sys/kern/sys_process.c				patch
 	sys/secmodel/bsd44/secmodel_bsd44_suser.c	patch
 	sys/sys/proc.h					patch
 	sys/sys/ptrace.h				patch

 arch/i386/i386/machdep.c, arch/amd64/amd64/machdep.c (from
 arch/x86/x86/machdep.c) by christos:
 Remove code that was used to avoid register spills. setcontext(2) can change
 the registers, so re-fetching will produce the wrong result for trace_exit().
 arch/i386/i386/trap.c by reinoud:
 Fix the illegal instruction return address. It was using the value of the
 cpu's %cr2 register but thats not valid:

 CR2 Contains a value called Page Fault Linear Address (PFLA). When a page
 fault occurs, the address the program attempted to access is stored in the CR2
 register.

 And this is thus NOT the illegal instruction address!
 kern/kern_sig.c by christos:
 PR kern/45327: Jared McNeill: ptrace: siginfo doesn't work with traced processes
 When saving the signal in p->p_xstat, clear it from the pending mask, but
 don't remove it from the siginfo queue, so that next time the debugger
 delivers it, the original information is found.
 When posting a signal from the debugger l->l_sigpendset is not set, so we
 use the process pending signal and add it back to the process pending set.
 Split sigget into sigget() and siggetinfo(). When a signal comes from the
 debugger (l->l_sigpendset == NULL), using siggetinfo() try to fetch the
 siginfo information from l->l_sigpend and then from p->p_sigpend if it
 was not found. This allows us to pass siginfo information for traps from
 the debugger.
 don't delete signal from the debugger.
 kern/kern_sleepq.c by christos:
 PR kern/40594: Antti Kantee: Don't call issignal() here to determine what errno
 to set for the interrupted syscall, because issignal() will consume the signal
 and it will not be delivered to the process afterwards. Instead call
 sigispending() (which now returns the first pending signal) and does not
 consume the signal.
 We need to process SA_STOP signals immediately, and not deliver them to
 the process. Instead of re-structuring the code to do that, call issignal()
 like before in that case. (tail -F /file^Zfg should not get interrupted).
 kern/kern_subr.c by jmcneill, christos:
 PR kern/45312: ptrace: PT_SETREGS can't alter system calls

 Add a new PT_SYSCALLEMU request that cancels the current syscall, for
 use with PT_SYSCALL.
 For PT_SYSCALLEMU, no need to stop again on syscall exit.
 ifdef unused variable with -UPTRACE

 kern/sys_process.c, sys/proc.h, sys/ptrace.h, secmodel/bsd44/secmodel_bsd44_suser.c by jmcneill, christos:
 PR kern/43681: PT_SYSCALL appears to be broken

 sys_ptrace: For PT_CONTINUE/PT_SYSCALL/PT_DETACH, modify the p_trace_enabled
 flag of the target process, not the calling process.
 Process the signal now, otherwise calling issignal() and ignoring
 the return will lose the signal if it came from the debugger
 (issignal() clears p->p_xstat)
 PR kern/45312: ptrace: PT_SETREGS can't alter system calls

 Add a new PT_SYSCALLEMU request that cancels the current syscall, for
 use with PT_SYSCALL.
 PR kern/45330: ptrace: signals can alter syscall return values

 process_stoptrace: defer signal processing to userret, ok christos@


 To generate a diff of this commit:
 cvs rdiff -u -r1.44 -r1.44.4.1 src/sys/arch/amd64/amd64/syscall.c
 cvs rdiff -u -r1.57 -r1.57.4.1 src/sys/arch/i386/i386/syscall.c
 cvs rdiff -u -r1.241.4.3 -r1.241.4.4 src/sys/arch/i386/i386/trap.c
 cvs rdiff -u -r1.289.4.6 -r1.289.4.7 src/sys/kern/kern_sig.c
 cvs rdiff -u -r1.35 -r1.35.4.1 src/sys/kern/kern_sleepq.c
 cvs rdiff -u -r1.192.4.1 -r1.192.4.2 src/sys/kern/kern_subr.c
 cvs rdiff -u -r1.143.4.1 -r1.143.4.2 src/sys/kern/sys_process.c
 cvs rdiff -u -r1.59 -r1.59.4.1 src/sys/secmodel/bsd44/secmodel_bsd44_suser.c
 cvs rdiff -u -r1.282 -r1.282.4.1 src/sys/sys/proc.h
 cvs rdiff -u -r1.40 -r1.40.20.1 src/sys/sys/ptrace.h

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

State-Changed-From-To: pending-pullups->closed
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Sun, 17 Jun 2012 19:46:59 +0000
State-Changed-Why:
pullup was done in february and I've been behind on cleaning up


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.