Skip to content

Commit d8eebb1

Browse files
hcahcaAlexander Gordeev
authored andcommitted
s390/futex: Avoid KMSAN instrumention for user pointers
Similar to commit eb6efdf ("s390/uaccess: add KMSAN support to put_user() and get_user()") disable KMSAN instrumention for futex inline assemblies, which contain dereferenced user pointers. With KMSAN instrumentation this would lead to accesses of shadows for user pointers, which should not happen. Handle the futex operations like they copy a value (old) from user space to kernel space. Acked-by: Ilya Leoshkevich <iii@linux.ibm.com> Signed-off-by: Heiko Carstens <hca@linux.ibm.com> Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
1 parent c4891f4 commit d8eebb1

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

arch/s390/include/asm/futex.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,20 @@
22
#ifndef _ASM_S390_FUTEX_H
33
#define _ASM_S390_FUTEX_H
44

5+
#include <linux/instrumented.h>
56
#include <linux/uaccess.h>
67
#include <linux/futex.h>
78
#include <asm/asm-extable.h>
89
#include <asm/mmu_context.h>
910
#include <asm/errno.h>
1011

1112
#define FUTEX_OP_FUNC(name, insn) \
12-
static inline int \
13+
static uaccess_kmsan_or_inline int \
1314
__futex_atomic_##name(int oparg, int *old, u32 __user *uaddr) \
1415
{ \
1516
int rc, new; \
1617
\
18+
instrument_copy_from_user_before(old, uaddr, sizeof(*old)); \
1719
asm_inline volatile( \
1820
" sacf 256\n" \
1921
"0: l %[old],%[uaddr]\n" \
@@ -30,6 +32,8 @@ __futex_atomic_##name(int oparg, int *old, u32 __user *uaddr) \
3032
[new] "=&d" (new), [uaddr] "+Q" (*uaddr) \
3133
: [oparg] "d" (oparg) \
3234
: "cc"); \
35+
if (!rc) \
36+
instrument_copy_from_user_after(old, uaddr, sizeof(*old), 0); \
3337
return rc; \
3438
}
3539

@@ -68,11 +72,12 @@ int arch_futex_atomic_op_inuser(int op, int oparg, int *oval, u32 __user *uaddr)
6872
return rc;
6973
}
7074

71-
static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
72-
u32 oldval, u32 newval)
75+
static uaccess_kmsan_or_inline
76+
int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr, u32 oldval, u32 newval)
7377
{
7478
int rc;
7579

80+
instrument_copy_from_user_before(uval, uaddr, sizeof(*uval));
7681
asm_inline volatile(
7782
" sacf 256\n"
7883
"0: cs %[old],%[new],%[uaddr]\n"
@@ -84,6 +89,7 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
8489
: [new] "d" (newval)
8590
: "cc", "memory");
8691
*uval = oldval;
92+
instrument_copy_from_user_after(uval, uaddr, sizeof(*uval), 0);
8793
return rc;
8894
}
8995

0 commit comments

Comments
 (0)