signal: let valid_signal() check more
PATCH 1/1 signal: let valid_signal() check more
Teach valid_signal() to check sig > 0 case.
Tested on UML only.
---
drivers/char/vt_ioctl.c +1 -1
@@ -727,7 +727,7 @@ int vt_ioctl(struct tty_struct *tty, struct file * file, {if (!perm || !capable (CAP_KILL )) goto eperm; -if (!valid_signal (arg) || arg <1 || arg ==SIGKILL ) +if (!valid_signal ((int )arg) || arg ==SIGKILL ) ret = -EINVAL ;else {spin_lock_irq (&vt_spawn_con.lock);
fs/fcntl.c +3 -4
@@ -313,11 +313,10 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,break ;case F_SETSIG :/* arg == 0 restores default behaviour. */ -if (!valid_signal (arg)) { -break ; +if (arg ==0 ||valid_signal ((int )arg)) { + err =0 ; + filp->f_owner.signum = arg; } - err =0 ; - filp->f_owner.signum = arg;break ;case F_GETLEASE : err =fcntl_getlease (filp);
include/linux/signal.h +2 -2
@@ -227,9 +227,9 @@ static inline void init_sigpending(struct sigpending *sig)extern void flush_sigqueue (struct sigpending *queue);/* Test if 'sig' is valid signal. Use this instead of testing _NSIG directly */ -static inline int valid_signal (unsigned long sig) +static inline int valid_signal (int sig) { -return sig <= _NSIG ?1 :0 ; +return sig <= _NSIG ? (sig >0 ) :0 ; }extern int next_signal (struct sigpending *pending,sigset_t *mask);
kernel/exit.c +2 -2
@@ -376,7 +376,7 @@ static void set_special_pids(struct pid *pid)*/ int allow_signal (int sig) { -if (!valid_signal (sig) || sig <1 ) +if (!valid_signal (sig))return -EINVAL ;spin_lock_irq (¤t->sighand->siglock);
@@ -397,7 +397,7 @@ EXPORT_SYMBOL(allow_signal);int disallow_signal (int sig) { -if (!valid_signal (sig) || sig <1 ) +if (!valid_signal (sig))return -EINVAL ;spin_lock_irq (¤t->sighand->siglock);
kernel/ptrace.c +1 -1
@@ -369,7 +369,7 @@ static int ptrace_setsiginfo(struct task_struct *child, const siginfo_t *info)static int ptrace_resume (struct task_struct *child,long request,long data) { -if (!valid_signal (data)) +if (!valid_signal ((int )data))return -EIO ;if (request ==PTRACE_SYSCALL )
kernel/signal.c +2 -2
@@ -1411,7 +1411,7 @@ int do_notify_parent(struct task_struct *tsk, int sig)if (psig->action[SIGCHLD -1 ].sa.sa_handler ==SIG_IGN ) sig =-1 ; } -if (valid_signal (sig) && sig >0 ) +if (valid_signal (sig))__group_send_sig_info (sig, &info, tsk->parent);__wake_up_parent (tsk, tsk->parent);spin_unlock_irqrestore (&psig->siglock, flags);
@@ -2308,7 +2308,7 @@ int do_sigaction(int sig, struct k_sigaction *act, struct k_sigaction *oact)struct k_sigaction *k;sigset_t mask; -if (!valid_signal (sig) || sig <1 || (act &&sig_kernel_only (sig))) +if (!valid_signal (sig) || (act &&sig_kernel_only (sig)))return -EINVAL ; k = &t->sighand->action[sig-1 ];
kernel/sys.c +1 -1
@@ -1631,7 +1631,7 @@ asmlinkage long sys_prctl(int option, unsigned long arg2, unsigned long arg3,switch (option) {case PR_SET_PDEATHSIG : -if (!valid_signal (arg2)) { +if (!valid_signal ((int )arg2)) { error = -EINVAL ;break ; }
Oleg Nesterov
maintainerQuoted 2 lines · Américo Wang
Teach
valid_signal()to check sig > 0 case.
Why?
drivers/char/vt_ioctl.c int vt_ioctl(struct tty_struct *tty, struct file * file, · line 730
Quoted 6 lines
drivers/char/vt_ioctl.c +1
-1@@ -727,7 +727,7 @@ int vt_ioctl(struct tty_struct *tty, struct file * file, {if (!perm || !capable (CAP_KILL )) goto eperm; -if (!valid_signal (arg) || arg <1 || arg ==SIGKILL ) +if (!valid_signal ((int )arg) || arg ==SIGKILL )
^^^^^
The patch adds a lot of unnecessary typecasts like this.
Quoted 6 lines
include/linux/signal.h +2
-2-static inline int valid_signal (unsigned long sig) +static inline int valid_signal (int sig) { -return sig <= _NSIG ?1 :0 ; +return sig <= _NSIG ? (sig >0 ) :0 ;}
This looks a bit strange, why not
return sig > 0 && sig <= _NSIG;
?
But, more importantly, I don't think the patch is correct.
Unless I misread the patch, now kill(pid, 0) returns -EINVAL, no?
And we have other users of valid_signal() which assume that sig == 0 is OK, for example arch_ptrace().
Imho, the patch has a point, but perhaps it is better to add the new helper and then convert the users which do something like
if (valid_signal(sig) && sig) ...
What do you think?
Oleg.
Quoted 5 lines · Oleg Nesterov
Quoted 2 lines · Américo Wang
Teach
valid_signal()to check sig > 0 case.Why?
Just to simplify the checking.
Quoted 10 lines
drivers/char/vt_ioctl.c int vt_ioctl(struct tty_struct *tty, struct file * file, · line 730
Quoted 7 lines
drivers/char/vt_ioctl.c +1
-1@@ -727,7 +727,7 @@ int vt_ioctl(struct tty_struct *tty, struct file * file, {if (!perm || !capable (CAP_KILL )) goto eperm; -if (!valid_signal (arg) || arg <1 || arg ==SIGKILL ) +if (!valid_signal ((int )arg) || arg ==SIGKILL )^^^^^The patch adds a lot of unnecessary typecasts like this.
because it's inline?
Quoted 10 lines
Quoted 7 lines
include/linux/signal.h +2
-2-static inline int valid_signal (unsigned long sig) +static inline int valid_signal (int sig) { -return sig <= _NSIG ?1 :0 ; +return sig <= _NSIG ? (sig >0 ) :0 ;}
This looks a bit strange, why not
Quoted 3 lines
return sig > 0 && sig <= _NSIG;?
Yes, this one is better.
Quoted 7 lines
But, more importantly, I don't think the patch is correct.
Unless I misread the patch, now
kill(pid, 0)returns-EINVAL, no?And we have other users of
valid_signal()which assume that sig == 0 is OK, for examplearch_ptrace().
Oh, thanks for pointing this out. I didn't know this. Sorry.
Quoted 8 lines
Imho, the patch has a point, but perhaps it is better to add the new helper and then convert the users which do something like
if (valid_signal(sig) && sig) ...What do you think?
I think this is a good idea. I will do it.
Thanks.
Signature · 1 line
"Against stupidity, the gods themselves, contend in vain."
Quoted 11 lines · Américo Wang
Quoted 9 lines
drivers/char/vt_ioctl.c int vt_ioctl(struct tty_struct *tty, struct file * file, · line 730
Quoted 6 lines
drivers/char/vt_ioctl.c +1
-1@@ -727,7 +727,7 @@ int vt_ioctl(struct tty_struct *tty, struct file * file, {if (!perm || !capable (CAP_KILL )) goto eperm; -if (!valid_signal (arg) || arg <1 || arg ==SIGKILL ) +if (!valid_signal ((int )arg) || arg ==SIGKILL )^^^^^The patch adds a lot of unnecessary typecasts like this.
because it's inline?
Why does your patch add a lot of seemingly unnecessary typecasts? [if your short reply was supposed to be an answer to that question then please explain it in more detail.]
Ingo
Quoted 11 lines · Ingo Molnar
Quoted 8 lines · Américo Wang
Quoted 8 lines
drivers/char/vt_ioctl.c int vt_ioctl(struct tty_struct *tty, struct file * file, · line 730
Quoted 6 lines
drivers/char/vt_ioctl.c +1
-1@@ -727,7 +727,7 @@ int vt_ioctl(struct tty_struct *tty, struct file * file, {if (!perm || !capable (CAP_KILL )) goto eperm; -if (!valid_signal (arg) || arg <1 || arg ==SIGKILL ) +if (!valid_signal ((int )arg) || arg ==SIGKILL )^^^^^
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
The patch adds a lot of unnecessary typecasts like this.
because it's inline?
Why does your patch add a lot of seemingly unnecessary typecasts? [if your short reply was supposed to be an answer to that question then please explain it in more detail.]
Hi, Ingo.
because I also changed the type of valid_signal():
-static inline int valid_signal(unsigned long sig) +static inline int valid_signal(int sig)
I noticed that gcc put this kind of warning into -Wtraditional-conversion recently, but it is still useful to use explicit cast, isn't it?
Thanks.
Signature · 1 line
"Against stupidity, the gods themselves, contend in vain."
Oleg Nesterov
maintainerQuoted 21 lines · Américo Wang
Quoted 11 lines · Ingo Molnar
Quoted 8 lines · Américo Wang
Quoted 8 lines
drivers/char/vt_ioctl.c int vt_ioctl(struct tty_struct *tty, struct file * file, · line 730
Quoted 6 lines
drivers/char/vt_ioctl.c +1
-1@@ -727,7 +727,7 @@ int vt_ioctl(struct tty_struct *tty, struct file * file, {if (!perm || !capable (CAP_KILL )) goto eperm; -if (!valid_signal (arg) || arg <1 || arg ==SIGKILL ) +if (!valid_signal ((int )arg) || arg ==SIGKILL )^^^^^Quoted 7 lines
Quoted 3 lines
Quoted 1 line
The patch adds a lot of unnecessary typecasts like this.
because it's inline?
Why does your patch add a lot of seemingly unnecessary typecasts? [if your short reply was supposed to be an answer to that question then please explain it in more detail.]
Quoted 6 lines
Hi, Ingo.
because I also changed the type of
valid_signal():-static inline int
valid_signal(unsigned long sig)+static inline intvalid_signal(int sig)
and please note that this change itself is a bit dangerous. Suppose that a bad user does sys_prctl(PR_SET_PDEATHSIG, LONG_MIN | SIGCHLD), and now valid_signal(arg2) (or valid_signal((int)arg2)) returns T.
(nothing really bad happens because ->pdeath_signal is "int", but still).
Note also that it is correct to do prctl(PR_SET_PDEATHSIG, 0), so the patch was doubly wrong here.
So, please check very carefully every change you are going to do. Make sure you don't change the behaviour, unless you think the current code is buggy. In that case please document the fix.
OTOH, I don't understand why sys_mq_notify() accepts sigev_signo == 0, perhaps this is oversight. good_sigevent() looks correct, but should use the helper.
Quoted 3 lines
I noticed that gcc put this kind of warning into -Wtraditional-conversion recently, but it is still useful to use explicit cast, isn't it?
I'd say explicit casts should be avoided as much as possible.
As for this particular case. Note that valid_signa((int)long_arg) only helps to hide the problem.
Oleg.