setitimer : Return -EFAULT if the user pointer "value" is NULL
PATCH 1/1 setitimer : Return -EFAULT if the user pointer "value" is NULL
Return -EFAULT if user pointer "value" is NULL.
In the current timer implementation
setitimer (which, NULL, NULL)
is equal to
timer.it_value.tv_sec = 0;
timer.it_value.tv_usec = 0;
timer.it_interval.tv_sec = 0;
timer.it_interval.tv_usec = 0;
setitimer (which, &timer, NULL);
setitimer man page says "The function setitimer() sets the specified timer to the value in new_value".
If the new_value is NULL, kernel should not set timer with tv_sec = 0 and tv_usec = 0, instead return -EFAULT.
--- kernel/itimer.c | 17 ++++++++--------- 1 files changed, 8 insertions(+), 9 deletions(-)
kernel/itimer.c +8 -9
@@ -279,19 +279,18 @@ SYSCALL_DEFINE3(setitimer, int, which, struct itimerval __user *, value, struct itimerval __user *, ovalue) {struct itimerval set_buffer, get_buffer; -int error; +int error = -EFAULT ;if (value) {if (copy_from_user (&set_buffer, value,sizeof (set_buffer)))return -EFAULT ; - }else -memset ((char *) &set_buffer,0 ,sizeof (set_buffer)); - error =do_setitimer (which, &set_buffer, ovalue ? &get_buffer :NULL ); -if (error || !ovalue) -return error; + error =do_setitimer (which, &set_buffer, ovalue ? &get_buffer :NULL ); +if (error || !ovalue) +return error; -if (copy_to_user (ovalue, &get_buffer,sizeof (get_buffer))) -return -EFAULT ; -return 0 ; +if (copy_to_user (ovalue, &get_buffer,sizeof (get_buffer))) +return -EFAULT ; + } +return error; }
Signature · 1 line
1.7.3.4
Quoted 1 line · Sasikantha babu
Return
-EFAULTif user pointer "value" is NULL.
In principle I agree, though this might break exisiting user space as this behaviour has been there since Linux 1.1.52
So the right thing to do is to add a WARN_ONCE() in the else path and schedule the removal of this "feature" for v3.6
kernel/itimer.c SYSCALL_DEFINE3(setitimer, int, which, struct itimerval __user *, value, · line 282
Quoted 10 lines
kernel/itimer.c +1
-1@@ -279,19 +279,18 @@ SYSCALL_DEFINE3(setitimer, int, which, struct itimerval __user *, value, struct itimerval __user *, ovalue) {struct itimerval set_buffer, get_buffer; -int error; +int error = -EFAULT ;
Instead of ripping the whole thing apart, it's way simpler to just do
if (!value) return -EFAULT;
Thanks,
tglx