rt ptracer can monopolize CPU (was: Cpu-Hotplug and Real-Time)

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Ingo Molnar <mingo@...>, Roland McGrath <roland@...>
Cc: Srivatsa Vaddagiri <vatsa@...>, <linux-kernel@...>, Dipankar Sarma <dipankar@...>, Paul E McKenney <paulmck@...>, Gautham R Shenoy <ego@...>
Date: Thursday, August 9, 2007 - 1:03 pm

On 08/07, Oleg Nesterov wrote:

Even simpler.

#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <sys/ptrace.h>
#include <sys/wait.h>
#define	__USE_GNU
#include <sched.h>

void die(const char *msg)
{
	printf("ERR!! %s: %m\n", msg);
        kill(0, SIGKILL);
}

void set_cpu(int cpu)
{
	unsigned cpuval = 1 << cpu;
	if (sched_setaffinity(0, 4, (void*)&cpuval) < 0)
		die("setaffinity");
}

// __wake_up_parent() does SYNC wake up, we need a handler to provoke
// signal_wake_up().
// otherwise ptrace_stop() is not preempted after read_unlock(tasklist).
static void sigchld(int sig)
{
}

int main(void)
{
	set_cpu(0);

	int pid = fork();
	if (!pid)
		for (;;)
			;

	struct sched_param sp = { 99 };
	if (sched_setscheduler(0, SCHED_FIFO, &sp))
		die("setscheduler");

	signal(SIGCHLD, sigchld);

	if (ptrace(PTRACE_ATTACH, pid, NULL, NULL))
		die("attach");

	wait(NULL);

	if (ptrace(PTRACE_DETACH, pid, NULL, NULL))
		die("detach");

	kill(pid, SIGKILL);

	return 0;
}

Locks CPU 0. Not a security problem, needs CAP_SYS_NICE and the task
could be reniced and killed, but still not good.

ptracee does ptrace_stop()->do_notify_parent_cldstop(), ptracer preempts
the child before it calls schedule(), ptrace(PTRACE_DETACH) goes to
wait_task_inactive() and yields forever.

Can we just replace yield() with schedule_timeout_uninterruptible(1) ?
wait_task_inactive() has no time-critical callers, and as it currently
used "on_rq" case is really unlikely.

Oleg.

-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Cpu-Hotplug and Real-Time, Gautham R Shenoy, (Tue Aug 7, 9:12 am)
Re: Cpu-Hotplug and Real-Time, Oleg Nesterov, (Tue Aug 7, 11:13 am)
rt ptracer can monopolize CPU (was: Cpu-Hotplug and Real-Time), Oleg Nesterov, (Thu Aug 9, 1:03 pm)
Re: Cpu-Hotplug and Real-Time, Venki Pallipadi, (Tue Aug 7, 1:33 pm)
Re: Cpu-Hotplug and Real-Time, Oleg Nesterov, (Tue Aug 7, 2:36 pm)