From nobody Mon Feb 9 16:16:55 2026 Received: from mailer.gwdg.de (mailer.gwdg.de [134.76.10.26]) (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 48B572C0299 for ; Thu, 18 Dec 2025 19:29:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=134.76.10.26 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766086170; cv=none; b=sd8A49qpoJ6UVYisprZ8O2Xo3g9ifBRYxgmBTUKTWU/v4b+ilA+yuMIfQLnGonF0fdI63d1BaM/B/a4qwbj0g/cr4uweUmCLEPEM4fDPfYCZLJ6LWeukiaRzH6SoivJ2zjsGdXTcLVGe4tS+JQ23pd2mas7AZ2LaBKzktpyaIy4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766086170; c=relaxed/simple; bh=+dPO+pHsMQkJsBb9p68AFG+XrOl8aHsbHiCtRTtjDYE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jzaG+zCTvPhwCvM05I9+a9la/+h5vN7xWVzXveh8lHo8RXG2IwSbkN6VPA9FxH8yVHfrf313JgkBprs6VoDwauOaOqZyrRqE3N1ry7+11Dy/TFEQvqinhy1hFCooHSHbtsv/ObsjTUsyI8Uf6A19kNSw6T0hOB1bCrJdaFev0ME= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cispa.de; spf=pass smtp.mailfrom=cispa.de; arc=none smtp.client-ip=134.76.10.26 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cispa.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cispa.de Received: from mbx19-sub-05.um.gwdg.de ([10.108.142.70] helo=email.gwdg.de) by mailer.gwdg.de with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (GWDG Mailer) (envelope-from ) id 1vWJRU-000RlX-0O; Thu, 18 Dec 2025 20:13:40 +0100 Received: from localhost.localdomain (10.250.9.200) by MBX19-SUB-05.um.gwdg.de (10.108.142.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.2562.35; Thu, 18 Dec 2025 20:13:39 +0100 From: Lukas Gerlach To: CC: , , , , , , , , , Lukas Gerlach Subject: [PATCH 2/2] riscv: Sanitize syscall table indexing under speculation Date: Thu, 18 Dec 2025 20:13:32 +0100 Message-ID: <20251218191332.35849-3-lukas.gerlach@cispa.de> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251218191332.35849-1-lukas.gerlach@cispa.de> References: <20251218191332.35849-1-lukas.gerlach@cispa.de> 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 X-ClientProxiedBy: MBX19-FMZ-05.um.gwdg.de (10.108.142.64) To MBX19-SUB-05.um.gwdg.de (10.108.142.70) X-Spam-Level: - X-Virus-Scanned: (clean) by clamav Content-Type: text/plain; charset="utf-8" The syscall number is a user-controlled value used to index into the syscall table. Use array_index_nospec() to clamp this value after the bounds check to prevent speculative out-of-bounds access and subsequent data leakage via cache side channels. Signed-off-by: Lukas Gerlach --- arch/riscv/kernel/traps.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/riscv/kernel/traps.c b/arch/riscv/kernel/traps.c index 80230de167de..47afea4ff1a8 100644 --- a/arch/riscv/kernel/traps.c +++ b/arch/riscv/kernel/traps.c @@ -339,8 +339,10 @@ void do_trap_ecall_u(struct pt_regs *regs) =20 add_random_kstack_offset(); =20 - if (syscall >=3D 0 && syscall < NR_syscalls) + if (syscall >=3D 0 && syscall < NR_syscalls) { + syscall =3D array_index_nospec(syscall, NR_syscalls); syscall_handler(regs, syscall); + } =20 /* * Ultimately, this value will get limited by KSTACK_OFFSET_MAX(), --=20 2.51.0