From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (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 57B5322A808 for ; Thu, 20 Mar 2025 22:10:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742508615; cv=none; b=BSIjmt8RDNSXICb3+qtf6f4l8AsvtEtP9Izlscggjorz3cbomJk3gWia/3VogY6ZT+vpu2pizPmyCIZ+9B1BgKe1jbypdngXBdpUTTdkB7E7SN/J+zLe8qFnV4qZ5J/3FeaY9mYLKDqSUBMqJIotbnsT+wNKD54Hz6Ix+PdCFoI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742508615; c=relaxed/simple; bh=WUircD2gMunYayRFEsupwySC2IZlWNKmBLpSeBOKDuk=; h=Mime-Version:Content-Type:Date:Message-Id:Cc:To:From:Subject: References:In-Reply-To; b=dcY/SNsgUUmMBezH42AXhSThIU77bZHneA3WwLucGW7mybL/khyUzXiaIU3GuiLA8ek780q1qDLdhFhoCZDYtidynOVHg+P6Tw/QyVAS3IyksyRCww7D6EkQ4JMoLbR3CD5mgO4e8uZy3x09VIBtjfIK11+Z4j7ih/CClsk5rlU= 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=SQyL5yoc; arc=none smtp.client-ip=209.85.128.49 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="SQyL5yoc" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-43cf7c2c351so949495e9.0 for ; Thu, 20 Mar 2025 15:10:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1742508611; x=1743113411; 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=ewXqUeA7RBIygwSLbMlGfEG1GVvVQPFVPFBcsvVuklE=; b=SQyL5yoctpMIiYraB/AyPJVy5DTn1JNM7nuDEIwNOlvDwmTGaE9QarnzBNwRDAf9Yr S6lWelZYnyG13MGjY2aFEn46naiKYS1xGah6DovppVBMq+DDhC342JRPMjGWevaGDi5D P38+EiLB1ojzvFt5wwQFvpnLxSbZuIRTVsaZQMg27u8bgMpy60iVeHb9rDYaq9Ch1DoL n7VygtUNpF09YivzwCyYIE5D9NYt11cY5TEpv7Rmqd0MetiT4IISrsvho8/QptOahGnW HSodB+AOHO/NZGq3BhnhMnt67qgbmBRCOsz5KNU9y7+Ek/5TWWnpf2wajHBWkLWd3rAk KQIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742508611; x=1743113411; 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=ewXqUeA7RBIygwSLbMlGfEG1GVvVQPFVPFBcsvVuklE=; b=ZMNB7oRl9NOvZ/PmFlbE+i+AnM7pTFL0/Jt7qBPs4uRrC5pLDLgvvahpgbMhhVnr6b rdLJSMLJqS+HyZdjaiaGPc13/vqVnhkDM+2gNm4I/diQFw4dOwFi2bDamgStBZSs7/pD rV7QDK32MR8Slt2PpGl5gRR7JrxZqocxZDWtrCcETP5ONRTfE37WlShl4Sk4jbAOPQbo Cg/q0G4OD3NaHXaRljYRdDlApW6U/FOLXrxzVQpoOZQEHp8wPc5b7mVrRc14z7ln3aoh wXzM04auWv6u6ydmR21ECrHfYJwyUK+IiXLFFKUagqZ6GWz26GWctmS698dxSH43ulqO BHDw== X-Gm-Message-State: AOJu0YyFZiIaA13uDgDxaIVkPBtiISPVkW+hQ8Zw3xeRkD9TPqsJ3s5w 4ZqF0wvGpG07hH49vIlyAWJXKRu8mC0NfzwHHljr0bKy7aAPzqxx9lanl5c+W0Y= X-Gm-Gg: ASbGncvTK4x12HbiKMuicU2pNYgKY7iemBB6QzXbNM5n72x9G8UHZoifcKBKDFycp6B MU2zOD3hS1FcyFyZ9H/lKVHkCb3IZuTfd0r3PhF2M9gizLbU6vkpZIrFMnu+F/uJdKLasbXEl8r qcHEs+rpvrxY7mVWXqfiWmYRohtqc0SNpTDMuMpW2oaY9s1Qga5aYVM4cnDSqWF8VrC+ENoMSae RwCbvD+z+ZD+s5PFsBAudAOOQrbVLdSRhwQD+4yLwVu2g4kEtDiEdDqi0B/3OLaw9104ww+jyKu 2T7vV3n4JafiXloAvxMT1e0zsAoHyH4CKLsRmKCNF3s0gDT1tCZpF1o31f9of0NAigHAX37V4mw 1xEDAWOm6C6xCXTE= X-Google-Smtp-Source: AGHT+IG3iOdJG0QpOBXcV58Rkg48UtcOBUQNUhvPAa+an4gh1o0G7FLaaJ5j+6uFEW3mo9uctUtXkw== X-Received: by 2002:a05:600c:5252:b0:439:9909:c785 with SMTP id 5b1f17b1804b1-43d5171da80mr576165e9.7.1742508611223; Thu, 20 Mar 2025 15:10:11 -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-3997f9eef37sm655138f8f.85.2025.03.20.15.10.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Mar 2025 15:10:08 -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: Thu, 20 Mar 2025 23:10:06 +0100 Message-Id: Cc: , , , , , , , , , , , , , , , , , , , , , "Zong Li" , "linux-riscv" To: "Deepak Gupta" , "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" 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: <20250314-v5_user_cfi_series-v12-22-e51202b53138@rivosinc.com> 2025-03-14T14:39:41-07:00, Deepak Gupta : > Kernel will have to perform shadow stack operations on user shadow stack. > Like during signal delivery and sigreturn, shadow stack token must be > created and validated respectively. Thus shadow stack access for kernel > must be enabled. Why can't kernel access the user shadow stack through an aliased WR mapping? > In future when kernel shadow stacks are enabled for linux kernel, it must > be enabled as early as possible for better coverage and prevent imbalance > between regular stack and shadow stack. After `relocate_enable_mmu` has > been done, this is as early as possible it can enabled. > > Reviewed-by: Zong Li > Signed-off-by: Deepak Gupta > --- > 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.