Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp846842ybi; Fri, 12 Jul 2019 05:37:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqwMW5Laf4vud9+WX6WDeaA2yuxic/wMzSLMzPV0/yQAizDPJYeA7WHduXb/kmPwLG6kMzhu X-Received: by 2002:a17:90a:80c4:: with SMTP id k4mr11698159pjw.74.1562935073247; Fri, 12 Jul 2019 05:37:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562935073; cv=none; d=google.com; s=arc-20160816; b=vj0gYMSfNBsSTD3IFlHVeukf14fjjOyIR++YsCaLZw9jA6mIb6ZhUHgPIbdS18h6B2 Lao3NtfEITMtW3LWhTEMkTCZXSfb/jIBuompioXsfNEYucgJ4wyferHhJpvSOviCsQqw LjVAdeNwrWXSgguyG0LepjM8WMx48AnS4H9VbeKxPiQHv/EcTjE3q3aL04da2/izHen8 irob1JPbV89YL3Vn6rJ3c4vMJ9TnVMxQs5SG9vrJ2KaOsd/kAw1+HJofmRy28WPi5ANk 3HD1A52wj+8J+KWHTd/f5mRDoashogEHT+0lKo3yk+UnSXo6bCuvKnlWJx5Tvxw1ADPb C4wA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+OuD8NeGkN7GWBrK4ihj37/s9OTxkPety2cYeaW5GJQ=; b=sf0cxDNCwvQUjrAjDNnbLe/NMmJYjo0QTh8aLLePoa/fXnuFSZKLRaGZiZRpM7EQsd xwfzIHDoKjjyb73mJdb0q4/0lcjykXolu7dQrL/UkussbbMq6Ay5cuakW+kLjLplG74G VU5KBEI25B4MEPO03wIu1NLPDGo8pG8kLpmWbue65lJCjh9H7VcLmIztIBRQqEDvdI6f 4b+4U3pQP7/gptz6mLEfIHZ6wkoVx9ZO3knhE4CrhQSUByNcGYIRYfxxdjK4HdqybUYU dujf0CCJM+xp2fkXvA1BXQbDZN4VF/dCjIhu+hX3zckms/uFOA/BuvgKzVivw4LtIL6+ VOTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ogENqcf+; 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 q23si7517402pjp.63.2019.07.12.05.37.38; Fri, 12 Jul 2019 05:37:53 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=ogENqcf+; 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 S1729493AbfGLMch (ORCPT + 99 others); Fri, 12 Jul 2019 08:32:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:50762 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728956AbfGLMcf (ORCPT ); Fri, 12 Jul 2019 08:32:35 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 69F42216E3; Fri, 12 Jul 2019 12:32:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562934754; bh=c9LPplSzz/uVr4cX4W0O58ybJ3HneGqBkRGgS8Tz5aI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ogENqcf+lRVGgQOWcH/ehQMt/6CT9VcmlCrfq9dLaTaehRFMBMsbS4pkk6lZ66/jD gB36AkJqvelw4UrSCiJgQtXjbnvqTa2ltY7T5A9fmJL9c2A8/ekGBLW1wZ+guEUhiQ r6LkLzJ+GlpYN7ai+xqr8N6E64kpZ4foeoR1Eqbo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dianzhang Chen , Thomas Gleixner , bp@alien8.de, hpa@zytor.com Subject: [PATCH 5.2 20/61] x86/tls: Fix possible spectre-v1 in do_get_thread_area() Date: Fri, 12 Jul 2019 14:19:33 +0200 Message-Id: <20190712121621.731120287@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190712121620.632595223@linuxfoundation.org> References: <20190712121620.632595223@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dianzhang Chen commit 993773d11d45c90cb1c6481c2638c3d9f092ea5b upstream. The index to access the threads tls array is controlled by userspace via syscall: sys_ptrace(), hence leading to a potential exploitation of the Spectre variant 1 vulnerability. The index can be controlled from: ptrace -> arch_ptrace -> do_get_thread_area. Fix this by sanitizing the user supplied index before using it to access the p->thread.tls_array. Signed-off-by: Dianzhang Chen Signed-off-by: Thomas Gleixner Cc: bp@alien8.de Cc: hpa@zytor.com Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/1561524630-3642-1-git-send-email-dianzhangchen0@gmail.com Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/tls.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) --- a/arch/x86/kernel/tls.c +++ b/arch/x86/kernel/tls.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -220,6 +221,7 @@ int do_get_thread_area(struct task_struc struct user_desc __user *u_info) { struct user_desc info; + int index; if (idx == -1 && get_user(idx, &u_info->entry_number)) return -EFAULT; @@ -227,8 +229,11 @@ int do_get_thread_area(struct task_struc if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX) return -EINVAL; - fill_user_desc(&info, idx, - &p->thread.tls_array[idx - GDT_ENTRY_TLS_MIN]); + index = idx - GDT_ENTRY_TLS_MIN; + index = array_index_nospec(index, + GDT_ENTRY_TLS_MAX - GDT_ENTRY_TLS_MIN + 1); + + fill_user_desc(&info, idx, &p->thread.tls_array[index]); if (copy_to_user(u_info, &info, sizeof(info))) return -EFAULT;