Received: by 10.223.176.5 with SMTP id f5csp2853213wra; Mon, 5 Feb 2018 10:59:53 -0800 (PST) X-Google-Smtp-Source: AH8x224UOQkWxbqE+OjPbEEghEwaEzVMr0J3RXkuG7PS/rOQ0EMT9DWSwvTN3ozKQSk8HXMcvox6 X-Received: by 10.99.146.3 with SMTP id o3mr39721563pgd.309.1517857193708; Mon, 05 Feb 2018 10:59:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517857193; cv=none; d=google.com; s=arc-20160816; b=Lou4DkSNIZQJU72Fx2lAZlkZCA+FcpfdDLbcOeFW9TOZGrWZS2RrvJpo6HUbNCffd1 1NXEEoCo/3biwKBRUVn4+CEUdiT8aDUx4UtN0BxBtDfwAswKB9utq7QECyrsnB77ZpQn esPFbEF+ZDV3eFEqRG1dxSJG7j+Y2YM8Ne69RqiPI9VGhxchtjvb7CbQXCxr85t/vRML Ri3s6OKA4HUUICSzH5ulYtZrxRJFlZ/RGMqE7pvFmgNCob+0UMj7M1J75MrCL875x2Of F1Jpr4lmYbT3qXpMKMg30BFktrTEYw1Jj12PMJ35FP2PCX6V4nSRBQsaMAd5zqxi4fQu iWmw== 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=F2F1k/TGqhSoSptaBJeh49Kp94mrUWCZsk6nOKoTSWU=; b=p1J31XeV6lzLtb9HKLpJHJTuq7yT6x0O3dQnNcFXklpl74buwSi+dJqCuoy3VqD3C1 DDzDFGOaFCUwIh7ldgJgIcNWKe+UWB1bCINVKSwhGl7gUotnPI9ovsQ+gHod02HMwLWu AmfkuOmEPGJq/fojhhd1IsXknYSBXNeWNYP+1E0pYvctuWe55YWAUEND2yZV5LeC2EvY MCx0ykQvyZDgzrivCapHHYK87oXYAqDqwJlHOmXu7w4OIyWfohrMZhgpjOheknRkN8ui LS+kzlJPFlb9FlXXCoHJDWnv3IIFz5jACNuXq4vrtz5bl1pWMtQzZiQgtDSkK2FeB8Bf YBgg== 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 o12-v6si7342155plk.60.2018.02.05.10.59.39; Mon, 05 Feb 2018 10:59:53 -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 S1753395AbeBES7X (ORCPT + 99 others); Mon, 5 Feb 2018 13:59:23 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:51890 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753618AbeBESYq (ORCPT ); Mon, 5 Feb 2018 13:24:46 -0500 Received: from localhost (unknown [104.132.1.108]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id A8E35FE1; Mon, 5 Feb 2018 18:24:43 +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 Subject: [PATCH 4.14 44/64] x86/syscall: Sanitize syscall table de-references under speculation Date: Mon, 5 Feb 2018 10:23:03 -0800 Message-Id: <20180205182140.385565178@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180205182138.571333346@linuxfoundation.org> References: <20180205182138.571333346@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.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dan Williams dan.j.williams@intel.com 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: 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 @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -284,7 +285,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); } @@ -320,6 +322,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