mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: tip-bot for Peter Zijlstra <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: tglx@linutronix.de, hpa@zytor.com, peterz@infradead.org,
	linux-kernel@vger.kernel.org, mingo@kernel.org,
	cj.chengjian@huawei.com
Subject: [tip:locking/urgent] futex: Sanitize user address in set_robust_list()
Date: Thu, 28 Dec 2017 06:21:51 -0800	[thread overview]
Message-ID: <tip-8f3365e34f7519904d78d9fb6dd9e4bae606b9b5@git.kernel.org> (raw)
In-Reply-To: <20171206214007.GI3857@worktop>

Commit-ID:  8f3365e34f7519904d78d9fb6dd9e4bae606b9b5
Gitweb:     https://git.kernel.org/tip/8f3365e34f7519904d78d9fb6dd9e4bae606b9b5
Author:     Peter Zijlstra <peterz@infradead.org>
AuthorDate: Wed, 6 Dec 2017 22:40:08 +0100
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Thu, 28 Dec 2017 15:19:12 +0100

futex: Sanitize user address in set_robust_list()

Passing in unaligned variables messes up cmpxchg on a whole bunch of
architectures and causes a in kernel lockup when the robust list is
accessed. Also, not respecting the natural alignment of data structures is
pretty dumb to begin with.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: dvhart@infradead.org
Cc: xiexiuqi@huawei.com
Cc: Cheng Jian <cj.chengjian@huawei.com>
Cc: huawei.libin@huawei.com
Cc: stable@vger.kernel.org
Link: https://lkml.kernel.org/r/20171206214007.GI3857@worktop
---
 include/uapi/asm-generic/errno.h | 1 +
 kernel/futex.c                   | 5 +++++
 2 files changed, 6 insertions(+)

diff --git a/include/uapi/asm-generic/errno.h b/include/uapi/asm-generic/errno.h
index cf9c51a..e306ee4 100644
--- a/include/uapi/asm-generic/errno.h
+++ b/include/uapi/asm-generic/errno.h
@@ -119,5 +119,6 @@
 #define ERFKILL		132	/* Operation not possible due to RF-kill */
 
 #define EHWPOISON	133	/* Memory page has hardware error */
+#define EMORON		134	/* User did something particularly silly */
 
 #endif
diff --git a/kernel/futex.c b/kernel/futex.c
index 57d0b36..4f471aa 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -3262,6 +3262,8 @@ out:
 SYSCALL_DEFINE2(set_robust_list, struct robust_list_head __user *, head,
 		size_t, len)
 {
+	unsigned long address = (unsigned long)head;
+
 	if (!futex_cmpxchg_enabled)
 		return -ENOSYS;
 	/*
@@ -3270,6 +3272,9 @@ SYSCALL_DEFINE2(set_robust_list, struct robust_list_head __user *, head,
 	if (unlikely(len != sizeof(*head)))
 		return -EINVAL;
 
+	if (unlikely(address % __alignof__(*head)))
+		return -EMORON;
+
 	current->robust_list = head;
 
 	return 0;

  parent reply	other threads:[~2017-12-28 14:24 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-06 14:21 [PATCH] futex: use fault_in to avoid infinite loop Cheng Jian
2017-12-06 16:04 ` Peter Zijlstra
2017-12-06 21:40   ` Peter Zijlstra
2017-12-08  5:21     ` Darren Hart
2017-12-08 10:50       ` Peter Zijlstra
2017-12-08 12:42     ` chengjian (D)
2017-12-28 14:21     ` tip-bot for Peter Zijlstra [this message]
2017-12-30  7:40     ` Michael Kerrisk

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=tip-8f3365e34f7519904d78d9fb6dd9e4bae606b9b5@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=cj.chengjian@huawei.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    /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

Powered by JetHome