[PATCH] signal: strict valid signal check

Hongchen Zhang posted 1 patch 4 years, 5 months ago
include/linux/signal.h | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
[PATCH] signal: strict valid signal check
Posted by Hongchen Zhang 4 years, 5 months ago
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@loongson.cn>
---
 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

Re: [PATCH] signal: strict valid signal check
Posted by Eric W. Biederman 4 years, 5 months ago
Hongchen Zhang <zhanghongchen@loongson.cn> writes:

> 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.

A quick look reveals this only affects mips.

If you have copied that silliness from mips for your new architecture
I would advise against it.  That just seems to make sigset_t twice
as big as it needs to be for no good reason.

What seems reasonable is to fix mips to only support 127 signals (with
the same sigset_t size) and to add "BUILD_BUG_ON(_NSIG <= 127);" along
with your comment somewhere in kernel/signal.c

Eric


> Signed-off-by: Hongchen Zhang <zhanghongchen@loongson.cn>
> ---
>  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;
Re: [PATCH] signal: strict valid signal check
Posted by kernel test robot 4 years, 5 months ago
Hi Hongchen,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linux/master]
[also build test ERROR on linus/master hnaz-mm/master v5.16-rc8 next-20220106]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Hongchen-Zhang/signal-strict-valid-signal-check/20220107-124756
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 136057256686de39cc3a07c2e39ef6bc43003ff6
config: hexagon-randconfig-r041-20220107 (https://download.01.org/0day-ci/archive/20220107/202201072220.gCthUkw6-lkp@intel.com/config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 32167bfe64a4c5dd4eb3f7a58e24f4cba76f5ac2)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/d6ab2033eb509bf064e07f58074e58562098dfcc
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Hongchen-Zhang/signal-strict-valid-signal-check/20220107-124756
        git checkout d6ab2033eb509bf064e07f58074e58562098dfcc
        # save the config file to linux build tree
        mkdir build_dir
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon SHELL=/bin/bash drivers/tty/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   In file included from drivers/tty/tty_io.c:71:
>> include/linux/signal.h:277:16: error: implicit declaration of function 'min' [-Werror,-Wimplicit-function-declaration]
           return sig <= min(_NSIG, 127) ? 1 : 0;
                         ^
   1 error generated.


vim +/min +277 include/linux/signal.h

   269	
   270	/* Test if 'sig' is valid signal. Use this instead of testing _NSIG directly */
   271	static inline int valid_signal(unsigned long sig)
   272	{
   273		/* max usable signal number is limited by both _NSIG and task's
   274		 * exit_code, and the max available signal number encoded in
   275		 * task's exit_code is 127.
   276		 */
 > 277		return sig <= min(_NSIG, 127) ? 1 : 0;
   278	}
   279	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org