Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752489Ab3JZO7R (ORCPT ); Sat, 26 Oct 2013 10:59:17 -0400 Received: from mail-we0-f182.google.com ([74.125.82.182]:52313 "EHLO mail-we0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751683Ab3JZO7P (ORCPT ); Sat, 26 Oct 2013 10:59:15 -0400 From: Michal Nazarewicz To: Jean-Christophe Plagniol-Villard , Tomi Valkeinen Cc: linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] drivers: video: metronomefb: avoid out-of-bounds array access Date: Sat, 26 Oct 2013 15:58:48 +0100 Message-Id: <3c610da0d5b555453d5295aae720042f1c065cab.1382791126.git.mina86@mina86.com> X-Mailer: git-send-email 1.8.4 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2213 Lines: 75 From: Michal Nazarewicz 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. Signed-off-by: Michal Nazarewicz --- 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 f30150d..44ef8b0 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.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/