public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Denys Vlasenko <dvlasenk@redhat.com>
To: Andy Lutomirski <luto@amacapital.net>
Cc: Ingo Molnar <mingo@kernel.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	"Krzysztof A. Sobiecki" <sobkas@gmail.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Borislav Petkov <bp@alien8.de>, "H. Peter Anvin" <hpa@zytor.com>,
	Oleg Nesterov <oleg@redhat.com>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Alexei Starovoitov <ast@plumgrid.com>,
	Will Drewry <wad@chromium.org>, Kees Cook <keescook@chromium.org>,
	X86 ML <x86@kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 2/3] x86/asm/entry/32: Remove most of SYSCALL32 code, part 1
Date: Mon, 27 Jul 2015 21:19:15 +0200	[thread overview]
Message-ID: <55B68433.4040706@redhat.com> (raw)
In-Reply-To: <CALCETrXNN8aFHw1DX+qN20ovx8irVSd-LMpX1Jjr5J2ZT9vnzg@mail.gmail.com>

On 07/24/2015 07:50 PM, Andy Lutomirski wrote:
> On Fri, Jul 24, 2015 at 6:47 AM, Denys Vlasenko <dvlasenk@redhat.com> wrote:
>> SYSCALL32 code is nearly identical to SYSCALL32, except for initial
>> section. Merge them.
>>
>> The removal is split into two parts, to make review eaiser. This is part 1.
>>
>> auditsys_entry_common and auditsys_exit macros are indented one more tab without
>> any changes. This prevents diff from becoming unreadable.
>> They will be removed in part 2.
> 
> I need to read these more closely, which is, at present, exceeding my
> ability to look at asm.  (See the big NMI thread.)  I'll look soon.
> 
> Meanwhile, this code is incredibly fragile wrt syscall restart.
> (Syscall restart on compat is really weird.)  Do we have a decent test
> for it?

How about this? (Feel free to expand, this is a first cut only).

$ ./test_restart
[RUN]	Test restart of read()
[OK]	Restart of read() worked
[RUN]	Test restart of recv()
[OK]	Restart of recv() worked





#undef _GNU_SOURCE
#define _GNU_SOURCE 1
#undef __USE_GNU
#define __USE_GNU 1
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <sys/time.h>
//#include <sys/ptrace.h>
#include <sys/wait.h>

void signal_SA_RESTART_empty_mask(int sig, void (*handler)(int))
{
	struct sigaction sa;
	memset(&sa, 0, sizeof(sa));
	sigemptyset(&sa.sa_mask);
	sa.sa_flags = SA_RESTART;
	sa.sa_handler = handler;
	sigaction(sig, &sa, NULL);
}

int make_writer(void)
{
	int pid, fd[2];
	if (pipe(fd)) exit(1);
	pid = fork();
	if (pid < 0) exit(1);
	if (pid == 0) {
		/* child */
		usleep(50*1000);
		write(fd[1], "123456789", 10);
		exit(0);
	}
	close(fd[1]);
	return fd[0];
}

int make_sender(void)
{
	int pid, fd[2];
	if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd)) exit(1);
	pid = fork();
	if (pid < 0) exit(1);
	if (pid == 0) {
		/* child */
		usleep(50*1000);
		write(fd[1], "123456789", 10);
		exit(0);
	}
	close(fd[1]);
	return fd[0];
}

int got_sig;

void sighandler(int sig)
{
	got_sig = 1;
}

void prepare(char buf[10])
{
	got_sig = 0;
	strcpy(buf, "qwertyuio");
	ualarm(25*1000, 0);
}

int check(const char *test_type, int len, char buf[10])
{
	int err = 0;
	if (len != 10 || strcmp(buf, "123456789") != 0) {
		printf("[FAIL]\tRestarted %s() returns wrong result\n", test_type);
		err = 1;
	}
	if (!got_sig) {
		printf("[FAIL]\tSignal was expected on %s read() but wasn't seen\n", test_type);
		err = 1;
	}
	if (!err)
		printf("[OK]\tRestart of %s() worked\n", test_type);
	return err;
}

int main(int argc, char **argv, char **envp)
{
	char buf[10];
	int fd;
	int len;
	int err;

	signal_SA_RESTART_empty_mask(SIGALRM, sighandler);

	printf("[RUN]\tTest restart of read()\n");
	fd = make_writer();
	prepare(buf);
	len = read(fd, buf, 10);
	err = check("read", len, buf);
	close(fd);

	printf("[RUN]\tTest restart of recv()\n");
	fd = make_sender();
	prepare(buf);
	len = recv(fd, buf, 10, MSG_PEEK);
	err |= check("recv", len, buf);
	if (!err) {
		/* Check that restarted recv() indeed had MSG_PEEK:
		 * i.e. that it did not consume the data.
		 */
		strcpy(buf, "qwertyuio");
		len = recv(fd, buf, 10, 0);
		if (len != 10 || strcmp(buf, "123456789") != 0) {
			printf("[FAIL]\tRestarted %s() had no MSG_PEEK flag\n", "recv");
			err = 1;
		}
	}
	close(fd);

	return err;
}

  parent reply	other threads:[~2015-07-27 19:19 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-24 13:47 [PATCH 1/3] x86/asm/entry/32: Massage SYSENTER32 fast path to be nearly identical to SYSCALL32 Denys Vlasenko
2015-07-24 13:47 ` [PATCH 2/3] x86/asm/entry/32: Remove most of SYSCALL32 code, part 1 Denys Vlasenko
2015-07-24 17:50   ` Andy Lutomirski
2015-07-25 18:36     ` Denys Vlasenko
2015-07-25 19:33       ` Andy Lutomirski
2015-07-27 19:19     ` Denys Vlasenko [this message]
2015-07-27 19:26       ` Andy Lutomirski
2015-08-25  7:19         ` Andy Lutomirski
2015-07-27 16:05   ` Ingo Molnar
2015-07-24 13:47 ` [PATCH 3/3] x86/asm/entry/32: Remove most of SYSCALL32 code, part 2 Denys Vlasenko
2015-07-24 17:37 ` [PATCH 1/3] x86/asm/entry/32: Massage SYSENTER32 fast path to be nearly identical to SYSCALL32 Andy Lutomirski

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=55B68433.4040706@redhat.com \
    --to=dvlasenk@redhat.com \
    --cc=ast@plumgrid.com \
    --cc=bp@alien8.de \
    --cc=fweisbec@gmail.com \
    --cc=hpa@zytor.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=mingo@kernel.org \
    --cc=oleg@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=sobkas@gmail.com \
    --cc=torvalds@linux-foundation.org \
    --cc=wad@chromium.org \
    --cc=x86@kernel.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