Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6556300rdb; Fri, 15 Dec 2023 01:46:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IEXQl+GOjgVM7j5Z6f1fmVebqHZ084t6tZve1PuQLF8SpffnP1Y7Dgem8sKwnshnC8qBKvn X-Received: by 2002:a05:6a00:460f:b0:6ce:4866:f388 with SMTP id ko15-20020a056a00460f00b006ce4866f388mr7542765pfb.24.1702633575722; Fri, 15 Dec 2023 01:46:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702633575; cv=none; d=google.com; s=arc-20160816; b=jR+OikYRzf6stEW9rCGZBiFV+SrwVsj8s5oTABTZCA361Lm+r5Xwxfj732xYKP4oxu 1jxmgNkVFKDersq294hFIJLjRzJTFwM39tE/N+sEk95nmavigJ2adrwxY6L4CuOyYeVg N2vLEd9AUsYrz3nlTmV+PQLdyDfeo4Kr/cuNZX7LRGGJQ5sPv2TxQo1VHBiDfigfD6yO 8Y1RQLgrFp9GalCyufUL86HMejWosPSqKfPXnwK1IgbKWoiAVo/Wpza0KOKKZAlwQnSQ 3u7QJ3kEYbsR9Mcjkx540YOv2ywYM62MeBS7iZXXFpW/+LroIV3hpaD+8rnlvBVO4y/B dmlQ== 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-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-699-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id j12-20020a65428c000000b0059779ae58a0si12744411pgp.465.2023.12.15.01.46.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 01:46:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-699-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; 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-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-699-linux.lists.archive=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id A63B8B22C02 for ; Fri, 15 Dec 2023 09:46:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 13BBB182DA; Fri, 15 Dec 2023 09:46:05 +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-Type: text/plain; charset=utf-8 Content-Disposition: inline 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.