Skip to contentSkip to conversation

rave-sp: Remove VLA

PATCH Superseded Kyle Spiers 3 participants 7 messages Apr 23, 2018 – Apr 26, 2018 Multifunction devices (MFD)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rave-sp: Remove VLA

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

---
 drivers/mfd/rave-sp.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/mfd/rave-sp.c +9 -2
index 5c858e784a89..99fa482419f9 100644
@@ -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(length > sizeof(crc_calculated))) {
+		dev_warn(dev, "Dropping oversized frame\n");
+		return;
+	}
 
 	print_hex_dump(KERN_DEBUG, "rave-sp rx: ", DUMP_PREFIX_NONE,
 		       16, 1, data, length, false);
Signature · 1 line
2.17.0.484.g0c8726318c-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · 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

-Kees

Quoted 36 lines
---
 drivers/mfd/rave-sp.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/mfd/rave-sp.c +9 -3
index 5c858e784a89..99fa482419f9 100644
@@ -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(length > sizeof(crc_calculated))) {
+               dev_warn(dev, "Dropping oversized frame\n");
+               return;
+       }
 
        print_hex_dump(KERN_DEBUG, "rave-sp rx: ", DUMP_PREFIX_NONE,
                       16, 1, data, length, false);
--

2.17.0.484.g0c8726318c-goog

Signature · 2 lines
Kees Cook
Pixel Security
#2 lore raw
In reply to Kyle Spiers
Quoted 27 lines · 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

---
 drivers/mfd/rave-sp.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/mfd/rave-sp.c +3 -1
index 5c858e784a89..99fa482419f9 100644
@@ -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

