Skip to contentSkip to conversation

firmware: cs_dsp: Use strnlen() on name fields in V1 wmfw files

PATCH In review Richard Fitzgerald 1 participant 2 messages Jul 8, 2024

Subsystems (2)
lore
Share & tools
lore

Richard Fitzgerald

author maintainer
#0 lore raw

PATCH v2 1/1 firmware: cs_dsp: Use strnlen() on name fields in V1 wmfw files

Use strnlen() instead of strlen() on the algorithm and coefficient name string arrays in V1 wmfw files.

In V1 wmfw files the name is a NUL-terminated string in a fixed-size array. cs_dsp should protect against overrunning the array if the NUL terminator is missing.

Fixes f6bc909e7673 ("firmware: cs_dsp: add driver to support firmware loading on Cirrus Logic DSPs")
---
 drivers/firmware/cirrus/cs_dsp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/firmware/cirrus/cs_dsp.c +2 -2
index 16484ab9b09d..8a347b938406 100644
@@ -1183,4 +1183,4 @@ static int cs_dsp_coeff_parse_alg(struct cs_dsp *dsp,
 		blk->id = le32_to_cpu(raw->id);
 		blk->name = raw->name;
-		blk->name_len = strlen(raw->name);
+		blk->name_len = strnlen(raw->name, ARRAY_SIZE(raw->name));
 		blk->ncoeff = le32_to_cpu(raw->ncoeff);
@@ -1260,4 +1260,4 @@ static int cs_dsp_coeff_parse_coeff(struct cs_dsp *dsp,
 		blk->name = raw->name;
-		blk->name_len = strlen(raw->name);
+		blk->name_len = strnlen(raw->name, ARRAY_SIZE(raw->name));
 		blk->ctl_type = le16_to_cpu(raw->ctl_type);
 		blk->flags = le16_to_cpu(raw->flags);
Signature · 1 line
2.39.2
author maintainer
#1 lore raw
Quoted 24 lines · Richard Fitzgerald

Use strnlen() instead of strlen() on the algorithm and coefficient name string arrays in V1 wmfw files.

In V1 wmfw files the name is a NUL-terminated string in a fixed-size array. cs_dsp should protect against overrunning the array if the NUL terminator is missing.

Fixes f6bc909e7673 ("firmware: cs_dsp: add driver to support firmware loading on Cirrus Logic DSPs")
---
  drivers/firmware/cirrus/cs_dsp.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/firmware/cirrus/cs_dsp.c +1 -1
index 16484ab9b09d..8a347b938406 100644
@@ -1183,4 +1183,4 @@ static int cs_dsp_coeff_parse_alg(struct cs_dsp *dsp,
  		blk->id = le32_to_cpu(raw->id);
  		blk->name = raw->name;
-		blk->name_len = strlen(raw->name);
+		blk->name_len = strnlen(raw->name, ARRAY_SIZE(raw->name));
  		blk->ncoeff = le32_to_cpu(raw->ncoeff);

drivers/firmware/cirrus/cs_dsp.c static int cs_dsp_coeff_parse_coeff(struct cs_dsp *dsp, · line 1263

Quoted 5 lines
drivers/firmware/cirrus/cs_dsp.c +1 -1
@@ -1260,4 +1260,4 @@ static int cs_dsp_coeff_parse_coeff(struct cs_dsp *dsp,
  		blk->name = raw->name;
-		blk->name_len = strlen(raw->name);
+		blk->name_len = strnlen(raw->name, ARRAY_SIZE(raw->name));
  		blk->ctl_type = le16_to_cpu(raw->ctl_type);
  		blk->flags = le16_to_cpu(raw->flags);

This is the same patch as V1 but with a couple of conflicting lines dropped from the context. You can ignore this V2 if you've got V1 to apply cleanly.

Sorry for the confusion.