diff options
author | Zev Weiss <zevweiss@gmail.com> | 2008-09-01 08:02:12 -0400 |
---|---|---|
committer | David Woodhouse <David.Woodhouse@intel.com> | 2008-09-02 04:29:05 -0400 |
commit | b67c5f87c13f398ec3f4d6b455cb0bbeda8d7ac0 (patch) | |
tree | fc2ebe12c5b34439b9034742f957177111409cc7 /drivers/mtd | |
parent | 02c0267a40c876a4d70f2000f21fe9ff89fb988e (diff) |
[MTD] mtdchar.c: Fix regression in MEMGETREGIONINFO ioctl()
The MEMGETREGIONINFO ioctl() in mtdchar.c was clobbering user memory by
overwriting more than intended, due the size of struct mtd_erase_region_info
changing in commit 0ecbc81adfcb9f15f86b05ff576b342ce81bbef8 ('Support
for auto locking flash on power up').
Fix avoids this by copying struct members one by one with put_user(), as there
is no longer a convenient struct to use the size of as the length argument to
copy_to_user().
Signed-off-by: Zev Weiss <zevweiss@gmail.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Diffstat (limited to 'drivers/mtd')
-rw-r--r-- | drivers/mtd/mtdchar.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index d2f331876e4c..e00d424e6575 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c | |||
@@ -410,16 +410,20 @@ static int mtd_ioctl(struct inode *inode, struct file *file, | |||
410 | 410 | ||
411 | case MEMGETREGIONINFO: | 411 | case MEMGETREGIONINFO: |
412 | { | 412 | { |
413 | struct region_info_user ur; | 413 | uint32_t ur_idx; |
414 | struct mtd_erase_region_info *kr; | ||
415 | struct region_info_user *ur = (struct region_info_user *) argp; | ||
414 | 416 | ||
415 | if (copy_from_user(&ur, argp, sizeof(struct region_info_user))) | 417 | if (get_user(ur_idx, &(ur->regionindex))) |
416 | return -EFAULT; | 418 | return -EFAULT; |
417 | 419 | ||
418 | if (ur.regionindex >= mtd->numeraseregions) | 420 | kr = &(mtd->eraseregions[ur_idx]); |
419 | return -EINVAL; | 421 | |
420 | if (copy_to_user(argp, &(mtd->eraseregions[ur.regionindex]), | 422 | if (put_user(kr->offset, &(ur->offset)) |
421 | sizeof(struct mtd_erase_region_info))) | 423 | || put_user(kr->erasesize, &(ur->erasesize)) |
424 | || put_user(kr->numblocks, &(ur->numblocks))) | ||
422 | return -EFAULT; | 425 | return -EFAULT; |
426 | |||
423 | break; | 427 | break; |
424 | } | 428 | } |
425 | 429 | ||