Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753587AbdL1OYh (ORCPT ); Thu, 28 Dec 2017 09:24:37 -0500 Received: from terminus.zytor.com ([65.50.211.136]:35395 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751411AbdL1OYg (ORCPT ); Thu, 28 Dec 2017 09:24:36 -0500 Date: Thu, 28 Dec 2017 06:21:51 -0800 From: tip-bot for Peter Zijlstra Message-ID: Cc: tglx@linutronix.de, hpa@zytor.com, peterz@infradead.org, linux-kernel@vger.kernel.org, mingo@kernel.org, cj.chengjian@huawei.com Reply-To: linux-kernel@vger.kernel.org, peterz@infradead.org, hpa@zytor.com, tglx@linutronix.de, mingo@kernel.org, cj.chengjian@huawei.com In-Reply-To: <20171206214007.GI3857@worktop> References: <20171206214007.GI3857@worktop> To: linux-tip-commits@vger.kernel.org Subject: [tip:locking/urgent] futex: Sanitize user address in set_robust_list() Git-Commit-ID: 8f3365e34f7519904d78d9fb6dd9e4bae606b9b5 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2072 Lines: 61 Commit-ID: 8f3365e34f7519904d78d9fb6dd9e4bae606b9b5 Gitweb: https://git.kernel.org/tip/8f3365e34f7519904d78d9fb6dd9e4bae606b9b5 Author: Peter Zijlstra AuthorDate: Wed, 6 Dec 2017 22:40:08 +0100 Committer: Thomas Gleixner 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) Signed-off-by: Thomas Gleixner Cc: dvhart@infradead.org Cc: xiexiuqi@huawei.com Cc: Cheng Jian 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;