public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] firmware: raspberrypi: Remove VLA usage
@ 2018-06-29 18:44 Kees Cook
  0 siblings, 0 replies; 4+ messages in thread
From: Kees Cook @ 2018-06-29 18:44 UTC (permalink / raw)
  To: Eric Anholt; +Cc: Arnd Bergmann, Stefan Wahren, linux-kernel

In the quest to remove all stack VLA usage from the kernel[1], this
removes the VLA in favor of a maximum size and adds a sanity check.
Existing callers of the firmware interface never need more than 24
bytes (struct gpio_set_config). This chooses 32 just to stay ahead
of future growth.

[1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com

Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/firmware/raspberrypi.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/firmware/raspberrypi.c b/drivers/firmware/raspberrypi.c
index 0602626bf72d..b80f15214b73 100644
--- a/drivers/firmware/raspberrypi.c
+++ b/drivers/firmware/raspberrypi.c
@@ -21,6 +21,8 @@
 #define MBOX_DATA28(msg)		((msg) & ~0xf)
 #define MBOX_CHAN_PROPERTY		8
 
+#define MAX_RPI_FW_PROP_BUF_SIZE	32
+
 static struct platform_device *rpi_hwmon;
 
 struct rpi_firmware {
@@ -145,11 +147,15 @@ int rpi_firmware_property(struct rpi_firmware *fw,
 	/* Single tags are very small (generally 8 bytes), so the
 	 * stack should be safe.
 	 */
-	u8 data[buf_size + sizeof(struct rpi_firmware_property_tag_header)];
+	u8 data[sizeof(struct rpi_firmware_property_tag_header) +
+		MAX_RPI_FW_PROP_BUF_SIZE];
 	struct rpi_firmware_property_tag_header *header =
 		(struct rpi_firmware_property_tag_header *)data;
 	int ret;
 
+	if (WARN_ON(buf_size > sizeof(data) - sizeof(*header)))
+		return -EINVAL;
+
 	header->tag = tag;
 	header->buf_size = buf_size;
 	header->req_resp_size = 0;
-- 
2.17.1


-- 
Kees Cook
Pixel Security

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH] fixup! firmware: raspberrypi: Remove VLA usage
       [not found] <Message-ID: <20180629184449.GA37304@beast>
@ 2018-07-02 19:45 ` Eric Anholt
  2018-07-02 21:05   ` Kees Cook
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Anholt @ 2018-07-02 19:45 UTC (permalink / raw)
  To: Kees Cook, Stefan Wahren; +Cc: Arnd Bergmann, linux-kernel, Eric Anholt

Kees - with this fix to your patch, the kernel boots again (otherwise,
the FW would try to parse the uninitialized bits of stack and throw
errors).  If you're good with me squashing this in, I'll do so and
send it to -next.

Signed-off-by: Eric Anholt <eric@anholt.net>
---
 drivers/firmware/raspberrypi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/firmware/raspberrypi.c b/drivers/firmware/raspberrypi.c
index b80f15214b73..a200a2174611 100644
--- a/drivers/firmware/raspberrypi.c
+++ b/drivers/firmware/raspberrypi.c
@@ -162,7 +162,7 @@ int rpi_firmware_property(struct rpi_firmware *fw,
 	memcpy(data + sizeof(struct rpi_firmware_property_tag_header),
 	       tag_data, buf_size);
 
-	ret = rpi_firmware_property_list(fw, &data, sizeof(data));
+	ret = rpi_firmware_property_list(fw, &data, buf_size + sizeof(*header));
 	memcpy(tag_data,
 	       data + sizeof(struct rpi_firmware_property_tag_header),
 	       buf_size);
-- 
2.18.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] fixup! firmware: raspberrypi: Remove VLA usage
  2018-07-02 19:45 ` [PATCH] fixup! " Eric Anholt
@ 2018-07-02 21:05   ` Kees Cook
  2018-07-05 19:27     ` Eric Anholt
  0 siblings, 1 reply; 4+ messages in thread
From: Kees Cook @ 2018-07-02 21:05 UTC (permalink / raw)
  To: Eric Anholt; +Cc: Stefan Wahren, Arnd Bergmann, LKML

On Mon, Jul 2, 2018 at 12:45 PM, Eric Anholt <eric@anholt.net> wrote:
> Kees - with this fix to your patch, the kernel boots again (otherwise,
> the FW would try to parse the uninitialized bits of stack and throw
> errors).  If you're good with me squashing this in, I'll do so and
> send it to -next.
>
> Signed-off-by: Eric Anholt <eric@anholt.net>
> ---
>  drivers/firmware/raspberrypi.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/firmware/raspberrypi.c b/drivers/firmware/raspberrypi.c
> index b80f15214b73..a200a2174611 100644
> --- a/drivers/firmware/raspberrypi.c
> +++ b/drivers/firmware/raspberrypi.c
> @@ -162,7 +162,7 @@ int rpi_firmware_property(struct rpi_firmware *fw,
>         memcpy(data + sizeof(struct rpi_firmware_property_tag_header),
>                tag_data, buf_size);
>
> -       ret = rpi_firmware_property_list(fw, &data, sizeof(data));
> +       ret = rpi_firmware_property_list(fw, &data, buf_size + sizeof(*header));
>         memcpy(tag_data,
>                data + sizeof(struct rpi_firmware_property_tag_header),
>                buf_size);

Eek! Yes, thank you. Yeah, please feel free to squash. Thanks for testing!

-Kees

-- 
Kees Cook
Pixel Security

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] fixup! firmware: raspberrypi: Remove VLA usage
  2018-07-02 21:05   ` Kees Cook
@ 2018-07-05 19:27     ` Eric Anholt
  0 siblings, 0 replies; 4+ messages in thread
From: Eric Anholt @ 2018-07-05 19:27 UTC (permalink / raw)
  To: Kees Cook; +Cc: Stefan Wahren, Arnd Bergmann, LKML

[-- Attachment #1: Type: text/plain, Size: 1297 bytes --]

Kees Cook <keescook@chromium.org> writes:

> On Mon, Jul 2, 2018 at 12:45 PM, Eric Anholt <eric@anholt.net> wrote:
>> Kees - with this fix to your patch, the kernel boots again (otherwise,
>> the FW would try to parse the uninitialized bits of stack and throw
>> errors).  If you're good with me squashing this in, I'll do so and
>> send it to -next.
>>
>> Signed-off-by: Eric Anholt <eric@anholt.net>
>> ---
>>  drivers/firmware/raspberrypi.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/firmware/raspberrypi.c b/drivers/firmware/raspberrypi.c
>> index b80f15214b73..a200a2174611 100644
>> --- a/drivers/firmware/raspberrypi.c
>> +++ b/drivers/firmware/raspberrypi.c
>> @@ -162,7 +162,7 @@ int rpi_firmware_property(struct rpi_firmware *fw,
>>         memcpy(data + sizeof(struct rpi_firmware_property_tag_header),
>>                tag_data, buf_size);
>>
>> -       ret = rpi_firmware_property_list(fw, &data, sizeof(data));
>> +       ret = rpi_firmware_property_list(fw, &data, buf_size + sizeof(*header));
>>         memcpy(tag_data,
>>                data + sizeof(struct rpi_firmware_property_tag_header),
>>                buf_size);
>
> Eek! Yes, thank you. Yeah, please feel free to squash. Thanks for testing!

Squashed and sent the PR.  Thanks!

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-07-05 19:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-06-29 18:44 [PATCH] firmware: raspberrypi: Remove VLA usage Kees Cook
     [not found] <Message-ID: <20180629184449.GA37304@beast>
2018-07-02 19:45 ` [PATCH] fixup! " Eric Anholt
2018-07-02 21:05   ` Kees Cook
2018-07-05 19:27     ` Eric Anholt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox