Skip to content

Commit 8c6657c

Browse files
author
Al Viro
committed
Switch flock copyin/copyout primitives to copy_{from,to}_user()
... and lose HAVE_ARCH_...; if copy_{to,from}_user() on an architecture sucks badly enough to make it a problem, we have a worse problem. Signed-off-by: Al Viro <[email protected]>
1 parent ca1579f commit 8c6657c

File tree

1 file changed

+29
-30
lines changed

1 file changed

+29
-30
lines changed

fs/fcntl.c

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -452,57 +452,56 @@ SYSCALL_DEFINE3(fcntl64, unsigned int, fd, unsigned int, cmd,
452452
#endif
453453

454454
#ifdef CONFIG_COMPAT
455+
/* careful - don't use anywhere else */
456+
#define copy_flock_fields(from, to) \
457+
(to).l_type = (from).l_type; \
458+
(to).l_whence = (from).l_whence; \
459+
(to).l_start = (from).l_start; \
460+
(to).l_len = (from).l_len; \
461+
(to).l_pid = (from).l_pid;
462+
455463
static int get_compat_flock(struct flock *kfl, struct compat_flock __user *ufl)
456464
{
457-
if (!access_ok(VERIFY_READ, ufl, sizeof(*ufl)) ||
458-
__get_user(kfl->l_type, &ufl->l_type) ||
459-
__get_user(kfl->l_whence, &ufl->l_whence) ||
460-
__get_user(kfl->l_start, &ufl->l_start) ||
461-
__get_user(kfl->l_len, &ufl->l_len) ||
462-
__get_user(kfl->l_pid, &ufl->l_pid))
465+
struct compat_flock fl;
466+
467+
if (copy_from_user(&fl, ufl, sizeof(struct compat_flock)))
463468
return -EFAULT;
469+
copy_flock_fields(*kfl, fl);
464470
return 0;
465471
}
466472

467-
static int put_compat_flock(struct flock *kfl, struct compat_flock __user *ufl)
473+
static int get_compat_flock64(struct flock *kfl, struct compat_flock64 __user *ufl)
468474
{
469-
if (!access_ok(VERIFY_WRITE, ufl, sizeof(*ufl)) ||
470-
__put_user(kfl->l_type, &ufl->l_type) ||
471-
__put_user(kfl->l_whence, &ufl->l_whence) ||
472-
__put_user(kfl->l_start, &ufl->l_start) ||
473-
__put_user(kfl->l_len, &ufl->l_len) ||
474-
__put_user(kfl->l_pid, &ufl->l_pid))
475+
struct compat_flock64 fl;
476+
477+
if (copy_from_user(&fl, ufl, sizeof(struct compat_flock64)))
475478
return -EFAULT;
479+
copy_flock_fields(*kfl, fl);
476480
return 0;
477481
}
478482

479-
#ifndef HAVE_ARCH_GET_COMPAT_FLOCK64
480-
static int get_compat_flock64(struct flock *kfl, struct compat_flock64 __user *ufl)
483+
static int put_compat_flock(struct flock *kfl, struct compat_flock __user *ufl)
481484
{
482-
if (!access_ok(VERIFY_READ, ufl, sizeof(*ufl)) ||
483-
__get_user(kfl->l_type, &ufl->l_type) ||
484-
__get_user(kfl->l_whence, &ufl->l_whence) ||
485-
__get_user(kfl->l_start, &ufl->l_start) ||
486-
__get_user(kfl->l_len, &ufl->l_len) ||
487-
__get_user(kfl->l_pid, &ufl->l_pid))
485+
struct compat_flock fl;
486+
487+
memset(&fl, 0, sizeof(struct compat_flock));
488+
copy_flock_fields(fl, *kfl);
489+
if (copy_to_user(ufl, &fl, sizeof(struct compat_flock)))
488490
return -EFAULT;
489491
return 0;
490492
}
491-
#endif
492493

493-
#ifndef HAVE_ARCH_PUT_COMPAT_FLOCK64
494494
static int put_compat_flock64(struct flock *kfl, struct compat_flock64 __user *ufl)
495495
{
496-
if (!access_ok(VERIFY_WRITE, ufl, sizeof(*ufl)) ||
497-
__put_user(kfl->l_type, &ufl->l_type) ||
498-
__put_user(kfl->l_whence, &ufl->l_whence) ||
499-
__put_user(kfl->l_start, &ufl->l_start) ||
500-
__put_user(kfl->l_len, &ufl->l_len) ||
501-
__put_user(kfl->l_pid, &ufl->l_pid))
496+
struct compat_flock64 fl;
497+
498+
memset(&fl, 0, sizeof(struct compat_flock64));
499+
copy_flock_fields(fl, *kfl);
500+
if (copy_to_user(ufl, &fl, sizeof(struct compat_flock64)))
502501
return -EFAULT;
503502
return 0;
504503
}
505-
#endif
504+
#undef copy_flock_fields
506505

507506
static unsigned int
508507
convert_fcntl_cmd(unsigned int cmd)

0 commit comments

Comments
 (0)