public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [BUG] ptraced process waiting on syscall may return kernel internal errnos
@ 2007-06-06  5:47 Satoru Takeuchi
  2007-06-06 10:59 ` Roland McGrath
  0 siblings, 1 reply; 27+ messages in thread
From: Satoru Takeuchi @ 2007-06-06  5:47 UTC (permalink / raw)
  To: Linux Kernel, Linus Torvalds, Andrew Morton; +Cc: Satoru Takeuchi

Hi,

If there is a multithread process which is waiting on restartable syscall
and ptraced, some threads may return from syscalls with a errno which should
never be seen by user programs when they receive SIGSTOP. It is not a rare
case beacuse strace send SIGSTOP to attached process on its exit (e.g. on
receiving SIGINT from terminal).

I found this problem on 2.6.22-rc3 and I also confirmed 2.6.22-rc4 has same
problem. Probably this bug is in generic signal code because this problem
occurs on both i386 box and ia64 box.

This bug is very easy to recreate and I don't know whether or not the problem
has some relation with the following bug which reported recently by Benjamin
Herrenschmidt.

	http://lkml.org/lkml/2007/6/4/468

I executed this recreate program on 2.6.22-rc4 with the following Linus's
patch and this bug also occured.

	http://lkml.org/lkml/2007/6/4/471

For more details, please refer to the attached recreate program.



BTW, I found one more strace related bug. I'll report it soon...

Thanks,
Satoru

-------------------------------------------------------------------------------
/*
 * recreate-signal-mt-ptrace-bug-pipe - recreate a signal bug.
 *
 * ---------------------------------------------------------------------------
 * 
 * Problem
 * =======
 *
 * If there is a multithread process which is in restartable syscall and
 * ptraced, some threads may return from syscalls with a errno which should
 * never be seen by user programs when they receive SIGSTOP. It is not a
 * rare case beacuse strace send SIGSTOP to attached process on its exit.
 *
 * How to recreate
 * ===============
 *
 * 1. run this program
 * 
 *    $ ./recreate-signal-mt-ptrace-bug-pipe &
 * 
 * 2. run strace and attach this program
 *
 *    $ strace -f -p $!
 *
 * 3. C-c on terminal (*1)
 *
 * (*1) Directly send SIGSTOP to ./recreate-signal-mt-ptrace-bug-pipe is
 *      also OK
 *
 * Expected Result
 * ===============
 *
 * All threads of this program was detached safely
 * 
 * Actual Result
 * =============
 *
 * Some threads may return from read() with ERESTARTSYS and print the
 * following message.
 *
 *	read() failed with errno 512
 * 
 * Note
 * ====
 *
 * This program can't always recreate a problem. However recreate
 * possibility is very high.
 * 
 *----------------------------------------------------------------------
 * 
 * Copyright 2007 Satoru Takeuchi <takeuchi_satoru@jp.futjisu.com>
 *
 * This software may be used and distributed according to the terms
 * of the GNU General Public License, incorporated herein by reference.
 * 
 */

#include <unistd.h>
#include <sys/types.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <err.h>

static int fd[2];

void *thread_fn(void *arg)
{
	char c;

	if (read(fd[0], &c, sizeof(char)) < 0)
		err(EXIT_FAILURE, "read() failed with errno %d\n", errno);
	
	return NULL;
}

#define NTHREAD 64

int main(int argc, char **argv)
{
	pthread_t t[NTHREAD];
	int i;

	if (pipe(fd) < 0)
		err(EXIT_FAILURE, "pipe() failed");

	for (i = 0; i < NTHREAD; i++)
		if (pthread_create(&t[i], NULL, thread_fn, NULL)) {
			warn("pthread_create() failed\n");
			exit(EXIT_FAILURE);
		}

	for (i = 0; i < NTHREAD; i++)
		if (!pthread_join(t[i], NULL))
			warn("pthread_join() failed");

	exit(EXIT_SUCCESS);
}

^ permalink raw reply	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2007-06-15 21:41 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-06-06  5:47 [BUG] ptraced process waiting on syscall may return kernel internal errnos Satoru Takeuchi
2007-06-06 10:59 ` Roland McGrath
2007-06-06 15:35   ` Linus Torvalds
2007-06-06 23:07     ` Paul Mackerras
2007-06-07  3:25     ` Benjamin Herrenschmidt
2007-06-07  3:27     ` Benjamin Herrenschmidt
2007-06-07 11:33     ` Satoru Takeuchi
2007-06-07 15:54       ` Linus Torvalds
2007-06-07 22:24         ` Benjamin Herrenschmidt
2007-06-08  3:18           ` Linus Torvalds
2007-06-08  5:30             ` Benjamin Herrenschmidt
2007-06-11 22:16             ` Benjamin Herrenschmidt
2007-06-08  3:07         ` Satoru Takeuchi
2007-06-13 22:06     ` Roland McGrath
2007-06-07  3:20   ` Benjamin Herrenschmidt
2007-06-13 15:15   ` Oleg Nesterov
2007-06-13 22:36     ` Benjamin Herrenschmidt
2007-06-13 23:01       ` Roland McGrath
2007-06-13 23:18         ` Benjamin Herrenschmidt
2007-06-14  0:02           ` Roland McGrath
2007-06-13 22:53     ` Roland McGrath
2007-06-14 12:26     ` Rafael J. Wysocki
2007-06-14 12:58       ` Oleg Nesterov
2007-06-14 23:35         ` Rafael J. Wysocki
2007-06-15 11:31           ` Oleg Nesterov
2007-06-15 21:48             ` Rafael J. Wysocki
2007-06-15  0:06         ` Benjamin Herrenschmidt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox