Skip to content

Commit 961888b

Browse files
ruiwang1Ingo Molnar
authored andcommitted
selftests/x86/mpx: Fix incorrect bounds with old _sigfault
For distributions with old userspace header files, the _sigfault structure is different. mpx-mini-test fails with the following error: [root@Purley]# mpx-mini-test_64 tabletest XSAVE is supported by HW & OS XSAVE processor supported state mask: 0x2ff XSAVE OS supported state mask: 0x2ff BNDREGS: size: 64 user: 1 supervisor: 0 aligned: 0 BNDCSR: size: 64 user: 1 supervisor: 0 aligned: 0 starting mpx bounds table test ERROR: siginfo bounds do not match shadow bounds for register 0 Fix it by using the correct offset of _lower/_upper in _sigfault. RHEL needs this patch to work. Signed-off-by: Rui Wang <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: [email protected] Fixes: e754aed ("x86/mpx, selftests: Add MPX self test") Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent 1299ef1 commit 961888b

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

tools/testing/selftests/x86/mpx-mini-test.c

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,11 +315,39 @@ static inline void *__si_bounds_upper(siginfo_t *si)
315315
return si->si_upper;
316316
}
317317
#else
318+
319+
/*
320+
* This deals with old version of _sigfault in some distros:
321+
*
322+
323+
old _sigfault:
324+
struct {
325+
void *si_addr;
326+
} _sigfault;
327+
328+
new _sigfault:
329+
struct {
330+
void __user *_addr;
331+
int _trapno;
332+
short _addr_lsb;
333+
union {
334+
struct {
335+
void __user *_lower;
336+
void __user *_upper;
337+
} _addr_bnd;
338+
__u32 _pkey;
339+
};
340+
} _sigfault;
341+
*
342+
*/
343+
318344
static inline void **__si_bounds_hack(siginfo_t *si)
319345
{
320346
void *sigfault = &si->_sifields._sigfault;
321347
void *end_sigfault = sigfault + sizeof(si->_sifields._sigfault);
322-
void **__si_lower = end_sigfault;
348+
int *trapno = (int*)end_sigfault;
349+
/* skip _trapno and _addr_lsb */
350+
void **__si_lower = (void**)(trapno + 2);
323351

324352
return __si_lower;
325353
}
@@ -331,7 +359,7 @@ static inline void *__si_bounds_lower(siginfo_t *si)
331359

332360
static inline void *__si_bounds_upper(siginfo_t *si)
333361
{
334-
return (*__si_bounds_hack(si)) + sizeof(void *);
362+
return *(__si_bounds_hack(si) + 1);
335363
}
336364
#endif
337365

0 commit comments

Comments
 (0)