From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (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 1053E1E5707 for ; Fri, 21 Mar 2025 07:35:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742542554; cv=none; b=CEHzmgjdKKXFRbi908JcKcYUJDj0cnzgAwEDnyvHDe4qGJEUTR7/LtZpkBIpyIG0CDu8iwwdYQxgVppg0bEhkNSRo0kWoUELBBSJyGFEk4oG4ra0JWzfPWLKyMsCiQMKuvCFPRjZF/7JszAUlGuuqXtswLZYZfCfS8ySh3vS1dw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742542554; c=relaxed/simple; bh=oVEU4h1wTtlqlUbh+FEIic8QhsG6E3beaWkZ1pscJx8=; h=Mime-Version:Content-Type:Date:Message-Id:Cc:To:From:Subject: References:In-Reply-To; b=INi3BdfniGlHekf4H+pMVM91U5eCF5+Q/1i5YgxZc4O7vyhGMSkls0spy+/q1w+QvzJahY22q43xrQdPGU7Vgn7dgdSt9nJxespQKzdXdbJLcyfPTlQDZaphvBvmd7P8g1RaUuDLRP0x5MwNh/YPtN2v3xJOTPXhUr1zl6TwwD4= 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.41 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-f41.google.com with SMTP id ffacd0b85a97d-39973c72e8cso233230f8f.0 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=Xb05u3a4bRkT2AGPoGBZodUKKUpoRsRm95brJkzp2Z6jyD//0v/fDUaekFeGDfHHJf I0Ft7f1PgIPjp62dxmFPNWm1ogiEqEvCuSdqNignK8m9isl8BQOhABHISNwzWv9pEwF5 P4YYmlaplzk4NdPZRZGz3YYDgWKFC30kGjyxuSj3wlByhqw4WuhFfbdR+IkWdcY24GlJ nfhVx2yJ6UnWAxYXoH7zw69LH+nWk9z4bgFjnOI5L+kFXATUyhQfKyuGP/20yzyDcisl ZXHv1bPILDu7Kp4N5KzOlKcma3LMPoOn+B8A4Sc2pH2UQsvG4LXvE72QWz9I+bV/k4bb iZww== X-Forwarded-Encrypted: i=1; AJvYcCW4+kipAIvjfaZXmUGuWCkCB6Opz5w+oSBJxUvtHSTRtp6tqd3Iq+upMEGngtnQUl2F7HQCJq29Lok6@vger.kernel.org X-Gm-Message-State: AOJu0YzA+WRpMl81oOZGRn5zrcrLaZbxr6Iil/effjL1c93Jhi4So1uc QSU1iBbkU3PDS73WNNvMBduUAg+IkNaUaPWFewRmAfBWQLPpRJL7q/ap3pi9AZQ= X-Gm-Gg: ASbGncv8HZImK+nhb9nnfnyRnv21lP+H1WDkjo9Nrv9kOSaGciU36X/HASeubmXLLF/ YoC2xuG4n9Cbk3gqbtcVvZRtqcXAAgUCKNBcHcIb/HtUTZkADeC6WEFGht5Xmn8gmyF7G1z3UqT /+qm7C8QnP/RhYBDBFdHKfDk5vrRsKiKudA7bLUDcALx7C9VvS6uPGvmap9Tl+GgVxlGbNBhOr5 zJ+L7MNhX7AwrfL8S63AF2eXjtnytgsI/vKih3vz8OmgBhwxm9kyZtskg7bsHH4749wK45iRKmi pQAS9zXiZkKLh4X7eVG2HBRyjlGLsc/9oBAzKzylUn5MGL9AzUAX3njPoX5UyD/IFscKQ7IZAa/ VPOMQA161wtx2h5c= 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: devicetree@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.