drivers/mfd/rave-sp.c static void rave_sp_receive_frame(struct rave_sp *sp, · line 422

Quoted 7 lines
drivers/mfd/rave-sp.c +3 -1
@@ -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(length > sizeof(crc_calculated))) {

Forgive me if I have this wrong (it's still very early here), but this doesn't leave any room for the payload?

    <--       length         -->
    <ck len><- payload length ->
    [CK][CK][D][A][T][A] .. [64]

It is my hope that length would always be larger than the size of the checksum, or else there would never be any data?

Should this not be:

if (unlikely(length > RAVE_SP_MAX_DATA_SIZE))

Nit: Adding the check is also an unrelated change, so would require a separate patch.

Quoted 6 lines
drivers/mfd/rave-sp.c +3 -0
+		dev_warn(dev, "Dropping oversized frame\n");
+		return;
+	}
 
 	print_hex_dump(KERN_DEBUG, "rave-sp rx: ", DUMP_PREFIX_NONE,
 		       16, 1, data, length, false);
Signature · 4 lines
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
#3 lore raw
Quoted 44 lines · Lee Jones
Quoted 27 lines · 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

---
 drivers/mfd/rave-sp.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/mfd/rave-sp.c +3 -1
index 5c858e784a89..99fa482419f9 100644
@@ -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

drivers/mfd/rave-sp.c static void rave_sp_receive_frame(struct rave_sp *sp, · line 422

Quoted 7 lines
drivers/mfd/rave-sp.c +3 -1
@@ -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(length > sizeof(crc_calculated))) {

Forgive me if I have this wrong (it's still very early here), but this doesn't leave any room for the payload?

    <--       length         -->
    <ck len><- payload length ->
    [CK][CK][D][A][T][A] .. [64]
Quoted 6 lines

It is my hope that length would always be larger than the size of the checksum, or else there would never be any data?

Should this not be:

if (unlikely(length > RAVE_SP_MAX_DATA_SIZE))

Oh, whoops, no, this should be:

+ if (unlikely(checksum_lengh > sizeof(crc_calculated))) {

(To validate the VLA max size.)

-Kees

Signature · 2 lines
Kees Cook
Pixel Security
#4 lore raw
Quoted 50 lines · Kees Cook
Quoted 49 lines · Lee Jones
Quoted 27 lines · 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

---
 drivers/mfd/rave-sp.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/mfd/rave-sp.c +3 -1
index 5c858e784a89..99fa482419f9 100644
@@ -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

drivers/mfd/rave-sp.c static void rave_sp_receive_frame(struct rave_sp *sp, · line 422

Quoted 7 lines
drivers/mfd/rave-sp.c +3 -1
@@ -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(length > sizeof(crc_calculated))) {

Forgive me if I have this wrong (it's still very early here), but this doesn't leave any room for the payload?

    <--       length         -->
    <ck len><- payload length ->
    [CK][CK][D][A][T][A] .. [64]

It is my hope that length would always be larger than the size of the checksum, or else there would never be any data?

Should this not be:

Quoted 7 lines
Quoted 1 line

if (unlikely(length > RAVE_SP_MAX_DATA_SIZE))

Oh, whoops, no, this should be:

+ if (unlikely(checksum_lengh > sizeof(crc_calculated))) {

(To validate the VLA max size.)

That doesn't match the OP's error message though:

  dev_warn(dev, "Dropping oversized frame\n");

Which I assume is designed to complement the existing warning:

  if (unlikely(length <= checksum_length))
          dev_warn(dev, "Dropping short frame\n");
Signature · 4 lines
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
#5 lore raw

The error message is also wrong. Would "Checksum length too large" be fine?

Quoted 3 lines · Lee Jones
Quoted 1 line · Kees Cook

On Mon, Apr 23, 2018 at 10:43 PM, Lee Jones <[email protected]>

Quoted 20 lines · wrote:
Quoted 20 lines
Quoted 20 lines · Kyle Spiers
Quoted 19 lines

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

---
 drivers/mfd/rave-sp.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/mfd/rave-sp.c +0 -0
index 5c858e784a89..99fa482419f9 100644
@@ -45,7 +45,9 @@
 #define RAVE_SP_DLE                  0x10
 
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

drivers/mfd/rave-sp.c line 48

Quoted 2 lines
drivers/mfd/rave-sp.c +0 -1
 #define RAVE_SP_MAX_DATA_SIZE                64
-#define RAVE_SP_CHECKSUM_SIZE                2  /* Worst case

scenario on RDU2 */

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/mfd/rave-sp.c static void rave_sp_receive_frame(struct

Quoted 7 lines
drivers/mfd/rave-sp.c +3 -0
+#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,

Quoted 42 lines
Quoted 20 lines
Quoted 20 lines

drivers/mfd/rave-sp.c static void rave_sp_receive_frame(struct rave_sp *sp, · line 422

Quoted 7 lines
drivers/mfd/rave-sp.c +3 -1
      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(length > sizeof(crc_calculated))) {

Forgive me if I have this wrong (it's still very early here), but this doesn't leave any room for the payload?

    <--       length         -->
    <ck len><- payload length ->
    [CK][CK][D][A][T][A] .. [64]

It is my hope that length would always be larger than the size of the checksum, or else there would never be any data?

Should this not be:

Quoted 7 lines
Quoted 1 line

if (unlikely(length > RAVE_SP_MAX_DATA_SIZE))

Oh, whoops, no, this should be:

+ if (unlikely(checksum_lengh > sizeof(crc_calculated))) {

(To validate the VLA max size.)

That doesn't match the OP's error message though:

   dev_warn(dev, "Dropping oversized frame\n");

Which I assume is designed to complement the existing warning:

   if (unlikely(length <= checksum_length))
           dev_warn(dev, "Dropping short frame\n");

--
Lee Jones [李琼斯]
Linaro Services Technical Lead

Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
#6 lore raw
Quoted 29 lines · Lee Jones
Quoted 4 lines · Kees Cook
Quoted 2 lines

On Mon, Apr 23, 2018 at 10:43 PM, Lee Jones <[email protected]>

Quoted 20 lines · wrote:
Quoted 20 lines
Quoted 20 lines · Kyle Spiers
Quoted 19 lines

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

---
 drivers/mfd/rave-sp.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/mfd/rave-sp.c +0 -0
index 5c858e784a89..99fa482419f9 100644
@@ -45,7 +45,9 @@
 #define RAVE_SP_DLE                  0x10
 
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

drivers/mfd/rave-sp.c line 48

Quoted 2 lines
drivers/mfd/rave-sp.c +0 -1
 #define RAVE_SP_MAX_DATA_SIZE                64
-#define RAVE_SP_CHECKSUM_SIZE                2  /* Worst case

scenario on RDU2 */

Quoted 44 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/mfd/rave-sp.c static void rave_sp_receive_frame(struct

Quoted 7 lines
drivers/mfd/rave-sp.c +3 -0
+#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,

Quoted 36 lines
Quoted 20 lines
Quoted 20 lines

drivers/mfd/rave-sp.c static void rave_sp_receive_frame(struct rave_sp *sp, · line 422

Quoted 7 lines
drivers/mfd/rave-sp.c +3 -1
      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(length > sizeof(crc_calculated))) {

Forgive me if I have this wrong (it's still very early here), but this doesn't leave any room for the payload?

    <--       length         -->
    <ck len><- payload length ->
    [CK][CK][D][A][T][A] .. [64]

It is my hope that length would always be larger than the size of the checksum, or else there would never be any data?

Should this not be:

Quoted 7 lines
Quoted 1 line

if (unlikely(length > RAVE_SP_MAX_DATA_SIZE))

Oh, whoops, no, this should be:

+ if (unlikely(checksum_lengh > sizeof(crc_calculated))) {

(To validate the VLA max size.)

That doesn't match the OP's error message though:

   dev_warn(dev, "Dropping oversized frame\n");

Which I assume is designed to complement the existing warning:

   if (unlikely(length <= checksum_length))
           dev_warn(dev, "Dropping short frame\n");

[MOVING - Please don't top post - reply in-line]

Quoted 1 line

The error message is also wrong. Would "Checksum length too large" be fine?

"Checksum too long, dropping" ?

Signature · 4 lines
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog