[PATCH] signal: strict valid signal check

From: Hongchen Zhang
Date: Thu Jan 06 2022 - 23:46:35 EST


The max usable signal number is limited by both _NSIG and task's
exit_code, and the max valid signal number encoded in task's
exit_code is 127. On the other hand _NSIG is normally power of 2,
so limit the rule in valid_signal to check a valid signal number.

Signed-off-by: Hongchen Zhang <zhanghongchen@xxxxxxxxxxx>
---
include/linux/signal.h | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/include/linux/signal.h b/include/linux/signal.h
index a6db6f2..9f1972e 100644
--- a/include/linux/signal.h
+++ b/include/linux/signal.h
@@ -270,7 +270,11 @@ static inline void init_sigpending(struct sigpending *sig)
/* Test if 'sig' is valid signal. Use this instead of testing _NSIG directly */
static inline int valid_signal(unsigned long sig)
{
- return sig <= _NSIG ? 1 : 0;
+ /* max usable signal number is limited by both _NSIG and task's
+ * exit_code, and the max available signal number encoded in
+ * task's exit_code is 127.
+ */
+ return sig <= min(_NSIG, 127) ? 1 : 0;
}

struct timespec;
--
1.8.3.1