Skip to contentSkip to conversation

ALSA: pcm: Avoid reading beyond ELD monitor name

PATCH Applied Sreeraj S Kurup 2 participants 3 messages Nov 20 – Nov 21 Sound

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ALSA: pcm: Avoid reading beyond ELD monitor name

snd_parse_eld() checks that mnl bytes are available in the ELD buffer, but passes mnl + 1 as the source size to strscpy().

When the monitor name is not NUL-terminated and the buffer ends immediately after the mnl bytes, strscpy() may read beyond the provided buffer.

Copy exactly mnl bytes and explicitly terminate the destination to avoid accessing a byte beyond the validated input length.

---
 sound/core/pcm_drm_eld.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
sound/core/pcm_drm_eld.c +4 -2
index 1941ee520063..556e5a43710d 100644
@@ -362,8 +362,10 @@ int snd_parse_eld(struct device *dev, struct snd_parsed_hdmi_eld *e,
 	} else if (ELD_FIXED_BYTES + mnl > size) {
 		dev_info(dev, "HDMI: out of range MNL %d\n", mnl);
 		goto out_fail;
-	} else
-		strscpy(e->monitor_name, buf + ELD_FIXED_BYTES, mnl + 1);
+	} else {
+		memcpy(e->monitor_name, buf + ELD_FIXED_BYTES, mnl);
+		e->monitor_name[mnl] = '\0';
+	}
 
 	for (i = 0; i < e->sad_count; i++) {
 		if (ELD_FIXED_BYTES + mnl + 3 * (i + 1) > size) {
Signature · 1 line
2.55.0
Applied
#1 lore raw
Quoted 4 lines · Sreeraj S Kurup

snd_parse_eld() checks that mnl bytes are available in the ELD buffer, but passes mnl + 1 as the source size to strscpy().

Quoted 8 lines

When the monitor name is not NUL-terminated and the buffer ends immediately after the mnl bytes, strscpy() may read beyond the provided buffer.

Copy exactly mnl bytes and explicitly terminate the destination to avoid accessing a byte beyond the validated input length.

Applied to for-next branch. Thanks.

Takashi