linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [patch] mtd: sanity check input
@ 2010-09-08 19:39 Dan Carpenter
  2010-09-13  8:53 ` Artem Bityutskiy
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2010-09-08 19:39 UTC (permalink / raw)
  To: David Woodhouse
  Cc: Artem Bityutskiy, kernel-janitors, linux-kernel,
	H Hartley Sweeten, linux-mtd, 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 <error27@gmail.com>

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))

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-09-13  8:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-08 19:39 [patch] mtd: sanity check input Dan Carpenter
2010-09-13  8:53 ` Artem Bityutskiy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).