All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 3/5] compat_sys_nanosleep: fix *rmtp/restarts handling
@ 2008-02-01 13:38 Oleg Nesterov
  2008-02-01 13:46 ` Ingo Molnar
  0 siblings, 1 reply; 4+ messages in thread
From: Oleg Nesterov @ 2008-02-01 13:38 UTC (permalink / raw)
  To: Andrew Morton, Thomas Gleixner
  Cc: Alexey Dobriyan, Ingo Molnar, Pavel Emelyanov, Peter Zijlstra,
	Toyo Abe, linux-kernel

COMPLETELY UNTESTED.

Spotted by Pavel Emelyanov and Alexey Dobriyan.

compat_sys_nanosleep() implicitly uses hrtimer_nanosleep_restart(), this can't
work. Make a suitable compat_nanosleep_restart() helper.

Also, set ->addr_limit = KERNEL_DS before doing hrtimer_nanosleep(), this func
was changed by the previous patch and now takes the "__user *" parameter.

Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>

--- MM/kernel/compat.c~3_COMPAT_NANOSLEEP	2008-02-01 14:27:16.000000000 +0300
+++ MM/kernel/compat.c	2008-02-01 14:50:01.000000000 +0300
@@ -40,10 +40,37 @@ int put_compat_timespec(const struct tim
 			__put_user(ts->tv_nsec, &cts->tv_nsec)) ? -EFAULT : 0;
 }
 
+static long compat_nanosleep_restart(struct restart_block *restart)
+{
+	long err;
+	mm_segment_t oldfs;
+	struct timespec tu;
+	struct compat_timespec *rmtp = (struct compat_timespec *)(restart->arg1);
+
+	restart->arg1 = (unsigned long)&tu;
+	oldfs = get_fs();
+	set_fs(KERNEL_DS);
+	err = hrtimer_nanosleep_restart(restart);
+	set_fs(oldfs);
+
+	if (err) {
+		if (rmtp && put_compat_timespec(&tu, rmtp))
+			return -EFAULT;
+
+		if (err == -ERESTART_RESTARTBLOCK) {
+			restart->fn = compat_nanosleep_restart;
+			restart->arg1 = (unsigned long)rmtp;
+		}
+	}
+
+	return err;
+}
+
 asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
 				     struct compat_timespec __user *rmtp)
 {
 	struct timespec tu, rmt;
+	mm_segment_t oldfs;
 	long ret;
 
 	if (get_compat_timespec(&tu, rqtp))
@@ -52,12 +79,23 @@ asmlinkage long compat_sys_nanosleep(str
 	if (!timespec_valid(&tu))
 		return -EINVAL;
 
+	oldfs = get_fs();
+	set_fs(KERNEL_DS);
 	ret = hrtimer_nanosleep(&tu, rmtp ? &rmt : NULL, HRTIMER_MODE_REL,
 				CLOCK_MONOTONIC);
+	set_fs(oldfs);
 
-	if (ret && rmtp) {
-		if (put_compat_timespec(&rmt, rmtp))
+	if (ret) {
+		if (rmtp && put_compat_timespec(&rmt, rmtp))
 			return -EFAULT;
+
+		if (err == -ERESTART_RESTARTBLOCK) {
+			struct restart_block *restart
+				= &current_thread_info()->restart_block;
+
+			restart->fn = compat_nanosleep_restart;
+			restart->arg1 = (unsigned long)rmtp;
+		}
 	}
 
 	return ret;


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

end of thread, other threads:[~2008-02-01 17:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-01 13:38 [PATCH 3/5] compat_sys_nanosleep: fix *rmtp/restarts handling Oleg Nesterov
2008-02-01 13:46 ` Ingo Molnar
2008-02-01 14:12   ` Oleg Nesterov
2008-02-01 17:35     ` Oleg Nesterov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.