Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758173AbdLRIpB (ORCPT ); Mon, 18 Dec 2017 03:45:01 -0500 Received: from mga05.intel.com ([192.55.52.43]:43723 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757935AbdLRIpA (ORCPT ); Mon, 18 Dec 2017 03:45:00 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,421,1508828400"; d="scan'208";a="13518978" From: Rui Wang To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: dave.hansen@linux.intel.com, rui.y.wang@intel.com Subject: [PATCH] x86/mpx/selftests: Fix wrong bounds with old _sigfault Date: Mon, 18 Dec 2017 16:34:10 +0800 Message-Id: <1513586050-1641-1-git-send-email-rui.y.wang@intel.com> X-Mailer: git-send-email 1.7.5.4 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2259 Lines: 76 I fixed this on my machine and forgot to tell anyone until a recent bug report. The patch almost get lost. Archiving it here. 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. Fixes: e754aedc26ef ("x86/mpx, selftests: Add MPX self test") Signed-off-by: Rui Wang --- tools/testing/selftests/x86/mpx-mini-test.c | 27 +++++++++++++++++++++++++-- 1 files changed, 25 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/x86/mpx-mini-test.c b/tools/testing/selftests/x86/mpx-mini-test.c index ec0f6b4..45035c3 100644 --- a/tools/testing/selftests/x86/mpx-mini-test.c +++ b/tools/testing/selftests/x86/mpx-mini-test.c @@ -315,11 +315,34 @@ static uint64_t read_mpx_status_sig(ucontext_t *uctxt) return si->si_upper; } #else + +/* This deals with old version of _sigfault in some distros +old _sigfault: + struct { + void *si_addr; + } _sigfault; + +new _sigfault: + struct { + void __user *_addr; + int _trapno; + short _addr_lsb; + union { + struct { + void __user *_lower; + void __user *_upper; + } _addr_bnd; + __u32 _pkey; + }; + } _sigfault; +*/ static inline void **__si_bounds_hack(siginfo_t *si) { void *sigfault = &si->_sifields._sigfault; void *end_sigfault = sigfault + sizeof(si->_sifields._sigfault); - void **__si_lower = end_sigfault; + int *trapno = (int*)end_sigfault; + /* skip _trapno and _addr_lsb */ + void **__si_lower = (void**)(trapno + 2); return __si_lower; } @@ -331,7 +354,7 @@ static uint64_t read_mpx_status_sig(ucontext_t *uctxt) static inline void *__si_bounds_upper(siginfo_t *si) { - return (*__si_bounds_hack(si)) + sizeof(void *); + return *(__si_bounds_hack(si) + 1); } #endif -- 1.7.5.4