mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kamal Mostafa <kamal@canonical.com>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org,
	kernel-team@lists.ubuntu.com
Cc: Andy Lutomirski <luto@amacapital.net>,
	Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	"security@kernel.org" <security@kernel.org>,
	Willy Tarreau <w@1wt.eu>, Ingo Molnar <mingo@kernel.org>,
	Kamal Mostafa <kamal@canonical.com>
Subject: [PATCH 3.13.y-ckt 05/19] x86/tls: Validate TLS entries to protect espfix
Date: Thu, 15 Jan 2015 14:09:41 -0800	[thread overview]
Message-ID: <1421359795-11155-6-git-send-email-kamal@canonical.com> (raw)
In-Reply-To: <1421359795-11155-1-git-send-email-kamal@canonical.com>

3.13.11-ckt14 -stable review patch.  If anyone has any objections, please let me know.

------------------

From: Andy Lutomirski <luto@amacapital.net>

commit 41bdc78544b8a93a9c6814b8bbbfef966272abbe upstream.

Installing a 16-bit RW data segment into the GDT defeats espfix.
AFAICT this will not affect glibc, Wine, or dosemu at all.

Signed-off-by: Andy Lutomirski <luto@amacapital.net>
Acked-by: H. Peter Anvin <hpa@zytor.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: security@kernel.org <security@kernel.org>
Cc: Willy Tarreau <w@1wt.eu>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
---
 arch/x86/kernel/tls.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
index f7fec09..e7650bd 100644
--- a/arch/x86/kernel/tls.c
+++ b/arch/x86/kernel/tls.c
@@ -27,6 +27,21 @@ static int get_free_idx(void)
 	return -ESRCH;
 }
 
+static bool tls_desc_okay(const struct user_desc *info)
+{
+	if (LDT_empty(info))
+		return true;
+
+	/*
+	 * espfix is required for 16-bit data segments, but espfix
+	 * only works for LDT segments.
+	 */
+	if (!info->seg_32bit)
+		return false;
+
+	return true;
+}
+
 static void set_tls_desc(struct task_struct *p, int idx,
 			 const struct user_desc *info, int n)
 {
@@ -66,6 +81,9 @@ int do_set_thread_area(struct task_struct *p, int idx,
 	if (copy_from_user(&info, u_info, sizeof(info)))
 		return -EFAULT;
 
+	if (!tls_desc_okay(&info))
+		return -EINVAL;
+
 	if (idx == -1)
 		idx = info.entry_number;
 
@@ -192,6 +210,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
 {
 	struct user_desc infobuf[GDT_ENTRY_TLS_ENTRIES];
 	const struct user_desc *info;
+	int i;
 
 	if (pos >= GDT_ENTRY_TLS_ENTRIES * sizeof(struct user_desc) ||
 	    (pos % sizeof(struct user_desc)) != 0 ||
@@ -205,6 +224,10 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
 	else
 		info = infobuf;
 
+	for (i = 0; i < count / sizeof(struct user_desc); i++)
+		if (!tls_desc_okay(info + i))
+			return -EINVAL;
+
 	set_tls_desc(target,
 		     GDT_ENTRY_TLS_MIN + (pos / sizeof(struct user_desc)),
 		     info, count / sizeof(struct user_desc));
-- 
1.9.1


  parent reply	other threads:[~2015-01-15 22:10 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-15 22:09 [3.13.y-ckt stable] Linux 3.13.11-ckt14 stable review Kamal Mostafa
2015-01-15 22:09 ` [PATCH 3.13.y-ckt 01/19] [3.13-stable only] ipv6: fix swapped ipv4/ipv6 mtu_reduced callbacks Kamal Mostafa
2015-01-15 22:09 ` [PATCH 3.13.y-ckt 02/19] e1000e: Fix no connectivity when driver loaded with cable out Kamal Mostafa
2015-01-15 22:09 ` [PATCH 3.13.y-ckt 03/19] usb: gadget: at91_udc: move prepare clk into process context Kamal Mostafa
2015-01-15 22:09 ` [PATCH 3.13.y-ckt 04/19] [3.13-stable only] KVM: x86: Fix far-jump to non-canonical check Kamal Mostafa
2015-01-15 22:09 ` Kamal Mostafa [this message]
2015-01-15 22:09 ` [PATCH 3.13.y-ckt 06/19] userns: Check euid no fsuid when establishing an unprivileged uid mapping Kamal Mostafa
2015-01-15 22:09 ` [PATCH 3.13.y-ckt 07/19] userns: Document what the invariant required for safe unprivileged mappings Kamal Mostafa
2015-01-15 22:09 ` [PATCH 3.13.y-ckt 08/19] userns: Only allow the creator of the userns " Kamal Mostafa
2015-01-15 22:09 ` [PATCH 3.13.y-ckt 09/19] x86_64, switch_to(): Load TLS descriptors before switching DS and ES Kamal Mostafa
2015-01-15 22:09 ` [PATCH 3.13.y-ckt 10/19] isofs: Fix infinite looping over CE entries Kamal Mostafa
2015-01-15 22:09 ` [PATCH 3.13.y-ckt 11/19] batman-adv: Calculate extra tail size based on queued fragments Kamal Mostafa
2015-01-15 22:09 ` [PATCH 3.13.y-ckt 12/19] KEYS: close race between key lookup and freeing Kamal Mostafa
2015-01-15 22:09 ` [PATCH 3.13.y-ckt 13/19] isofs: Fix unchecked printing of ER records Kamal Mostafa
2015-01-15 22:09 ` [PATCH 3.13.y-ckt 14/19] x86_64, vdso: Fix the vdso address randomization algorithm Kamal Mostafa
2015-01-15 22:09 ` [PATCH 3.13.y-ckt 15/19] groups: Consolidate the setgroups permission checks Kamal Mostafa
2015-01-15 22:09 ` [PATCH 3.13.y-ckt 16/19] userns: Don't allow setgroups until a gid mapping has been setablished Kamal Mostafa
2015-01-15 22:09 ` [PATCH 3.13.y-ckt 17/19] userns: Don't allow unprivileged creation of gid mappings Kamal Mostafa
2015-01-15 22:09 ` [PATCH 3.13.y-ckt 18/19] move d_rcu from overlapping d_child to overlapping d_alias Kamal Mostafa
2015-01-15 22:09 ` [PATCH 3.13.y-ckt 19/19] deal with deadlock in d_walk() Kamal Mostafa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1421359795-11155-6-git-send-email-kamal@canonical.com \
    --to=kamal@canonical.com \
    --cc=kernel-team@lists.ubuntu.com \
    --cc=konrad.wilk@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=mingo@kernel.org \
    --cc=security@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=w@1wt.eu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®