Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp839586ybi; Fri, 12 Jul 2019 05:31:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqxbKYdquGR7flZmVSnYmkm5cFoJeRUyFrYMMQV2a9T6DFg+loKGQy6yk2lVUREir4CrJ1DR X-Received: by 2002:a63:5463:: with SMTP id e35mr10381586pgm.451.1562934664590; Fri, 12 Jul 2019 05:31:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562934664; cv=none; d=google.com; s=arc-20160816; b=pkAmcLzm7Y7d5bkDNkYOXC6pIfLBYlxryV9tGVl0ZvbMsL8YYdMymFrMAhcUgPcrNr Zm0/7YvsMlTpduEGLqXYT8rsDSmZCPUqow6HovO2ZSabr8GRgeys2YM4iXY9wdsJ3gOc ZU80kBMDgU3LQhQbPmGr+7NuOC0bS01MCsyjiZOTR/r6BaL4y2Mb9QNN7OFFSFAn6I8i hTtg5Oy2ylauBFOAYS/et3L2Ef66UMxo68xZvtczxTQUcIIeN3BTqCTrHwihx612Xgog hNBuW6qHNp4RUR3AcMcKa+evnnpIaPdeB2Pmq3Q68XZekqVabu/vmotl1MSVYnrmUlNX 9QCw== 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=J2k1I0+txRwoEtV35kTLDk3gAFacreK6L+c2h12eG2D+c5Fq0PDUmTzTeIBZLjxd69 xI0kCNS4yqyJsglKw0ozWNNUyPz6ERQ08yJAfuUwyE2xgSSDNgWjnSSkTqVwZOGx8pxL oBJNCKUn1EfwWFEfGF8Fsy41d4zk+/15NuEjhgopQ/pK0suZ9iEoSfxkUyUpW4t7BnR1 QLj4hDHkolhAVq6WhEvvTLC28X2Dv60KPHDJQ/7mYjsnkQHphOs6j8bExgfY9mUyOPbT r9QarBNOkV6q2n253tTi0RwQLQLc+e5CaWtm3s/WN1UOSJQFdHHoiF6JyLIOB4KLRafE 0M0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="I9/yRjwB"; 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 r6si7760940pls.145.2019.07.12.05.30.49; Fri, 12 Jul 2019 05:31:04 -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="I9/yRjwB"; 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 S1729045AbfGLM3w (ORCPT + 99 others); Fri, 12 Jul 2019 08:29:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:44932 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728697AbfGLM3r (ORCPT ); Fri, 12 Jul 2019 08:29:47 -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 51D4121019; Fri, 12 Jul 2019 12:29:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562934586; bh=c9LPplSzz/uVr4cX4W0O58ybJ3HneGqBkRGgS8Tz5aI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I9/yRjwBkJcBKeuxl4Rb6lbwSJuNUQJ8la+oK2dZcirzU4NsfAV+9yheKpCDPJRbg b0d+zXVVtbRj5bdFNtN0ge9LLyPx7cZKSogu/5c5DILBvPqrZWcW0MUy5bHwQsIAgV EGy3aCojIvUXezCuKAblvxiDCvPBDQSWc0ww8DhY= 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.1 103/138] x86/tls: Fix possible spectre-v1 in do_get_thread_area() Date: Fri, 12 Jul 2019 14:19:27 +0200 Message-Id: <20190712121632.716444080@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190712121628.731888964@linuxfoundation.org> References: <20190712121628.731888964@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;