KSPP / linux

Linux kernel source tree (Kernel Self Protection Project)
https://kernsec.org/wiki/index.php/Kernel_Self_Protection_Project
Other
82 stars 5 forks source link

Enable -Wrestrict #134

Open kees opened 3 years ago

kees commented 3 years ago

We can avoid some possible robustness issues with overlapping arguments if we turn -Wrestrict back on. There are only a handful in an x86_64 allmodconfig build, and all appear to be the common "append to a string using sprintf()" idiom that isn't considered good form any more:

drivers/input/joystick/analog.c: In function 'analog_name':
drivers/input/joystick/analog.c:428:3: warning: 'snprintf' argument 4 overlaps destination object 'analog' [-Wrestrict]
  428 |   snprintf(analog->name, sizeof(analog->name), "%s %d-hat",
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  429 |     analog->name, hweight16(analog->mask & ANALOG_HATS_ALL));
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/input/joystick/analog.c:420:40: note: destination object referenced by 'restrict'-qualified argument 1 was declared here
  420 | static void analog_name(struct analog *analog)
      |                         ~~~~~~~~~~~~~~~^~~~~~
drivers/leds/led-class-flash.c: In function 'flash_fault_show':
drivers/leds/led-class-flash.c:212:9: warning: 'sprintf' argument 3 overlaps destination object 'buf' [-Wrestrict]
  212 |  return sprintf(buf, "%s\n", buf);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~
drivers/leds/led-class-flash.c:189:40: note: destination object referenced by 'restrict'-qualified argument 1 was declared here
  189 |   struct device_attribute *attr, char *buf)
      |                                  ~~~~~~^~~
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c: In function 'stmmac_request_irq_multi_msi':
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:3517:3: warning: 'sprintf' argument 3 may overlap destination object 'dev' [-Wrestrict]
 3517 |   sprintf(int_name, "%s:%s-%d", dev->name, "rx", i);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:3416:60: note: destination object referenced by 'restrict'-qualified argument 1 was declared here
 3416 | static int stmmac_request_irq_multi_msi(struct net_device *dev)
      |                                         ~~~~~~~~~~~~~~~~~~~^~~
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:3540:3: warning: 'sprintf' argument 3 may overlap destination object 'dev' [-Wrestrict]
 3540 |   sprintf(int_name, "%s:%s-%d", dev->name, "tx", i);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:3416:60: note: destination object referenced by 'restrict'-qualified argument 1 was declared here
 3416 | static int stmmac_request_irq_multi_msi(struct net_device *dev)
      |                                         ~~~~~~~~~~~~~~~~~~~^~~
drivers/thunderbolt/xdomain.c: In function 'modalias_show':
drivers/thunderbolt/xdomain.c:733:9: warning: 'sprintf' argument 3 overlaps destination object 'buf' [-Wrestrict]
  733 |  return sprintf(buf, "%s\n", buf);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~
drivers/thunderbolt/xdomain.c:727:15: note: destination object referenced by 'restrict'-qualified argument 1 was declared here
  727 |         char *buf)
      |         ~~~~~~^~~
kees commented 3 years ago

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c: https://git.kernel.org/pub/scm/linux/kernel/git/arnd/playground.git/commit/?h=randconfig-5.13&id=dc05fdd057deb9317c15fcab368da46e3495dee4 https://lore.kernel.org/lkml/caa29114659049e584b9fa7fbb6226c8@AcuMS.aculab.com/

kees commented 3 years ago

drivers/input/joystick/analog.c: https://git.kernel.org/pub/scm/linux/kernel/git/arnd/playground.git/commit/?h=randconfig-5.13&id=b92f8369f98afa1aac83699e78193883d15180d1 https://lore.kernel.org/lkml/20210324131959.2089129-1-arnd@kernel.org/

kees commented 5 months ago

Looks like Arnd and Gatlin have got this done: https://lore.kernel.org/lkml/CAN1+aZxiJVdMUd8q5w+Xo9EmHc9hhFzRyzEmgJ7eb5eNi+PD=g@mail.gmail.com/