From: Michal Nazarewicz <mpn@google.com> To: Jean-Christophe Plagniol-Villard <plagnioj@jcrosoft.com>, Tomi Valkeinen <tomi.valkeinen@ti.com> Cc: linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] drivers: video: metronomefb: avoid out-of-bounds array access Date: Sun, 10 Nov 2013 19:38:38 +0100 [thread overview] Message-ID: <1384108718-23637-1-git-send-email-mpn@google.com> (raw) From: Michal Nazarewicz <mina86@mina86.com> load_waveform function checks whether padding bytes in stuff2a and stuff2b are all zero, but does so by treating those arrays as a single longer array. Since the structure is packed, and the size sum matches, it all works, but creates some confusion in the code. This commit changes the stuff2a and stuff2b arrays into pad1 and pad2 fields such that they cover the same bytes as the arrays covered, and changes the check in the load_waveform function so that the fields are read instead of iterating over an arary. It also renames the other “stuff” fields to “ignore*” fields to give them more semantic meaning. --- drivers/video/metronomefb.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/drivers/video/metronomefb.c b/drivers/video/metronomefb.c index 195cc2d..4f36a2b 100644 --- a/drivers/video/metronomefb.c +++ b/drivers/video/metronomefb.c @@ -126,7 +126,7 @@ static struct fb_var_screeninfo metronomefb_var = { /* the waveform structure that is coming from userspace firmware */ struct waveform_hdr { - u8 stuff[32]; + u8 ignore1[32]; u8 wmta[3]; u8 fvsn; @@ -134,13 +134,14 @@ struct waveform_hdr { u8 luts; u8 mc; u8 trc; - u8 stuff3; + u8 ignore2; u8 endb; u8 swtb; - u8 stuff2a[2]; + u32 pad1; /* u16 halfof(pad1) */ - u8 stuff2b[3]; + /* u16 halfof(pad1) */ + u8 pad2; u8 wfm_cs; } __attribute__ ((packed)); @@ -210,11 +211,9 @@ static int load_waveform(u8 *mem, size_t size, int m, int t, } wfm_hdr->mc += 1; wfm_hdr->trc += 1; - for (i = 0; i < 5; i++) { - if (*(wfm_hdr->stuff2a + i) != 0) { - dev_err(dev, "Error: unexpected value in padding\n"); - return -EINVAL; - } + if (wfm_hdr->pad1 || wfm_hdr->pad2) { + dev_err(dev, "Error: unexpected value in padding\n"); + return -EINVAL; } /* calculating trn. trn is something used to index into -- 1.8.3.2
WARNING: multiple messages have this Message-ID (diff)
From: Michal Nazarewicz <mpn@google.com> To: Jean-Christophe Plagniol-Villard <plagnioj@jcrosoft.com>, Tomi Valkeinen <tomi.valkeinen@ti.com> Cc: linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] drivers: video: metronomefb: avoid out-of-bounds array access Date: Sun, 10 Nov 2013 18:38:38 +0000 [thread overview] Message-ID: <1384108718-23637-1-git-send-email-mpn@google.com> (raw) In-Reply-To: <3c610da0d5b555453d5295aae720042f1c065cab.1382791126.git.mina86@mina86.com> From: Michal Nazarewicz <mina86@mina86.com> load_waveform function checks whether padding bytes in stuff2a and stuff2b are all zero, but does so by treating those arrays as a single longer array. Since the structure is packed, and the size sum matches, it all works, but creates some confusion in the code. This commit changes the stuff2a and stuff2b arrays into pad1 and pad2 fields such that they cover the same bytes as the arrays covered, and changes the check in the load_waveform function so that the fields are read instead of iterating over an arary. It also renames the other “stuff” fields to “ignore*” fields to give them more semantic meaning. --- drivers/video/metronomefb.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/drivers/video/metronomefb.c b/drivers/video/metronomefb.c index 195cc2d..4f36a2b 100644 --- a/drivers/video/metronomefb.c +++ b/drivers/video/metronomefb.c @@ -126,7 +126,7 @@ static struct fb_var_screeninfo metronomefb_var = { /* the waveform structure that is coming from userspace firmware */ struct waveform_hdr { - u8 stuff[32]; + u8 ignore1[32]; u8 wmta[3]; u8 fvsn; @@ -134,13 +134,14 @@ struct waveform_hdr { u8 luts; u8 mc; u8 trc; - u8 stuff3; + u8 ignore2; u8 endb; u8 swtb; - u8 stuff2a[2]; + u32 pad1; /* u16 halfof(pad1) */ - u8 stuff2b[3]; + /* u16 halfof(pad1) */ + u8 pad2; u8 wfm_cs; } __attribute__ ((packed)); @@ -210,11 +211,9 @@ static int load_waveform(u8 *mem, size_t size, int m, int t, } wfm_hdr->mc += 1; wfm_hdr->trc += 1; - for (i = 0; i < 5; i++) { - if (*(wfm_hdr->stuff2a + i) != 0) { - dev_err(dev, "Error: unexpected value in padding\n"); - return -EINVAL; - } + if (wfm_hdr->pad1 || wfm_hdr->pad2) { + dev_err(dev, "Error: unexpected value in padding\n"); + return -EINVAL; } /* calculating trn. trn is something used to index into -- 1.8.3.2
next reply other threads:[~2013-11-10 18:38 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2013-11-10 18:38 Michal Nazarewicz [this message] 2013-11-10 18:38 ` [PATCH] drivers: video: metronomefb: avoid out-of-bounds array access Michal Nazarewicz -- strict thread matches above, loose matches on Subject: below -- 2013-10-26 14:58 Michal Nazarewicz 2013-10-26 14:58 ` Michal Nazarewicz
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=1384108718-23637-1-git-send-email-mpn@google.com \ --to=mpn@google.com \ --cc=linux-fbdev@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=plagnioj@jcrosoft.com \ --cc=tomi.valkeinen@ti.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.