Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit de66d97

Browse files
Richard Palethorpegregkh
authored andcommitted
x86/entry/ia32: Ensure s32 is sign extended to s64
commit 56062d6 upstream. Presently ia32 registers stored in ptregs are unconditionally cast to unsigned int by the ia32 stub. They are then cast to long when passed to __se_sys*, but will not be sign extended. This takes the sign of the syscall argument into account in the ia32 stub. It still casts to unsigned int to avoid implementation specific behavior. However then casts to int or unsigned int as necessary. So that the following cast to long sign extends the value. This fixes the io_pgetevents02 LTP test when compiled with -m32. Presently the systemcall io_pgetevents_time64() unexpectedly accepts -1 for the maximum number of events. It doesn't appear other systemcalls with signed arguments are effected because they all have compat variants defined and wired up. Fixes: ebeb8c8 ("syscalls/x86: Use 'struct pt_regs' based syscall calling for IA32_EMULATION and x32") Suggested-by: Arnd Bergmann <[email protected]> Signed-off-by: Richard Palethorpe <[email protected]> Signed-off-by: Nikolay Borisov <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Arnd Bergmann <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Link: https://lore.kernel.org/ltp/[email protected]/ Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 500ad5d commit de66d97

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

arch/x86/include/asm/syscall_wrapper.h

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,29 @@ extern long __ia32_sys_ni_syscall(const struct pt_regs *regs);
5858
,,regs->di,,regs->si,,regs->dx \
5959
,,regs->r10,,regs->r8,,regs->r9) \
6060

61+
62+
/* SYSCALL_PT_ARGS is Adapted from s390x */
63+
#define SYSCALL_PT_ARG6(m, t1, t2, t3, t4, t5, t6) \
64+
SYSCALL_PT_ARG5(m, t1, t2, t3, t4, t5), m(t6, (regs->bp))
65+
#define SYSCALL_PT_ARG5(m, t1, t2, t3, t4, t5) \
66+
SYSCALL_PT_ARG4(m, t1, t2, t3, t4), m(t5, (regs->di))
67+
#define SYSCALL_PT_ARG4(m, t1, t2, t3, t4) \
68+
SYSCALL_PT_ARG3(m, t1, t2, t3), m(t4, (regs->si))
69+
#define SYSCALL_PT_ARG3(m, t1, t2, t3) \
70+
SYSCALL_PT_ARG2(m, t1, t2), m(t3, (regs->dx))
71+
#define SYSCALL_PT_ARG2(m, t1, t2) \
72+
SYSCALL_PT_ARG1(m, t1), m(t2, (regs->cx))
73+
#define SYSCALL_PT_ARG1(m, t1) m(t1, (regs->bx))
74+
#define SYSCALL_PT_ARGS(x, ...) SYSCALL_PT_ARG##x(__VA_ARGS__)
75+
76+
#define __SC_COMPAT_CAST(t, a) \
77+
(__typeof(__builtin_choose_expr(__TYPE_IS_L(t), 0, 0U))) \
78+
(unsigned int)a
79+
6180
/* Mapping of registers to parameters for syscalls on i386 */
6281
#define SC_IA32_REGS_TO_ARGS(x, ...) \
63-
__MAP(x,__SC_ARGS \
64-
,,(unsigned int)regs->bx,,(unsigned int)regs->cx \
65-
,,(unsigned int)regs->dx,,(unsigned int)regs->si \
66-
,,(unsigned int)regs->di,,(unsigned int)regs->bp)
82+
SYSCALL_PT_ARGS(x, __SC_COMPAT_CAST, \
83+
__MAP(x, __SC_TYPE, __VA_ARGS__)) \
6784

6885
#define __SYS_STUB0(abi, name) \
6986
long __##abi##_##name(const struct pt_regs *regs); \

include/linux/syscalls.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ struct cachestat;
125125
#define __TYPE_IS_LL(t) (__TYPE_AS(t, 0LL) || __TYPE_AS(t, 0ULL))
126126
#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
127127
#define __SC_CAST(t, a) (__force t) a
128+
#define __SC_TYPE(t, a) t
128129
#define __SC_ARGS(t, a) a
129130
#define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
130131

0 commit comments

Comments
 (0)