Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp1040362lqp; Fri, 22 Mar 2024 04:01:15 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVb0PU+OauxkqtwiexEY/FypWf0CH6BdDzbJAUbh0CwcojC0lvHxB4OvIG7Zf6bFTlM9HUgrkArnyeHRaKpkL0F6/Ir5IeRQITjFUZ4Vg== X-Google-Smtp-Source: AGHT+IHiFPbOY3ZYdKpC28EKVeCDJZvjBE5+b24ArvhEpB+Gc99MRCKkNiwIStA70uT1oLjjaW+A X-Received: by 2002:a05:620a:223:b0:789:e15d:3f20 with SMTP id u3-20020a05620a022300b00789e15d3f20mr1906904qkm.15.1711105274862; Fri, 22 Mar 2024 04:01:14 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711105274; cv=pass; d=google.com; s=arc-20160816; b=aHDaFvwqIapNVve48Ftf9z6xCI5BLP8vi9M+8rtOfC2q4K/chp2QL38dMbeRLzl8kl o/aEncGVOFt2hcm7nOFxRD9tjkscJOUXHfDQGqRb2z8CPKHZqkIGDX02xhYASndrcVhs BbBJQ34KVBSjhD6U3HZ6Uipu4mU1jDjqHRN8FCvGPeFfwg/+orY0vJH6pZtRdBd6fbJz G4BYDIqJqXPvdYt0vTHC4k91PTCPv/tQ/S9RfKz9Q6M8sNdhqp84OpeQO4j6YIF2HrmA sZllNx2pWVYhg0g2zoe3lnQeLErlyO9UuY77GshbWNWL5IrZlscg8IJBIBqQWvs2xQZh sz5w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:precedence:robot-unsubscribe:robot-id :message-id:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:in-reply-to:cc:subject:to:reply-to:sender :from:dkim-signature:dkim-signature:date; bh=h5ZtWgNkBRMIWmFp5Y46fMbsEbaY+4L88vZSo4bSAYk=; fh=dji4/ZiAv8qX9jynVPGsr6wL2rPWczx2HXWQgbVeoxg=; b=Q5ivUrWbtTf3P2I5+MJ7O0Di/wMdRb9x3ASfR0kRPyfeIBwR5iwYWM8RyezbIOfR5K ht1mMNpKSOWoBjgqJGuyKUAQ3ghzDEItM3GUqdC06lqNmjp6sHBVC7uN5bYsBqkBfFy7 UaCHCFY8iFsIOKNuwG16iEVOFtys/5tNixnVazzvcRN5d3RitQlWRh2yaQh5j6T8Mww4 IYaAoMKiCr/VBdaaE3KZbAsFAjTTR0zLiVyCoYTnxUJ0rozYzLTKNrz2sgnzXYljH/nc KVOkOJL91zLi29GbBU/qExmTfEOXwjRpjKL6+pJ4b4Q0O7sbbm9wwXBmKsaG7pRkU109 yDlw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=3fbqRSWW; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-111342-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-111342-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id j1-20020a05620a410100b007882418432asi1904334qko.348.2024.03.22.04.01.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 04:01:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-111342-linux.lists.archive=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=@linutronix.de header.s=2020 header.b=3fbqRSWW; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-111342-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-111342-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de 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 857571C2247A for ; Fri, 22 Mar 2024 11:01:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7D7B33F8FB; Fri, 22 Mar 2024 11:00:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="3fbqRSWW"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="vK8io8cX" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E1ED63AC2B; Fri, 22 Mar 2024 11:00:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711105203; cv=none; b=NGGLw/3D0AQTfejYeJh5SscrWcuh9Mg2cbL/6h5WuLXhcSHta22Z3hkCizSXMl0xWsLIysrKWBs5FGEdcW+kl6TLNurtq/uQmefC8MWij+5n/XsM7oe5xRLgWkdXqKNGltmyHMWDulbfpxWEIxEtYrEAdHddVQvPzK7NK6WMgfk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711105203; c=relaxed/simple; bh=tJHE6WQbKfpVHDW5fVetKWlZW1/K4yJf4ZiivuZPg8o=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=qOPzNpXgeeBZu+JqpfMpXL2O15VVhw9v/a7elYysSOycjRcsVhfO8GSxG43OnTL3jQR5pce1k9mo3GAt88A4OnlOALO3KR6y2ErxU3H8uINE5XxSWH2rqHaCzhiWBMKAlaTqi2Xaj/xT/yezImEeLIm++dcATlAU0bKbEoXvGjk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=3fbqRSWW; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=vK8io8cX; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Date: Fri, 22 Mar 2024 10:59:58 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1711105199; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=h5ZtWgNkBRMIWmFp5Y46fMbsEbaY+4L88vZSo4bSAYk=; b=3fbqRSWWm7VdSohU6QuSBy0+Ow0oLKfAsYETKjbOUBsX6B59zz4BetrD3Dx+s4Re7+S+aT pundB6tZuqQvaAFlSCRAuljOYsFPPSDFg+diHz+R9hP6eCu8bnnlgeFJkomh85iGhAIKJJ ybpZ2EA8gocFnqV9UsKCY3o5TMaxYErW1uDWvhy8EmBxfSj4yUw2X+S28KgA7UlnLo+mxT 7mcojqpiJr/TS27Yf4vFtppudGLp1E7P+nce/HwFRBnYfzfnoUUHBm/wGpguF5jcUDU318 AxHkPw/FHurYhfxmAEySs+5hzpc24/FvJ0Ng5XMzat/2S4TDUBD+tt5iT76ujg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1711105199; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=h5ZtWgNkBRMIWmFp5Y46fMbsEbaY+4L88vZSo4bSAYk=; b=vK8io8cXiG5x2vUrVfeZjYF1uqcRgbQ91f7ZEH/+0LOdPqvL5UxouiDKi7p6SsGs921bF2 2l48tkXpFqoRsZCA== From: "tip-bot2 for H.J. Lu" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/shstk] x86/shstk: Enable shadow stacks for x32 Cc: "H.J. Lu" , Ingo Molnar , "Edgecombe, Rick P" , "H. Peter Anvin" , Linus Torvalds , Andy Lutomirski , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20240315140433.1966543-1-hjl.tools@gmail.com> References: <20240315140433.1966543-1-hjl.tools@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <171110519880.10875.7663158781394877164.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit The following commit has been merged into the x86/shstk branch of tip: Commit-ID: 2883f01ec37dd8668e7222dfdb5980c86fdfe277 Gitweb: https://git.kernel.org/tip/2883f01ec37dd8668e7222dfdb5980c86fdfe277 Author: H.J. Lu AuthorDate: Fri, 15 Mar 2024 07:04:33 -07:00 Committer: Ingo Molnar CommitterDate: Fri, 22 Mar 2024 10:17:11 +01:00 x86/shstk: Enable shadow stacks for x32 1. Add shadow stack support to x32 signal. 2. Use the 64-bit map_shadow_stack syscall for x32. 3. Set up shadow stack for x32. Tested with shadow stack enabled x32 glibc on Intel Tiger Lake: I configured x32 glibc with --enable-cet, build glibc and run all glibc tests with shadow stack enabled. There are no regressions. I verified that shadow stack is enabled via /proc/pid/status. Signed-off-by: H.J. Lu Signed-off-by: Ingo Molnar Tested-by: H.J. Lu Cc: "Edgecombe, Rick P" Cc: "H. Peter Anvin" Cc: Linus Torvalds Cc: Andy Lutomirski Link: https://lore.kernel.org/r/20240315140433.1966543-1-hjl.tools@gmail.com --- arch/x86/entry/syscalls/syscall_64.tbl | 2 +- arch/x86/kernel/shstk.c | 4 ++-- arch/x86/kernel/signal_64.c | 6 ++++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/arch/x86/entry/syscalls/syscall_64.tbl b/arch/x86/entry/syscalls/syscall_64.tbl index 7e8d46f..cc78226 100644 --- a/arch/x86/entry/syscalls/syscall_64.tbl +++ b/arch/x86/entry/syscalls/syscall_64.tbl @@ -374,7 +374,7 @@ 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat 452 common fchmodat2 sys_fchmodat2 -453 64 map_shadow_stack sys_map_shadow_stack +453 common map_shadow_stack sys_map_shadow_stack 454 common futex_wake sys_futex_wake 455 common futex_wait sys_futex_wait 456 common futex_requeue sys_futex_requeue diff --git a/arch/x86/kernel/shstk.c b/arch/x86/kernel/shstk.c index 59e15dd..6f1e988 100644 --- a/arch/x86/kernel/shstk.c +++ b/arch/x86/kernel/shstk.c @@ -163,8 +163,8 @@ static int shstk_setup(void) if (features_enabled(ARCH_SHSTK_SHSTK)) return 0; - /* Also not supported for 32 bit and x32 */ - if (!cpu_feature_enabled(X86_FEATURE_USER_SHSTK) || in_32bit_syscall()) + /* Also not supported for 32 bit */ + if (!cpu_feature_enabled(X86_FEATURE_USER_SHSTK) || in_ia32_syscall()) return -EOPNOTSUPP; size = adjust_shstk_size(0); diff --git a/arch/x86/kernel/signal_64.c b/arch/x86/kernel/signal_64.c index 23d8aaf..8a94053 100644 --- a/arch/x86/kernel/signal_64.c +++ b/arch/x86/kernel/signal_64.c @@ -315,6 +315,9 @@ int x32_setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs) uc_flags = frame_uc_flags(regs); + if (setup_signal_shadow_stack(ksig)) + return -EFAULT; + if (!user_access_begin(frame, sizeof(*frame))) return -EFAULT; @@ -377,6 +380,9 @@ COMPAT_SYSCALL_DEFINE0(x32_rt_sigreturn) if (!restore_sigcontext(regs, &frame->uc.uc_mcontext, uc_flags)) goto badframe; + if (restore_signal_shadow_stack()) + goto badframe; + if (compat_restore_altstack(&frame->uc.uc_stack)) goto badframe;