Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp4010580ybd; Tue, 25 Jun 2019 12:22:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqwmfSFawUxEeGnUS3O+Nukm/Pf/2K3jGyP/LBcrLkQV0+o+Au1wWQE3LIet2xMYsjwFVeEN X-Received: by 2002:a63:9143:: with SMTP id l64mr29586179pge.65.1561490571740; Tue, 25 Jun 2019 12:22:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561490571; cv=none; d=google.com; s=arc-20160816; b=jLMNlFNtExF1KKTEoU5JNJXoQRDC0mOueffDsRg4xk1fOT447sTL/BaAS7r/QqMwOp 2e5TZVGuJi2vjbtcu3cC9zIYdJdLU09RC3xQadYpWiCRpnc39saHpTK2nreag9oM9dhb NRvCDDEjoEgJDNRn5pps1ZhahrVVJnCVt7NTTnp3ZiIjVPsPVicOy/5esSs1UZFYpHZj ECkZ4zawszLOTuL7r4wjSq/L6sOZ6sVxHrA2BVlWTnI7EG7Xr8XgWzoEAozjNnwXE0m3 OuU99ugh5R5aqFOUnxYS+nfetdklVuZUwyNu+lcYKCrmjoJvrUygUiY0J0+dC+BeavuB GcOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=PEwqdcBJhdsaGNwQ8qE4axyMsE12bW7MvOTK5Jf6qqU=; b=tW/QgFGgjfKS0SGyoLHocYdqm5fA4UmXV9IjJlBPFa+65L8NsrgNipKk0Zl/6Jma5K U8EXegB6xxtNg3GVPOOorVGJ6q7lCTX3y1DUj7piqCvD6UKpUy0wVor8OTzGnlu2Wg91 mU2l2njVKTv+GzonBUdcxFQ9QN4tXdlaE8Ci13PDAVQ4yk35blS+mD327PVMbIRNjdUy J0MD8n2J1yyUu/P8aONcCmXMbE/EICmfZThf13MC1mldhPMzTFfykoz5iNIwznYEPrTC l2UrKoqK3ipW+nNEj47o3HO0T0CPzuNSr/MbIvsIbG+3BLydnL+JJzV0O4vTTQocUJe0 Ek1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ti3NlNQ6; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id cl7si1084989plb.267.2019.06.25.12.22.36; Tue, 25 Jun 2019 12:22:51 -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=@gmail.com header.s=20161025 header.b=ti3NlNQ6; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728636AbfFYQXP (ORCPT + 99 others); Tue, 25 Jun 2019 12:23:15 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:44789 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726740AbfFYQXO (ORCPT ); Tue, 25 Jun 2019 12:23:14 -0400 Received: by mail-pf1-f194.google.com with SMTP id t16so9724186pfe.11 for ; Tue, 25 Jun 2019 09:23:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=PEwqdcBJhdsaGNwQ8qE4axyMsE12bW7MvOTK5Jf6qqU=; b=ti3NlNQ62g67PQgPc9j9llrb2zEXYEBG+Q5EGe0fV3A64ndBCBOu3k+b46nE1nbCpG x+/FVoVhF5daJhzBCgl+Ix9APbMaph1HrCt3Bf/ZeN62s5qPQy7UHbFB0DllWPnTx8St T1RZx8QYUJScxpD9lLoL2bj/nS+VJFo/TNS2HIATAURqVW7qZIQEwEfZ4ieRkSv5BQPO gTFuPtKbss9dUwucRDmTxsCnc6sMvO9u2HgBnZzr9quBjJmwTGO6PeixYrOVznfFpCdT 2FXBHwCtSJmw3Zn4rt9xwb1o9/fvdyD0iGh64DpKs9B5rTI/5hTdoHFX/OuLYx++LSc6 CIrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=PEwqdcBJhdsaGNwQ8qE4axyMsE12bW7MvOTK5Jf6qqU=; b=Zlg0e5ZuhR3eQY284pFpjAndvA6qbZHCp+hGZeHIkBUIsEkX35Q+jD7OdvC7lZtYSj nHM2ZofykHDk3HW8ijAgkR0nQ8YyIoAR/dQ1cLXEFM0/UoyUUqCZBBjcuep/MLOsu8aG BVeFP7byc9mFw3Wxx5kPOJIlcAu8LHNEQNDFW9QVGm8xp/LFkX4MJlwu+RKstC7b/mrQ /fR1J+5y6l2qe9D51UvUFFg3J+mablgdhi1L7Yozs2IhT1QQAyggZN/TPXQFWARnQUW4 asWwGHOHi+TLHn1bk623PdAgdEWV46DizgDLMUE2gGsufVpDQXaLUWHMy7HSfUgvJZ8N Tv+g== X-Gm-Message-State: APjAAAU1oKIdPl8tVDM8/PIO1Y4RaiuIX7EpB80YaddtcMQ/vUCVzrZt 3QHKqjxelXRoFQ7TxmwgJiU= X-Received: by 2002:a17:90a:b00b:: with SMTP id x11mr33213904pjq.120.1561479794311; Tue, 25 Jun 2019 09:23:14 -0700 (PDT) Received: from tom-pc.ipads-lab.se.sjtu.edu.cn ([202.120.40.82]) by smtp.gmail.com with ESMTPSA id w132sm16436090pfd.78.2019.06.25.09.23.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 25 Jun 2019 09:23:13 -0700 (PDT) From: Dianzhang Chen To: tglx@linutronix.de Cc: mingo@redhat.com, bp@alien8.de, hpa@zytor.com, x86@kernel.org, linux-kernel@vger.kernel.org, Dianzhang Chen Subject: [PATCH v2] x86/tls: Fix possible spectre-v1 in do_get_thread_area() Date: Wed, 26 Jun 2019 00:22:59 +0800 Message-Id: <1561479779-6660-1-git-send-email-dianzhangchen0@gmail.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 idx can be controlled from: ptrace -> arch_ptrace -> do_get_thread_area. Fix this by sanitizing idx before using it to index p->thread.tls_array. Signed-off-by: Dianzhang Chen --- arch/x86/kernel/tls.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c index a5b802a..424cff5 100644 --- 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_struct *p, int idx, 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,9 @@ int do_get_thread_area(struct task_struct *p, int idx, 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; + + fill_user_desc(&info, idx, &p->thread.tls_array[index]); if (copy_to_user(u_info, &info, sizeof(info))) return -EFAULT; -- 2.7.4