LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] misc: tifm: Remove VLA
@ 2018-04-09 21:07 Laura Abbott
2018-04-10 7:57 ` Arnd Bergmann
0 siblings, 1 reply; 3+ messages in thread
From: Laura Abbott @ 2018-04-09 21:07 UTC (permalink / raw)
To: Alex Dubov, Arnd Bergmann, Greg Kroah-Hartman
Cc: Laura Abbott, linux-kernel, kernel-hardening
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 <labbott@redhat.com>
---
drivers/misc/tifm_7xx1.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/misc/tifm_7xx1.c b/drivers/misc/tifm_7xx1.c
index e5f108713dd8..690eaaea5ce4 100644
--- a/drivers/misc/tifm_7xx1.c
+++ b/drivers/misc/tifm_7xx1.c
@@ -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);
--
2.14.3
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] misc: tifm: Remove VLA
2018-04-09 21:07 [PATCH] misc: tifm: Remove VLA Laura Abbott
@ 2018-04-10 7:57 ` Arnd Bergmann
2018-04-10 18:49 ` Laura Abbott
0 siblings, 1 reply; 3+ messages in thread
From: Arnd Bergmann @ 2018-04-10 7:57 UTC (permalink / raw)
To: Laura Abbott
Cc: Alex Dubov, Greg Kroah-Hartman, Linux Kernel Mailing List,
Kernel Hardening
On Mon, Apr 9, 2018 at 11:07 PM, Laura Abbott <labbott@redhat.com> wrote:
> 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 <labbott@redhat.com>
> ---
> drivers/misc/tifm_7xx1.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/misc/tifm_7xx1.c b/drivers/misc/tifm_7xx1.c
> index e5f108713dd8..690eaaea5ce4 100644
> --- a/drivers/misc/tifm_7xx1.c
> +++ b/drivers/misc/tifm_7xx1.c
> @@ -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
diff --git a/drivers/misc/tifm_7xx1.c b/drivers/misc/tifm_7xx1.c
index e5f108713dd8..c702cd92d396 100644
--- a/drivers/misc/tifm_7xx1.c
+++ b/drivers/misc/tifm_7xx1.c
@@ -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);
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] misc: tifm: Remove VLA
2018-04-10 7:57 ` Arnd Bergmann
@ 2018-04-10 18:49 ` Laura Abbott
0 siblings, 0 replies; 3+ messages in thread
From: Laura Abbott @ 2018-04-10 18:49 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Alex Dubov, Greg Kroah-Hartman, Linux Kernel Mailing List,
Kernel Hardening
On 04/10/2018 12:57 AM, Arnd Bergmann wrote:
> On Mon, Apr 9, 2018 at 11:07 PM, Laura Abbott <labbott@redhat.com> wrote:
>> 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 <labbott@redhat.com>
>> ---
>> drivers/misc/tifm_7xx1.c | 3 ++-
>> 1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/misc/tifm_7xx1.c b/drivers/misc/tifm_7xx1.c
>> index e5f108713dd8..690eaaea5ce4 100644
>> --- a/drivers/misc/tifm_7xx1.c
>> +++ b/drivers/misc/tifm_7xx1.c
>> @@ -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?
>
Sure.
> Arnd
>
> diff --git a/drivers/misc/tifm_7xx1.c b/drivers/misc/tifm_7xx1.c
> index e5f108713dd8..c702cd92d396 100644
> --- a/drivers/misc/tifm_7xx1.c
> +++ b/drivers/misc/tifm_7xx1.c
> @@ -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);
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-04-10 18:49 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-09 21:07 [PATCH] misc: tifm: Remove VLA Laura Abbott
2018-04-10 7:57 ` Arnd Bergmann
2018-04-10 18:49 ` Laura Abbott
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).