From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (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 19EFB1EB9F7 for ; Fri, 21 Mar 2025 07:35:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742542555; cv=none; b=KwXzgzm6Tj8OSirzL97sPTyeZr891rJ6atYpaoqbgDGT0w8DeiD4CRRNRKSP5N20HxE994QZxxYey6ExTMHpEHC4ZUPS64WioQz3vFS88rlYXzVO/1A+np3b4uyonwqVxcEGDxdrPvzLZ1E1CslO4ZWPpAdeu2RuvXEew+ZB88U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742542555; c=relaxed/simple; bh=oVEU4h1wTtlqlUbh+FEIic8QhsG6E3beaWkZ1pscJx8=; h=Mime-Version:Content-Type:Date:Message-Id:Cc:To:From:Subject: References:In-Reply-To; b=tttGq5zJMNZ3EBhSaNhENZ99TENWidiObK8oeJ7nXzsfs9gAbsC6KLGQFaMpWxnDGyAPSnd1heW1kgIIgEq4VK2vCcxeAX7JkHXyoa8EscN3V2b18Lg23M698deYuYJHhS+rdE0CVNlobcE77Cr+6DvkIwdMxNd9z9OLSnyr8u8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=OAPjI+Nt; arc=none smtp.client-ip=209.85.221.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="OAPjI+Nt" Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-39127effa72so192681f8f.2 for ; Fri, 21 Mar 2025 00:35:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1742542551; x=1743147351; darn=vger.kernel.org; h=in-reply-to:references:subject:from:to:cc:message-id:date :content-transfer-encoding:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=uE0YN48K2zRXVt+YdSQ/RPd3ayIjfmSlm7kfHTz7O6c=; b=OAPjI+Nt8Mx7oV7aEVLf94wsdw+DPtnZFtkzH1+AA2u31jCIT1+VBXpuzC/2X46qXd x558zm27VkDuYd75yDwCGQuu9lhq5Xj+h41lYnMHrm9krK9AyzXE2UAZUEYZRGp0WxMs cJqdtk9U6Nx3CFN4imX/4xn2O2btcPml93+vKVoV4monqJ05p9WMdHx9rToeFw+yb/Dz MIy/AwQZkpRzQWF65imYjbbFbhvMKNFMtxfo3QIfFjf2+Wc3aq0hmwkU66NjrQACmYMH XFXCaiPgCRmEm/sRm7nFcbQmPR2a7RCeEsqkBAT5wj57EOelvetdxbMq82PQmd40/kob 1WhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742542551; x=1743147351; h=in-reply-to:references:subject:from:to:cc:message-id:date :content-transfer-encoding:mime-version:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=uE0YN48K2zRXVt+YdSQ/RPd3ayIjfmSlm7kfHTz7O6c=; b=VVcDpUWjFE/BDvtSRTO7I3KmP2EVKn2G6y/iA2z6s6q3SFwf1X1aoyqDCj/wY1nm92 WRe2iHezjXr8zEb1BuJGX0EdhrcfCgX8+bx3kIbrYksvmR1pv/ZNYueCnkSyRifGUEcs 2yh+ZguLbfOMTicuO5lMf1MhodHJWRhnX5tpihRoDmyut4ugX8fKOPSvxI5rNqO2Jq+F ESKZvA/kOYjJ6bxclLdSUBZBXDIt3oi1HYF5xhslVy+jFo0AgGrqnp3nXkle1DsvB3CK 89+H5l3oP1RMz+dZzAGynlfengmWqN2E9BnFPBHk2K76WGyoD/TcjQ+50TtA/daU4AxC OOlA== X-Forwarded-Encrypted: i=1; AJvYcCVO+fG6yoqPQCrL7OKEFi8Srlm65NdG6+d3mEwXSm0tUfwJRQZBZ+ncxPFUwuEVyJqvmDjfxUmxkeupXrk=@vger.kernel.org X-Gm-Message-State: AOJu0YxUCiDR7Ys4uCzQzrd6sg3o0Qala8GjVH7VNZrWjVwQAizCKCd4 pekLEF7ob+zkGPyFGHpAagHQLRmUWEC/MJCPIwlHfkMyBOwxBm+ns5QHjzHKSRw= X-Gm-Gg: ASbGncu3q5PUbsXb6Z9nvRK6DDFblcEVBKtkIipwIvs36VpiNknGjoD48o+BDI5/MVt Rjcd2QbASWrHBkz8LBijpPsLfh9U2tfEky7w5mpwOaD8m9WMhep1bdDCka3n7/OEaiTMHyNgFRe KTdXgg8fj79PVF+S1fiU6CIqz441UEnAskA0MZDNGcS1OR4yw/9EfQoVD3mbaFvE5lbT8N4JQmp qKg0HZwzHpf8L9OHbX0NkiFheAjGplkFbeJSbk0M33TXW7hz+/inkBsi34veS9fKT0mJSokLq8o ElH2EWurnct/ZrcgeTOxGIlhq44Uj6aEAtJS64CX19mWMZjc466vbdeYxSG2UPXLL0IXnItcHjj tyuczlFrTJFNWv5U= X-Google-Smtp-Source: AGHT+IGZStgpQKD6s5SPSh0Un5MoJV2dCYto8osYkw90aX9XoWoskpnSL/J6+EfI/KAtzzUYKMCKnA== X-Received: by 2002:a05:6000:188f:b0:391:277e:c400 with SMTP id ffacd0b85a97d-3997f941b74mr851925f8f.13.1742542551154; Fri, 21 Mar 2025 00:35:51 -0700 (PDT) Received: from localhost (ip-89-103-73-235.bb.vodafone.cz. [89.103.73.235]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3997f9b3f7csm1592933f8f.49.2025.03.21.00.35.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Mar 2025 00:35:50 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Fri, 21 Mar 2025 08:35:49 +0100 Message-Id: Cc: "Thomas Gleixner" , "Ingo Molnar" , "Borislav Petkov" , "Dave Hansen" , , "H. Peter Anvin" , "Andrew Morton" , "Liam R. Howlett" , "Vlastimil Babka" , "Lorenzo Stoakes" , "Paul Walmsley" , "Palmer Dabbelt" , "Albert Ou" , "Conor Dooley" , "Rob Herring" , "Krzysztof Kozlowski" , "Arnd Bergmann" , "Christian Brauner" , "Peter Zijlstra" , "Oleg Nesterov" , "Eric Biederman" , "Kees Cook" , "Jonathan Corbet" , "Shuah Khan" , "Jann Horn" , "Conor Dooley" , , , , , , , , , , , , , , , , , , , , , , "Zong Li" , "linux-riscv" To: "Deepak Gupta" From: =?utf-8?q?Radim_Kr=C4=8Dm=C3=A1=C5=99?= Subject: Re: [PATCH v12 22/28] riscv: enable kernel access to shadow stack memory via FWFT sbi call References: <20250314-v5_user_cfi_series-v12-0-e51202b53138@rivosinc.com> <20250314-v5_user_cfi_series-v12-22-e51202b53138@rivosinc.com> In-Reply-To: 2025-03-20T15:42:44-07:00, Deepak Gupta : > On Thu, Mar 20, 2025 at 3:10=E2=80=AFPM Radim Kr=C4=8Dm=C3=A1=C5=99 wrote: >> >> 2025-03-14T14:39:41-07:00, Deepak Gupta : >> > Kernel will have to perform shadow stack operations on user shadow sta= ck. >> > Like during signal delivery and sigreturn, shadow stack token must be >> > created and validated respectively. Thus shadow stack access for kerne= l >> > must be enabled. >> >> Why can't kernel access the user shadow stack through an aliased WR >> mapping? > > It can, although that opens up a can of worms. If this alternating > mapping is user mode > then ensuring that another threat in userspace can't write to this > address in this window > of signal handling. Right, it must not be user mode. > A kernel alternate mapping can be created, but > that can lead to all > sorts of requirements of ensuring the page is pinned down. IIRC, It > has been debated > on x86 shadow stack merge time as well on how a flaky alias mapping appro= ach can > become and weaken the threat model it is supposed to protect against. True. > Simply using `ssamoswap` is simple and serves the purpose. Enabling shado= w stack > access for the kernel doesn't have any adverse effect on the kernel. Makes sense. We just depend on an extra feature, because we should consider the case when M-mode doesn't allow S-mode shadow stack, but S-mode can enable U-mode shadow stack: >> > --- >> > diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S >> > @@ -320,6 +326,12 @@ SYM_CODE_START(_start_kernel) >> > la tp, init_task >> > la sp, init_thread_union + THREAD_SIZE >> > addi sp, sp, -PT_SIZE_ON_STACK >> > + li a7, SBI_EXT_FWFT >> > + li a6, SBI_EXT_FWFT_SET >> > + li a0, SBI_FWFT_SHADOW_STACK >> > + li a1, 1 /* enable supervisor to access shadow stack access */ >> > + li a2, SBI_FWFT_SET_FLAG_LOCK >> > + ecall >> >> I think the ecall can fail even on machines that have Zicfiss, so it >> would be good to disable user shadow stack if that happens.