Received: by 10.223.176.5 with SMTP id f5csp2848577wra; Mon, 5 Feb 2018 10:54:27 -0800 (PST) X-Google-Smtp-Source: AH8x2273ME+iFfrqmbDMnAOi2EqLucUeVqKwiJDJbnWg9STI0PqW+qokJbzRGcVTVB3B2xq3ERvT X-Received: by 2002:a17:902:5a05:: with SMTP id q5-v6mr10946073pli.152.1517856867551; Mon, 05 Feb 2018 10:54:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517856867; cv=none; d=google.com; s=arc-20160816; b=jfh+NW2ie/IpK47FsGFEGDFsJnQrmcS1qghFEd3TssYeZTmDQx1tq0KnGrjWsYZUSW IlN5oqbJvhWIdU/igo7Wg6OXisVv3KyZ6vf8nTsvFfPIIFgxmwRC1BAKD+Vo4lChQn4L /MLW59XSr1AbbpSk7jXOIMr0g3NBbt36pjf3dnXFixAcXAvA2wlvNTyp2Ov7dxH9fR06 D+ONOdDSFVfUOumLW46VOzeBxabDqCWskDeHnieDKEa2tYHBiq8+g4i3VawVvO7hTgIr XO9ntbm9zblZTDFpHTnsRmC1jNuTeFg8gbq4jMcEjYlXYk/fszmz0YRXKpNtaTbaNWLu yFrQ== 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=RQeE7capP/jrjJMaLqf/QwkBdWS9xA5WfMUeJPjv+qU=; b=y01t002WlxiqwcXYl2y72PCSurslZZSXYTQ3tOvGKRzrbVSq4EBFidfg8ReKivU5nF /8VVXjjzb3a7f34/GwrEE5YkDDDwb9o39VaMmm3s7nrgsv97/MK6HsO0zjrWqSiS7fZz ZE8gq38aZGQ9SWinUdBAhYG7s0yCQM5qwuWA12pn1Ch1G7PfseSPMkpxGZh8yrWA9E01 nPzskKK23f+8cx/4OtCwntCYIWl8PgXdV7LTK4/2cqKP0NeymsYUaNBQsmEtTZbo3pSQ Oz8XmFzEKNw/HaKSTfTpIYrEyYS6GOiIPESAjUvYbeGwWPdE2DmzxJ3yA2zgDg3M5g4a /E4g== 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 g3-v6si181254plb.331.2018.02.05.10.54.13; Mon, 05 Feb 2018 10:54:27 -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 S1753835AbeBESxv (ORCPT + 99 others); Mon, 5 Feb 2018 13:53:51 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:52834 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753456AbeBESZk (ORCPT ); Mon, 5 Feb 2018 13:25:40 -0500 Received: from localhost (unknown [104.132.1.108]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id F15B4113D; Mon, 5 Feb 2018 18:25:25 +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.15 40/60] x86/syscall: Sanitize syscall table de-references under speculation Date: Mon, 5 Feb 2018 10:23:13 -0800 Message-Id: <20180205182215.617155182@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180205182213.902626065@linuxfoundation.org> References: <20180205182213.902626065@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.15-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 @@ -282,7 +283,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); } @@ -318,6 +320,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