misc: tifm: Remove VLA
Subsystems (2)
PATCH 1/1 misc: tifm: Remove VLA
There's an ongoing effort to remove VLAs[1] from the kernel to eventually turn on -Wvla. The single VLA can either take a value of 2 or 4 so switch to the upper bound.
[1] https://lkml.org/lkml/2018/3/7/621
--- drivers/misc/tifm_7xx1.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/misc/tifm_7xx1.c +2 -1
@@ -239,7 +239,8 @@ static int tifm_7xx1_resume(struct pci_dev *dev)unsigned long timeout;unsigned int good_sockets =0 , bad_sockets =0 ;unsigned long flags; -unsigned char new_ids[fm->num_sockets]; +/* Maximum number of entries is 4 */ +unsigned char new_ids[4 ];DECLARE_COMPLETION_ONSTACK (finish_resume);pci_set_power_state (dev,PCI_D0 );
Signature · 1 line
2.14.3
Arnd Bergmann
maintainerQuoted 16 lines · Laura Abbott
There's an ongoing effort to remove VLAs[1] from the kernel to eventually turn on -Wvla. The single VLA can either take a value of 2 or 4 so switch to the upper bound.
[1] https://lkml.org/lkml/2018/3/7/621
Signed-off-by Laura Abbott <[email protected]>--- drivers/misc/tifm_7xx1.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/misc/tifm_7xx1.c +0
-0
drivers/misc/tifm_7xx1.c static int tifm_7xx1_resume(struct pci_dev *dev) · line 245
Quoted 8 lines
drivers/misc/tifm_7xx1.c +2
-1@@ -239,7 +239,8 @@ static int tifm_7xx1_resume(struct pci_dev *dev)unsigned long timeout;unsigned int good_sockets =0 , bad_sockets =0 ;unsigned long flags; -unsigned char new_ids[fm->num_sockets]; +/* Maximum number of entries is 4 */ +unsigned char new_ids[4 ];DECLARE_COMPLETION_ONSTACK (finish_resume);
I like the idea of removing all the VLAs, but this one appears to make the code less robust rather than more: In case of an unexpected fm->num_sockets value, we now not only overflow the kernel stack area but also the local variable into the neighboring stack slots.
Maybe add an extra overflow check?
Arnd
drivers/misc/tifm_7xx1.c +5 -1
@@ -239,9 +239,12 @@ static int tifm_7xx1_resume(struct pci_dev *dev)unsigned long timeout;unsigned int good_sockets =0 , bad_sockets =0 ;unsigned long flags; -unsigned char new_ids[fm->num_sockets]; +/* Maximum number of entries is 4 */ +unsigned char new_ids[4 ];DECLARE_COMPLETION_ONSTACK (finish_resume); +if (WARN_ON (fm->num_sockets >ARRAY_SIZE (new_ids))) +return -ENXIO ; +pci_set_power_state (dev,PCI_D0 );pci_restore_state (dev);
rc = pci_enable_device(dev);
Quoted 31 lines · Arnd Bergmann
Quoted 16 lines · Laura Abbott
There's an ongoing effort to remove VLAs[1] from the kernel to eventually turn on -Wvla. The single VLA can either take a value of 2 or 4 so switch to the upper bound.
[1] https://lkml.org/lkml/2018/3/7/621
Signed-off-by Laura Abbott <[email protected]>--- drivers/misc/tifm_7xx1.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/misc/tifm_7xx1.c +0
-0drivers/misc/tifm_7xx1.c static int tifm_7xx1_resume(struct pci_dev *dev) · line 245
Quoted 8 lines
drivers/misc/tifm_7xx1.c +2
-1@@ -239,7 +239,8 @@ static int tifm_7xx1_resume(struct pci_dev *dev)unsigned long timeout;unsigned int good_sockets =0 , bad_sockets =0 ;unsigned long flags; -unsigned char new_ids[fm->num_sockets]; +/* Maximum number of entries is 4 */ +unsigned char new_ids[4 ];DECLARE_COMPLETION_ONSTACK (finish_resume);I like the idea of removing all the VLAs, but this one appears to make the code less robust rather than more: In case of an unexpected
fm->num_socketsvalue, we now not only overflow the kernel stack area but also the local variable into the neighboring stack slots.
Quoted 2 lines
Maybe add an extra overflow check?
Sure.
Quoted 22 lines
Arnd
drivers/misc/tifm_7xx1.c +5
-1@@ -239,9 +239,12 @@ static int tifm_7xx1_resume(struct pci_dev *dev)unsigned long timeout;unsigned int good_sockets =0 , bad_sockets =0 ;unsigned long flags; -unsigned char new_ids[fm->num_sockets]; +/* Maximum number of entries is 4 */ +unsigned char new_ids[4 ];DECLARE_COMPLETION_ONSTACK (finish_resume); +if (WARN_ON (fm->num_sockets >ARRAY_SIZE (new_ids))) +return -ENXIO ; +pci_set_power_state (dev,PCI_D0 );pci_restore_state (dev); rc =pci_enable_device (dev);