Skip to content

Commit

Permalink
futex: arch_futex_atomic_op_inuser() calling conventions change
Browse files Browse the repository at this point in the history
Move access_ok() in and pagefault_enable()/pagefault_disable() out.
Mechanical conversion only - some instances don't really need
a separate access_ok() at all (e.g. the ones only using
get_user()/put_user(), or architectures where access_ok()
is always true); we'll deal with that in followups.

Signed-off-by: Al Viro <[email protected]>
  • Loading branch information
Al Viro committed Mar 28, 2020
1 parent bb6d3fb commit a08971e
Show file tree
Hide file tree
Showing 20 changed files with 43 additions and 57 deletions.
5 changes: 2 additions & 3 deletions arch/alpha/include/asm/futex.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ static inline int arch_futex_atomic_op_inuser(int op, int oparg, int *oval,
{
int oldval = 0, ret;

pagefault_disable();
if (!access_ok(uaddr, sizeof(u32)))
return -EFAULT;

switch (op) {
case FUTEX_OP_SET:
Expand All @@ -53,8 +54,6 @@ static inline int arch_futex_atomic_op_inuser(int op, int oparg, int *oval,
ret = -ENOSYS;
}

pagefault_enable();

if (!ret)
*oval = oldval;

Expand Down
5 changes: 3 additions & 2 deletions arch/arc/include/asm/futex.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,12 @@ static inline int arch_futex_atomic_op_inuser(int op, int oparg, int *oval,
{
int oldval = 0, ret;

if (!access_ok(uaddr, sizeof(u32)))
return -EFAULT;

#ifndef CONFIG_ARC_HAS_LLSC
preempt_disable(); /* to guarantee atomic r-m-w of futex op */
#endif
pagefault_disable();

switch (op) {
case FUTEX_OP_SET:
Expand All @@ -101,7 +103,6 @@ static inline int arch_futex_atomic_op_inuser(int op, int oparg, int *oval,
ret = -ENOSYS;
}

pagefault_enable();
#ifndef CONFIG_ARC_HAS_LLSC
preempt_enable();
#endif
Expand Down
5 changes: 3 additions & 2 deletions arch/arm/include/asm/futex.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,12 @@ arch_futex_atomic_op_inuser(int op, int oparg, int *oval, u32 __user *uaddr)
{
int oldval = 0, ret, tmp;

if (!access_ok(uaddr, sizeof(u32)))
return -EFAULT;

#ifndef CONFIG_SMP
preempt_disable();
#endif
pagefault_disable();

switch (op) {
case FUTEX_OP_SET:
Expand All @@ -159,7 +161,6 @@ arch_futex_atomic_op_inuser(int op, int oparg, int *oval, u32 __user *uaddr)
ret = -ENOSYS;
}

pagefault_enable();
#ifndef CONFIG_SMP
preempt_enable();
#endif
Expand Down
5 changes: 2 additions & 3 deletions arch/arm64/include/asm/futex.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ arch_futex_atomic_op_inuser(int op, int oparg, int *oval, u32 __user *_uaddr)
int oldval = 0, ret, tmp;
u32 __user *uaddr = __uaccess_mask_ptr(_uaddr);

pagefault_disable();
if (!access_ok(_uaddr, sizeof(u32)))
return -EFAULT;

switch (op) {
case FUTEX_OP_SET:
Expand All @@ -75,8 +76,6 @@ arch_futex_atomic_op_inuser(int op, int oparg, int *oval, u32 __user *_uaddr)
ret = -ENOSYS;
}

pagefault_enable();

if (!ret)
*oval = oldval;

Expand Down
5 changes: 2 additions & 3 deletions arch/hexagon/include/asm/futex.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ arch_futex_atomic_op_inuser(int op, int oparg, int *oval, u32 __user *uaddr)
{
int oldval = 0, ret;

pagefault_disable();
if (!access_ok(uaddr, sizeof(u32)))
return -EFAULT;

switch (op) {
case FUTEX_OP_SET:
Expand All @@ -62,8 +63,6 @@ arch_futex_atomic_op_inuser(int op, int oparg, int *oval, u32 __user *uaddr)
ret = -ENOSYS;
}

pagefault_enable();

if (!ret)
*oval = oldval;

Expand Down
5 changes: 2 additions & 3 deletions arch/ia64/include/asm/futex.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ arch_futex_atomic_op_inuser(int op, int oparg, int *oval, u32 __user *uaddr)
{
int oldval = 0, ret;

pagefault_disable();
if (!access_ok(uaddr, sizeof(u32)))
return -EFAULT;

switch (op) {
case FUTEX_OP_SET:
Expand All @@ -74,8 +75,6 @@ arch_futex_atomic_op_inuser(int op, int oparg, int *oval, u32 __user *uaddr)
ret = -ENOSYS;
}

pagefault_enable();

if (!ret)
*oval = oldval;

Expand Down
5 changes: 2 additions & 3 deletions arch/microblaze/include/asm/futex.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ arch_futex_atomic_op_inuser(int op, int oparg, int *oval, u32 __user *uaddr)
{
int oldval = 0, ret;

pagefault_disable();
if (!access_ok(uaddr, sizeof(u32)))
return -EFAULT;

switch (op) {
case FUTEX_OP_SET:
Expand All @@ -56,8 +57,6 @@ arch_futex_atomic_op_inuser(int op, int oparg, int *oval, u32 __user *uaddr)
ret = -ENOSYS;
}

pagefault_enable();

if (!ret)
*oval = oldval;

Expand Down
5 changes: 2 additions & 3 deletions arch/mips/include/asm/futex.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ arch_futex_atomic_op_inuser(int op, int oparg, int *oval, u32 __user *uaddr)
{
int oldval = 0, ret;

pagefault_disable();
if (!access_ok(uaddr, sizeof(u32)))
return -EFAULT;

switch (op) {
case FUTEX_OP_SET:
Expand All @@ -116,8 +117,6 @@ arch_futex_atomic_op_inuser(int op, int oparg, int *oval, u32 __user *uaddr)
ret = -ENOSYS;
}

pagefault_enable();

if (!ret)
*oval = oldval;

Expand Down
6 changes: 2 additions & 4 deletions arch/nds32/include/asm/futex.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ arch_futex_atomic_op_inuser(int op, int oparg, int *oval, u32 __user *uaddr)
{
int oldval = 0, ret;


pagefault_disable();
if (!access_ok(uaddr, sizeof(u32)))
return -EFAULT;
switch (op) {
case FUTEX_OP_SET:
__futex_atomic_op("move %0, %3", ret, oldval, tmp, uaddr,
Expand All @@ -93,8 +93,6 @@ arch_futex_atomic_op_inuser(int op, int oparg, int *oval, u32 __user *uaddr)
ret = -ENOSYS;
}

pagefault_enable();

if (!ret)
*oval = oldval;

Expand Down
5 changes: 2 additions & 3 deletions arch/openrisc/include/asm/futex.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ arch_futex_atomic_op_inuser(int op, int oparg, int *oval, u32 __user *uaddr)
{
int oldval = 0, ret;

pagefault_disable();
if (!access_ok(uaddr, sizeof(u32)))
return -EFAULT;

switch (op) {
case FUTEX_OP_SET:
Expand All @@ -57,8 +58,6 @@ arch_futex_atomic_op_inuser(int op, int oparg, int *oval, u32 __user *uaddr)
ret = -ENOSYS;
}

pagefault_enable();

if (!ret)
*oval = oldval;

Expand Down
5 changes: 3 additions & 2 deletions arch/parisc/include/asm/futex.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ arch_futex_atomic_op_inuser(int op, int oparg, int *oval, u32 __user *uaddr)
int oldval, ret;
u32 tmp;

if (!access_ok(uaddr, sizeof(u32)))
return -EFAULT;

_futex_spin_lock_irqsave(uaddr, &flags);
pagefault_disable();

ret = -EFAULT;
if (unlikely(get_user(oldval, uaddr) != 0))
Expand Down Expand Up @@ -73,7 +75,6 @@ arch_futex_atomic_op_inuser(int op, int oparg, int *oval, u32 __user *uaddr)
ret = -EFAULT;

out_pagefault_enable:
pagefault_enable();
_futex_spin_unlock_irqrestore(uaddr, &flags);

if (!ret)
Expand Down
5 changes: 2 additions & 3 deletions arch/powerpc/include/asm/futex.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ static inline int arch_futex_atomic_op_inuser(int op, int oparg, int *oval,
{
int oldval = 0, ret;

if (!access_ok(uaddr, sizeof(u32)))
return -EFAULT;
allow_read_write_user(uaddr, uaddr, sizeof(*uaddr));
pagefault_disable();

switch (op) {
case FUTEX_OP_SET:
Expand All @@ -58,8 +59,6 @@ static inline int arch_futex_atomic_op_inuser(int op, int oparg, int *oval,
ret = -ENOSYS;
}

pagefault_enable();

*oval = oldval;

prevent_read_write_user(uaddr, uaddr, sizeof(*uaddr));
Expand Down
5 changes: 2 additions & 3 deletions arch/riscv/include/asm/futex.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ arch_futex_atomic_op_inuser(int op, int oparg, int *oval, u32 __user *uaddr)
{
int oldval = 0, ret = 0;

pagefault_disable();
if (!access_ok(uaddr, sizeof(u32)))
return -EFAULT;

switch (op) {
case FUTEX_OP_SET:
Expand All @@ -73,8 +74,6 @@ arch_futex_atomic_op_inuser(int op, int oparg, int *oval, u32 __user *uaddr)
ret = -ENOSYS;
}

pagefault_enable();

if (!ret)
*oval = oldval;

Expand Down
4 changes: 2 additions & 2 deletions arch/s390/include/asm/futex.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ static inline int arch_futex_atomic_op_inuser(int op, int oparg, int *oval,
int oldval = 0, newval, ret;
mm_segment_t old_fs;

if (!access_ok(uaddr, sizeof(u32)))
return -EFAULT;
old_fs = enable_sacf_uaccess();
pagefault_disable();
switch (op) {
case FUTEX_OP_SET:
__futex_atomic_op("lr %2,%5\n",
Expand All @@ -54,7 +55,6 @@ static inline int arch_futex_atomic_op_inuser(int op, int oparg, int *oval,
default:
ret = -ENOSYS;
}
pagefault_enable();
disable_sacf_uaccess(old_fs);

if (!ret)
Expand Down
5 changes: 2 additions & 3 deletions arch/sh/include/asm/futex.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ static inline int arch_futex_atomic_op_inuser(int op, u32 oparg, int *oval,
u32 oldval, newval, prev;
int ret;

pagefault_disable();
if (!access_ok(uaddr, sizeof(u32)))
return -EFAULT;

do {
ret = get_user(oldval, uaddr);
Expand Down Expand Up @@ -67,8 +68,6 @@ static inline int arch_futex_atomic_op_inuser(int op, u32 oparg, int *oval,
ret = futex_atomic_cmpxchg_inatomic(&prev, uaddr, oldval, newval);
} while (!ret && prev != oldval);

pagefault_enable();

if (!ret)
*oval = oldval;

Expand Down
6 changes: 2 additions & 4 deletions arch/sparc/include/asm/futex_64.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ static inline int arch_futex_atomic_op_inuser(int op, int oparg, int *oval,
{
int oldval = 0, ret, tem;

if (!access_ok(uaddr, sizeof(u32)))
return -EFAULT;
if (unlikely((((unsigned long) uaddr) & 0x3UL)))
return -EINVAL;

pagefault_disable();

switch (op) {
case FUTEX_OP_SET:
__futex_cas_op("mov\t%4, %1", ret, oldval, uaddr, oparg);
Expand All @@ -60,8 +60,6 @@ static inline int arch_futex_atomic_op_inuser(int op, int oparg, int *oval,
ret = -ENOSYS;
}

pagefault_enable();

if (!ret)
*oval = oldval;

Expand Down
5 changes: 2 additions & 3 deletions arch/x86/include/asm/futex.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ static inline int arch_futex_atomic_op_inuser(int op, int oparg, int *oval,
{
int oldval = 0, ret, tem;

pagefault_disable();
if (!access_ok(uaddr, sizeof(u32)))
return -EFAULT;

switch (op) {
case FUTEX_OP_SET:
Expand All @@ -70,8 +71,6 @@ static inline int arch_futex_atomic_op_inuser(int op, int oparg, int *oval,
ret = -ENOSYS;
}

pagefault_enable();

if (!ret)
*oval = oldval;

Expand Down
5 changes: 2 additions & 3 deletions arch/xtensa/include/asm/futex.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ static inline int arch_futex_atomic_op_inuser(int op, int oparg, int *oval,
#if XCHAL_HAVE_S32C1I || XCHAL_HAVE_EXCLUSIVE
int oldval = 0, ret;

pagefault_disable();
if (!access_ok(uaddr, sizeof(u32)))
return -EFAULT;

switch (op) {
case FUTEX_OP_SET:
Expand All @@ -99,8 +100,6 @@ static inline int arch_futex_atomic_op_inuser(int op, int oparg, int *oval,
ret = -ENOSYS;
}

pagefault_enable();

if (!ret)
*oval = oldval;

Expand Down
4 changes: 2 additions & 2 deletions include/asm-generic/futex.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ arch_futex_atomic_op_inuser(int op, u32 oparg, int *oval, u32 __user *uaddr)
int oldval, ret;
u32 tmp;

if (!access_ok(uaddr, sizeof(u32)))
return -EFAULT;
preempt_disable();
pagefault_disable();

ret = -EFAULT;
if (unlikely(get_user(oldval, uaddr) != 0))
Expand Down Expand Up @@ -67,7 +68,6 @@ arch_futex_atomic_op_inuser(int op, u32 oparg, int *oval, u32 __user *uaddr)
ret = -EFAULT;

out_pagefault_enable:
pagefault_enable();
preempt_enable();

if (ret == 0)
Expand Down
5 changes: 2 additions & 3 deletions kernel/futex.c
Original file line number Diff line number Diff line change
Expand Up @@ -1723,10 +1723,9 @@ static int futex_atomic_op_inuser(unsigned int encoded_op, u32 __user *uaddr)
oparg = 1 << oparg;
}

if (!access_ok(uaddr, sizeof(u32)))
return -EFAULT;

pagefault_disable();
ret = arch_futex_atomic_op_inuser(op, oparg, &oldval, uaddr);
pagefault_enable();
if (ret)
return ret;

Expand Down

0 comments on commit a08971e

Please sign in to comment.