aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/ioctl.c
diff options
context:
space:
mode:
authorJulia Lawall <julia@diku.dk>2010-10-29 15:14:18 -0400
committerChris Mason <chris.mason@oracle.com>2010-10-29 15:14:18 -0400
commit2354d08fe9aeec3e451b85cb5387a6b28dbca0b1 (patch)
tree7a3f43dfac81fc54faf231400a4b871ca24bb031 /fs/btrfs/ioctl.c
parent18e503d695ff8ff9a43768555aa74575bf6b77f3 (diff)
Btrfs: use memdup_user helpers
Use memdup_user when user data is immediately copied into the allocated region. The semantic patch that makes this change is as follows: (http://coccinelle.lip6.fr/) // <smpl> @@ expression from,to,size,flag; position p; identifier l1,l2; @@ - to = \(kmalloc@p\|kzalloc@p\)(size,flag); + to = memdup_user(from,size); if ( - to==NULL + IS_ERR(to) || ...) { <+... when != goto l1; - -ENOMEM + PTR_ERR(to) ...+> } - if (copy_from_user(to, from, size) != 0) { - <+... when != goto l2; - -EFAULT - ...+> - } // </smpl> Signed-off-by: Julia Lawall <julia@diku.dk> Cc: Chris Mason <chris.mason@oracle.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/ioctl.c')
-rw-r--r--fs/btrfs/ioctl.c20
1 files changed, 6 insertions, 14 deletions
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index db0b8fc59235..8079ebfeaf50 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -1073,14 +1073,10 @@ static noinline int btrfs_ioctl_tree_search(struct file *file,
1073 if (!capable(CAP_SYS_ADMIN)) 1073 if (!capable(CAP_SYS_ADMIN))
1074 return -EPERM; 1074 return -EPERM;
1075 1075
1076 args = kmalloc(sizeof(*args), GFP_KERNEL); 1076 args = memdup_user(argp, sizeof(*args));
1077 if (!args) 1077 if (IS_ERR(args))
1078 return -ENOMEM; 1078 return PTR_ERR(args);
1079 1079
1080 if (copy_from_user(args, argp, sizeof(*args))) {
1081 kfree(args);
1082 return -EFAULT;
1083 }
1084 inode = fdentry(file)->d_inode; 1080 inode = fdentry(file)->d_inode;
1085 ret = search_ioctl(inode, args); 1081 ret = search_ioctl(inode, args);
1086 if (ret == 0 && copy_to_user(argp, args, sizeof(*args))) 1082 if (ret == 0 && copy_to_user(argp, args, sizeof(*args)))
@@ -1188,14 +1184,10 @@ static noinline int btrfs_ioctl_ino_lookup(struct file *file,
1188 if (!capable(CAP_SYS_ADMIN)) 1184 if (!capable(CAP_SYS_ADMIN))
1189 return -EPERM; 1185 return -EPERM;
1190 1186
1191 args = kmalloc(sizeof(*args), GFP_KERNEL); 1187 args = memdup_user(argp, sizeof(*args));
1192 if (!args) 1188 if (IS_ERR(args))
1193 return -ENOMEM; 1189 return PTR_ERR(args);
1194 1190
1195 if (copy_from_user(args, argp, sizeof(*args))) {
1196 kfree(args);
1197 return -EFAULT;
1198 }
1199 inode = fdentry(file)->d_inode; 1191 inode = fdentry(file)->d_inode;
1200 1192
1201 if (args->treeid == 0) 1193 if (args->treeid == 0)