public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
To: Linux Kernel <linux-kernel@vger.kernel.org>,
	Linus Torvalds <torvalds@osdl.org>,
	Andrew Morton <akpm@linux-foundation.org>
Cc: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Subject: [BUG] ptraced process waiting on syscall may return kernel internal errnos
Date: Wed, 06 Jun 2007 14:47:54 +0900	[thread overview]
Message-ID: <87hcplvdkl.wl%takeuchi_satoru@jp.fujitsu.com> (raw)

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);
}

             reply	other threads:[~2007-06-06  5:47 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-06  5:47 Satoru Takeuchi [this message]
2007-06-06 10:59 ` [BUG] ptraced process waiting on syscall may return kernel internal errnos 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87hcplvdkl.wl%takeuchi_satoru@jp.fujitsu.com \
    --to=takeuchi_satoru@jp.fujitsu.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@osdl.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox