Skip to contentSkip to conversation

rave-sp: Remove VLA

PATCH Applied Kyle Spiers 3 participants 3 messages Apr 27, 2018 – Apr 30, 2018 Multifunction devices (MFD)

lore
Share & tools
lore
#0 lore raw

PATCH v2 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..4ce96b7137db 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(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);
Signature · 1 line
2.17.0.441.gb46fe60e1d-goog
Applied
#1 lore raw
Quoted 10 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(-)

Applied, thanks.

Kees, do you want me to add your Ack?

Quoted 29 lines
drivers/mfd/rave-sp.c +9 -2
index 5c858e784a89..4ce96b7137db 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(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);
Signature · 4 lines
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
Reviewed-by
#2 lore raw
Quoted 8 lines · Lee Jones
Quoted 6 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

Quoted 8 lines
Quoted 4 lines
---
 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!

Thanks!

-Kees

Quoted 36 lines
Quoted 20 lines
drivers/mfd/rave-sp.c +3 -1
index 5c858e784a89..4ce96b7137db 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;

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

Quoted 10 lines
drivers/mfd/rave-sp.c +6 -1
-     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
Signature · 2 lines
Kees Cook
Pixel Security