From patchwork Fri Dec 15 09:45:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Dobriyan X-Patchwork-Id: 179138 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp9153103dys; Fri, 15 Dec 2023 01:46:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IEkPWRynixZORS0f6vF99Prlz1kx9ZvYqMWCtN4+X4D5juuAa5jDi0be3AS2QCwTvXtrrXZ X-Received: by 2002:ac8:59d3:0:b0:425:4043:419a with SMTP id f19-20020ac859d3000000b004254043419amr19194181qtf.70.1702633581559; Fri, 15 Dec 2023 01:46:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702633581; cv=none; d=google.com; s=arc-20160816; b=K6zHYa3bCxn/6jco1Qzr0si/Yw5ttPiJ+bCxFc1l+gEqLqoNxAnf0uc8bi2EUXAW6/ pQM5d5iD8eUJXwcT3eWEKbzWwdDPgwDLS2EbXcb8MmzciuVW6giST4Zjn52ILzNh0q0n wyawgOBVFzPbMY658TsKhKD8kpkptF/ok67xzPoD89CD8Xkin12q+kBVz+F1TgY6Wr61 LFRHmIahW3PdY3mb4bfg6j+ltJyafZeiMdFruZ0+yeX7Fu66jAcpCff6NSTd8eW22hHc liskGqZ78OyZoe8w5BitrODP+v12dQZmUrdC/V1JQ8UjfFfTl4qv9S9VfnAs1ZzoDgjn VqNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-disposition:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:message-id:subject:cc:to:from:date :dkim-signature; bh=+vdymqIL4YSsilHrh5VGy7v4a6vTjmyAqVMJ+Z7Xb7g=; fh=fEiOzAOAjCMekWCNjiNYaJIGyQIAslIRWSSc38W++64=; b=GgqfYGJ1soF65lIUUzTKHepvhxbfcRV+MdU2hLHUGRgx7SJ0YcsI/FMFs5NPb2Hy15 OVTeqomdfO4BrlD0TJ+1cqkYc4jYNzFI2JH7eI6forSTiF2seHus0q8sUjV9xnFrQb7I 2jXDiw8SOB/aS/3euhR4VfPpqNAg4bRG9wA6XwF+NFGquXFuwlQjXBgUML6yngDABTg9 KHO1tqGWq8AZBBOO4qr/HtUP9zU1yu/LqxiMjYjh0N6WOf4VuWTBRxdOpqHLdh9NAMxI oJ774z9XWqYPH/lxfahqGSWXQi2J/HmOWy3uHmka5JRnD8xlA87UySME4Cf8iG811EeX g4ZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ExFif04X; spf=pass (google.com: domain of linux-kernel+bounces-699-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-699-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id bt14-20020ac8690e000000b0042553065f6csi19120077qtb.220.2023.12.15.01.46.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 01:46:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-699-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ExFif04X; spf=pass (google.com: domain of linux-kernel+bounces-699-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-699-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 4E5BF1C22A39 for ; Fri, 15 Dec 2023 09:46:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EB01D18C14; Fri, 15 Dec 2023 09:46:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ExFif04X" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BC6B5168B9 for ; Fri, 15 Dec 2023 09:46:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lj1-f178.google.com with SMTP id 38308e7fff4ca-2ca1e6a94a4so5087171fa.0 for ; Fri, 15 Dec 2023 01:46:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702633561; x=1703238361; darn=vger.kernel.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=+vdymqIL4YSsilHrh5VGy7v4a6vTjmyAqVMJ+Z7Xb7g=; b=ExFif04XfkY7+PhCciQNa2eXcGed6Azjj8RRPaW3e4PofkuXT6K0y9RzWEgLWfZVlv FpG2LG4/QAqq+eYR8kISW8GvpMKAZprzcfMLlBxZIkVph2ElLfn3zLfZ2SvKbWgwl4uq zpIPMLYiJO1NQNFR7WAdrMXJWm3+e24OV9XjCarsxgNMGbNK3fmMWDHjMakll5iCi610 lANNTyL2twK92tC/6QVjAmc2sm+Z1nrjN7BaV+k3/rSp7j/dxn43uJqWV5nxVxD++eyy cLtn9h1KGSwog/MkIPp/jmxDbgXQXVkwoDDGF0qRJ/gfv2f5EdSyhXzhUDQeGk6Z+2kE IKPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702633561; x=1703238361; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=+vdymqIL4YSsilHrh5VGy7v4a6vTjmyAqVMJ+Z7Xb7g=; b=n1T4mVidrYUPRaaAl+dhvecuwGmEtuQ+tVij/J/h7L4dzIHPP+DTsfP8HIHbtai7Np f44lGbNaplNfxs3z/rHwgImitpg50/JYrREcjztvDUcrlt6QMu5uBm8IDnw9ob1wxjZ+ H8/de4y0RjvaaWP75UWDpjiHZnr/Ng2aHphLwPC/pGa4Z8MW2Z625qOLQB6u6rEP8oGA q+428lHww+pBDT0battX/zifSsz+ebL3Gd9iMk3baej675nm+0xalBoY+fcGHNSSLjxE nX5dqMwgxzln0P7+wjF7thiJ+xcfOUCdIIRa+Nv7XMUj0JoPRFFjTUHEVCQP+AU8o6gB E3/A== X-Gm-Message-State: AOJu0Ywe6E4dw3dvZH6GZ4ggYWXFn3q/m8RkQMXWSQMoS0cjEHd6xu6/ MqJRy9aK1hOcRZy/Df/5+Q== X-Received: by 2002:a2e:bc8b:0:b0:2cc:1e99:7c18 with SMTP id h11-20020a2ebc8b000000b002cc1e997c18mr7130797ljf.62.1702633560572; Fri, 15 Dec 2023 01:46:00 -0800 (PST) Received: from p183 ([46.53.250.251]) by smtp.gmail.com with ESMTPSA id g6-20020a50d5c6000000b0054cc827e73dsm7915590edj.78.2023.12.15.01.45.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 01:45:59 -0800 (PST) Date: Fri, 15 Dec 2023 12:45:57 +0300 From: Alexey Dobriyan To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen Cc: linux-kernel@vger.kernel.org, "H. Peter Anvin" Subject: [PATCH] selftests/x86/mm: fixup nx_stack test stability with SA_ONSTACK Message-ID: <8299b17a-a730-46e5-a258-fac78ff0420b@p183> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785340709914029454 X-GMAIL-MSGID: 1785340709914029454 I forgot that using sigaltstack(2) requires opt-in with SA_ONSTACK. If userspace stack is NX, then the test continues to work and reports PASS. If there is kernel bug and some pages of userspace stack are executable, then test can be derailed because signal stack frame contents will pass as random instruction with unpredictable consequences. Signed-off-by: Alexey Dobriyan --- tools/testing/selftests/x86/nx_stack.c | 34 ++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) --- a/tools/testing/selftests/x86/nx_stack.c +++ b/tools/testing/selftests/x86/nx_stack.c @@ -160,10 +160,25 @@ static void sigtrap(int _, siginfo_t *__, void *uc_) int main(void) { + { + /* + * We don't know now much stack SIGSEGV handler uses. + * Bump this by 1 page every time someone complains, + * or rewrite it in assembly. + */ + const size_t len = SIGSTKSZ; + void *p = mmap(NULL, len, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); + assert(p != MAP_FAILED); + stack_t ss = {}; + ss.ss_sp = p; + ss.ss_size = len; + int rv = sigaltstack(&ss, NULL); + assert(rv == 0); + } { struct sigaction act = {}; sigemptyset(&act.sa_mask); - act.sa_flags = SA_SIGINFO; + act.sa_flags = SA_SIGINFO|SA_ONSTACK; act.sa_sigaction = &sigsegv; int rv = sigaction(SIGSEGV, &act, NULL); assert(rv == 0); @@ -171,7 +186,7 @@ int main(void) { struct sigaction act = {}; sigemptyset(&act.sa_mask); - act.sa_flags = SA_SIGINFO; + act.sa_flags = SA_SIGINFO|SA_ONSTACK; act.sa_sigaction = &sigtrap; int rv = sigaction(SIGTRAP, &act, NULL); assert(rv == 0); @@ -188,21 +203,6 @@ int main(void) rv = setrlimit(RLIMIT_STACK, &rlim); assert(rv == 0); } - { - /* - * We don't know now much stack SIGSEGV handler uses. - * Bump this by 1 page every time someone complains, - * or rewrite it in assembly. - */ - const size_t len = SIGSTKSZ; - void *p = mmap(NULL, len, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); - assert(p != MAP_FAILED); - stack_t ss = {}; - ss.ss_sp = p; - ss.ss_size = len; - int rv = sigaltstack(&ss, NULL); - assert(rv == 0); - } make_stack1(); /* * Unreachable, but if _this_ INT3 is ever reached, it's a bug somewhere.