LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH v2] rave-sp: Remove VLA
@ 2018-04-27 22:30 Kyle Spiers
2018-04-30 12:38 ` Lee Jones
0 siblings, 1 reply; 3+ messages in thread
From: Kyle Spiers @ 2018-04-27 22:30 UTC (permalink / raw)
To: lee.jones; +Cc: linux-kernel, keescook, Kyle Spiers
As part of the effort to remove VLAs from the kernel[1], this creates
constants for the checksum lengths of CCITT and 8B2C and changes
crc_calculated to be the maximum size of a checksum.
https://lkml.org/lkml/2018/3/7/621
Signed-off-by: Kyle Spiers <ksspiers@google.com>
---
drivers/mfd/rave-sp.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/mfd/rave-sp.c b/drivers/mfd/rave-sp.c
index 5c858e784a89..4ce96b7137db 100644
--- a/drivers/mfd/rave-sp.c
+++ b/drivers/mfd/rave-sp.c
@@ -45,7 +45,9 @@
#define RAVE_SP_DLE 0x10
#define RAVE_SP_MAX_DATA_SIZE 64
-#define RAVE_SP_CHECKSUM_SIZE 2 /* Worst case scenario on RDU2 */
+#define RAVE_SP_CHECKSUM_8B2C 1
+#define RAVE_SP_CHECKSUM_CCITT 2
+#define RAVE_SP_CHECKSUM_SIZE RAVE_SP_CHECKSUM_CCITT
/*
* We don't store STX, ETX and unescaped bytes, so Rx is only
* DATA + CSUM
@@ -415,7 +417,12 @@ static void rave_sp_receive_frame(struct rave_sp *sp,
const size_t payload_length = length - checksum_length;
const u8 *crc_reported = &data[payload_length];
struct device *dev = &sp->serdev->dev;
- u8 crc_calculated[checksum_length];
+ u8 crc_calculated[RAVE_SP_CHECKSUM_SIZE];
+
+ if (unlikely(checksum_length > sizeof(crc_calculated))) {
+ dev_warn(dev, "Checksum too long, dropping\n");
+ return;
+ }
print_hex_dump(KERN_DEBUG, "rave-sp rx: ", DUMP_PREFIX_NONE,
16, 1, data, length, false);
--
2.17.0.441.gb46fe60e1d-goog
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] rave-sp: Remove VLA
2018-04-27 22:30 [PATCH v2] rave-sp: Remove VLA Kyle Spiers
@ 2018-04-30 12:38 ` Lee Jones
2018-04-30 13:48 ` Kees Cook
0 siblings, 1 reply; 3+ messages in thread
From: Lee Jones @ 2018-04-30 12:38 UTC (permalink / raw)
To: Kyle Spiers; +Cc: linux-kernel, keescook
On Fri, 27 Apr 2018, Kyle Spiers wrote:
> As part of the effort to remove VLAs from the kernel[1], this creates
> constants for the checksum lengths of CCITT and 8B2C and changes
> crc_calculated to be the maximum size of a checksum.
>
> https://lkml.org/lkml/2018/3/7/621
>
> Signed-off-by: Kyle Spiers <ksspiers@google.com>
> ---
> drivers/mfd/rave-sp.c | 11 +++++++++--
> 1 file changed, 9 insertions(+), 2 deletions(-)
Applied, thanks.
Kees, do you want me to add your Ack?
> diff --git a/drivers/mfd/rave-sp.c b/drivers/mfd/rave-sp.c
> index 5c858e784a89..4ce96b7137db 100644
> --- a/drivers/mfd/rave-sp.c
> +++ b/drivers/mfd/rave-sp.c
> @@ -45,7 +45,9 @@
> #define RAVE_SP_DLE 0x10
>
> #define RAVE_SP_MAX_DATA_SIZE 64
> -#define RAVE_SP_CHECKSUM_SIZE 2 /* Worst case scenario on RDU2 */
> +#define RAVE_SP_CHECKSUM_8B2C 1
> +#define RAVE_SP_CHECKSUM_CCITT 2
> +#define RAVE_SP_CHECKSUM_SIZE RAVE_SP_CHECKSUM_CCITT
> /*
> * We don't store STX, ETX and unescaped bytes, so Rx is only
> * DATA + CSUM
> @@ -415,7 +417,12 @@ static void rave_sp_receive_frame(struct rave_sp *sp,
> const size_t payload_length = length - checksum_length;
> const u8 *crc_reported = &data[payload_length];
> struct device *dev = &sp->serdev->dev;
> - u8 crc_calculated[checksum_length];
> + u8 crc_calculated[RAVE_SP_CHECKSUM_SIZE];
> +
> + if (unlikely(checksum_length > sizeof(crc_calculated))) {
> + dev_warn(dev, "Checksum too long, dropping\n");
> + return;
> + }
>
> print_hex_dump(KERN_DEBUG, "rave-sp rx: ", DUMP_PREFIX_NONE,
> 16, 1, data, length, false);
--
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] rave-sp: Remove VLA
2018-04-30 12:38 ` Lee Jones
@ 2018-04-30 13:48 ` Kees Cook
0 siblings, 0 replies; 3+ messages in thread
From: Kees Cook @ 2018-04-30 13:48 UTC (permalink / raw)
To: Lee Jones; +Cc: Kyle Spiers, LKML
On Mon, Apr 30, 2018 at 5:38 AM, Lee Jones <lee.jones@linaro.org> wrote:
> On Fri, 27 Apr 2018, Kyle Spiers wrote:
>
>> As part of the effort to remove VLAs from the kernel[1], this creates
>> constants for the checksum lengths of CCITT and 8B2C and changes
>> crc_calculated to be the maximum size of a checksum.
>>
>> https://lkml.org/lkml/2018/3/7/621
>>
>> Signed-off-by: Kyle Spiers <ksspiers@google.com>
>> ---
>> drivers/mfd/rave-sp.c | 11 +++++++++--
>> 1 file changed, 9 insertions(+), 2 deletions(-)
>
> Applied, thanks.
>
> Kees, do you want me to add your Ack?
Sure!
Reviewed-by: Kees Cook <keescook@chromium.org>
Thanks!
-Kees
>
>> diff --git a/drivers/mfd/rave-sp.c b/drivers/mfd/rave-sp.c
>> index 5c858e784a89..4ce96b7137db 100644
>> --- a/drivers/mfd/rave-sp.c
>> +++ b/drivers/mfd/rave-sp.c
>> @@ -45,7 +45,9 @@
>> #define RAVE_SP_DLE 0x10
>>
>> #define RAVE_SP_MAX_DATA_SIZE 64
>> -#define RAVE_SP_CHECKSUM_SIZE 2 /* Worst case scenario on RDU2 */
>> +#define RAVE_SP_CHECKSUM_8B2C 1
>> +#define RAVE_SP_CHECKSUM_CCITT 2
>> +#define RAVE_SP_CHECKSUM_SIZE RAVE_SP_CHECKSUM_CCITT
>> /*
>> * We don't store STX, ETX and unescaped bytes, so Rx is only
>> * DATA + CSUM
>> @@ -415,7 +417,12 @@ static void rave_sp_receive_frame(struct rave_sp *sp,
>> const size_t payload_length = length - checksum_length;
>> const u8 *crc_reported = &data[payload_length];
>> struct device *dev = &sp->serdev->dev;
>> - u8 crc_calculated[checksum_length];
>> + u8 crc_calculated[RAVE_SP_CHECKSUM_SIZE];
>> +
>> + if (unlikely(checksum_length > sizeof(crc_calculated))) {
>> + dev_warn(dev, "Checksum too long, dropping\n");
>> + return;
>> + }
>>
>> print_hex_dump(KERN_DEBUG, "rave-sp rx: ", DUMP_PREFIX_NONE,
>> 16, 1, data, length, false);
>
> --
> Lee Jones [李琼斯]
> Linaro Services Technical Lead
> Linaro.org │ Open source software for ARM SoCs
> Follow Linaro: Facebook | Twitter | Blog
--
Kees Cook
Pixel Security
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-04-30 13:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-27 22:30 [PATCH v2] rave-sp: Remove VLA Kyle Spiers
2018-04-30 12:38 ` Lee Jones
2018-04-30 13:48 ` Kees Cook
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).