Received: by 10.223.176.5 with SMTP id f5csp690130wra; Fri, 9 Feb 2018 05:45:41 -0800 (PST) X-Google-Smtp-Source: AH8x227GcXoUNGgerV+JHQCEbSsMALkxwhM/gMWVWxwWPOkK7EAyzVssVwU2DxB3xME2N9F7uRdb X-Received: by 10.99.120.139 with SMTP id t133mr2428618pgc.382.1518183940970; Fri, 09 Feb 2018 05:45:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518183940; cv=none; d=google.com; s=arc-20160816; b=Np7jKYkK47iitHDMZg9gsmWuN/p7jhXEqOlomP8rasUB0ASh0tk1/m8A1wg/CThMBn zXCpmcEKqXhlV84saF9fBgOOXzv1tNzmHbkkZcrNJj26a4dQqbYg0LrUV4QGuF7iX94s VE0haQzCEhVmoyhXYsuaoQgdTtFfaoAgejUR1d+caZVTSU1MGULJaGuOiNTIy8vvXR62 wHuFzt8xdzXPkJyNUlXKr8xiTOAlvkrFPOfG5E+XtZdUdtseecqcBepLSWnfyPQRcBrn DHRMweWp6UaKsIFbpylbgjQwJhq2KWpUVj8HrILOxkR+O7NUERONUMlv4mJIuzZzqCam roHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=rqZ31J0FQdm4UJdbIPgg52bezpe5DIWzu+cZ/5xHiPc=; b=FCQcvq2UwO1SywHKn0EGr+Eedljyu3P540n0rCwhMUKK/JNID3zvvvbE+0NnMnKQi0 hsNKSxOzAzQHWzGC+/qkogpbP3YTCTqjbCppbtAMyl9fthctWmHezdJU/+o6Cb8WaJnu dfRMe7CI9/Hueeny/GJea7qeluzGfXlMDVU2EiTB346qfEG4w1u1/z7TWM/26aLGIIpw BEv3tqMGI5eMmOdZ4qsaro6QkxwCtfD1AC0z8ufOTQc9/FXB/PfZv2Ho3TRcUVUYiwsd JPzcEsyrRzK6RGn/pywmenT4NmOXkWwP+tzoFGkV7Y+ghpmKyyFKrv944sejqYDYTnVq BqkA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t64si1368567pgc.749.2018.02.09.05.45.26; Fri, 09 Feb 2018 05:45:40 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753224AbeBINn2 (ORCPT + 99 others); Fri, 9 Feb 2018 08:43:28 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:50658 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752261AbeBINnZ (ORCPT ); Fri, 9 Feb 2018 08:43:25 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id BAB4F103C; Fri, 9 Feb 2018 13:43:09 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Linus Torvalds , Dan Williams , Thomas Gleixner , linux-arch@vger.kernel.org, kernel-hardening@lists.openwall.com, Andy Lutomirski , alan@linux.intel.com, David Woodhouse Subject: [PATCH 4.9 64/92] x86/syscall: Sanitize syscall table de-references under speculation Date: Fri, 9 Feb 2018 14:39:33 +0100 Message-Id: <20180209133935.882457967@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180209133931.211869118@linuxfoundation.org> References: <20180209133931.211869118@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dan Williams (cherry picked from commit 2fbd7af5af8665d18bcefae3e9700be07e22b681) The syscall table base is a user controlled function pointer in kernel space. Use array_index_nospec() to prevent any out of bounds speculation. While retpoline prevents speculating into a userspace directed target it does not stop the pointer de-reference, the concern is leaking memory relative to the syscall table base, by observing instruction cache behavior. Reported-by: Linus Torvalds Signed-off-by: Dan Williams Signed-off-by: Thomas Gleixner Cc: linux-arch@vger.kernel.org Cc: kernel-hardening@lists.openwall.com Cc: gregkh@linuxfoundation.org Cc: Andy Lutomirski Cc: alan@linux.intel.com Link: https://lkml.kernel.org/r/151727417984.33451.1216731042505722161.stgit@dwillia2-desk3.amr.corp.intel.com Signed-off-by: David Woodhouse Signed-off-by: Greg Kroah-Hartman --- arch/x86/entry/common.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) --- a/arch/x86/entry/common.c +++ b/arch/x86/entry/common.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -277,7 +278,8 @@ __visible void do_syscall_64(struct pt_r * regs->orig_ax, which changes the behavior of some syscalls. */ if (likely((nr & __SYSCALL_MASK) < NR_syscalls)) { - regs->ax = sys_call_table[nr & __SYSCALL_MASK]( + nr = array_index_nospec(nr & __SYSCALL_MASK, NR_syscalls); + regs->ax = sys_call_table[nr]( regs->di, regs->si, regs->dx, regs->r10, regs->r8, regs->r9); } @@ -313,6 +315,7 @@ static __always_inline void do_syscall_3 } if (likely(nr < IA32_NR_syscalls)) { + nr = array_index_nospec(nr, IA32_NR_syscalls); /* * It's possible that a 32-bit syscall implementation * takes a 64-bit parameter but nonetheless assumes that