From patchwork Wed Sep 8 19:39:56 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: mtd: sanity check input Date: Wed, 08 Sep 2010 09:39:56 -0000 From: Dan Carpenter X-Patchwork-Id: 64201 Message-Id: <20100908193956.GB3463@bicker> To: David Woodhouse Cc: Artem Bityutskiy , kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org, H Hartley Sweeten , linux-mtd@lists.infradead.org, Ben Hutchings , "Kirill A. Shutemov" If "ur_idx" is wrong we could go past the end of the array. The "ur_idx" comes from root so it's not a huge deal, but adding a sanity check makes the code more robust. Signed-off-by: Dan Carpenter diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index a825002..9c00549 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c @@ -513,6 +513,9 @@ static int mtd_ioctl(struct file *file, u_int cmd, u_long arg) if (get_user(ur_idx, &(ur->regionindex))) return -EFAULT; + if (ur_idx >= mtd->numeraseregions) + return -EINVAL; + kr = &(mtd->eraseregions[ur_idx]); if (put_user(kr->offset, &(ur->offset))