The HDMI specification defines the SPD InfoFrame Vendor Name and Product
Description as fixed-size fields, padded with zeros and left without any
trailing NUL when a name spans the whole field.
Mark the fields as non-strings, so that the copies can be handed over to
strtomem_pad(), which implements precisely the required semantics. This
also bounds the reads from the source strings, whereas the open-coded
strlen() could run past the end of the buffer in the
hdmi_spd_infoframe_unpack() path, where the names come straight from the
wire and are not NUL-terminated.
Fixes: 2c676f378edb ("[media] hdmi: added unpack and logging functions for InfoFrames")
Cc: <redacted> # v6.1+
Signed-off-by: Cristian Ciocaltea <redacted>
---
drivers/video/hdmi.c | 11 +++++------
include/linux/hdmi.h | 4 ++--
2 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/drivers/video/hdmi.c b/drivers/video/hdmi.c
index 45b42f14a750..cd18121afa20 100644
--- a/drivers/video/hdmi.c
+++ b/drivers/video/hdmi.c
@@ -217,23 +217,22 @@ EXPORT_SYMBOL(hdmi_avi_infoframe_pack);
* @vendor: vendor string
* @product: product string
*
+ * Both strings are copied into the fixed-size infoframe fields,
+ * truncated if too long and padded with zeros otherwise.
+ *
* Returns 0 on success or a negative error code on failure.
*/
int hdmi_spd_infoframe_init(struct hdmi_spd_infoframe *frame,
const char *vendor, const char *product)
{
- size_t len;
-
memset(frame, 0, sizeof(*frame));
frame->type = HDMI_INFOFRAME_TYPE_SPD;
frame->version = 1;
frame->length = HDMI_SPD_INFOFRAME_SIZE;
- len = strlen(vendor);
- memcpy(frame->vendor, vendor, min(len, sizeof(frame->vendor)));
- len = strlen(product);
- memcpy(frame->product, product, min(len, sizeof(frame->product)));
+ strtomem_pad(frame->vendor, vendor, 0);
+ strtomem_pad(frame->product, product, 0);
return 0;
}diff --git a/include/linux/hdmi.h b/include/linux/hdmi.h
index b80a5ee63bb2..08922d5330d6 100644
--- a/include/linux/hdmi.h
+++ b/include/linux/hdmi.h
@@ -271,8 +271,8 @@ struct hdmi_spd_infoframe {
enum hdmi_infoframe_type type;
unsigned char version;
unsigned char length;
- char vendor[8];
- char product[16];
+ char vendor[8] __nonstring;
+ char product[16] __nonstring;
enum hdmi_spd_sdi sdi;
};
--
2.56.0