Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2427935imj; Mon, 18 Feb 2019 05:56:43 -0800 (PST) X-Google-Smtp-Source: AHgI3Iaj20bBReQJ4AsTsTCXm+L6Pv18KafR9cJ2NDmwQYcenW5ZowzuZA1McgWg5hmsxD8QMeBG X-Received: by 2002:a62:68c5:: with SMTP id d188mr24912345pfc.194.1550498203796; Mon, 18 Feb 2019 05:56:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550498203; cv=none; d=google.com; s=arc-20160816; b=jqCKFh66hrGLgQNMba1Zo+q9Rfs0nu9+NJnWZMJPeHRVKJ08o4+7HhTo7LcUdSiduN t1Yu4zMkOb6NaYZJdLCaY+zaYA+pnzbG60PJJcuVFiETQ7S9iHLE4IjkIKhFTlmCFse7 YleGInMi4SOB4YPz/r8ZrJAMhf4v2MYC4IrVWXn/huUm5SoEjjUxBSxaS/w8tyv6hwZ2 aENSoKp34UtRStodoBvkYt+ECKa+767G5oARdu1GPGInODxbHLbl4Ym5bDmV5MADiSSv gPKUbGq+CWNQZT0afU05ThROS2k6FnNyiT069n1gG9Jw4wGWkKu0R+Cern1P/KCERdBj OXog== 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=JULCQEvNu5BWshnSg5tm92pQMuDhA3CkPK8Buyg2494=; b=LkbqMPpLNTL92CXIfJVNMe6m+WX1jxZ+yc0A8zHPfVMQhKnsLMGrafm7II+Kjh60yG 76pIBOMfvkkgm2Me0JounRkcuAi8Izy354nEC0jTe9eYDwL/xIUfU0Hg45BfbIkEbL3R wuitl7rmur9CgIAqHNnZX7h/A4Ss2oVju3II2BhMxeYhEEdkXAgmmIb9OsUvvtr5RJq4 xqKpLz93N/89ya48+hlbvIM78UMEKKTVSHFkfKSt3qKFykPal3qDqiwBjIdJSIlOVSE7 zYDK7CfYGgdb/G5WBF5uC+PD3eFLyONL78A4xORJXPP8TCiHTcysxBuzMDIWDxvB+ZQK uS6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CVO9oBzp; 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 p18si12747362pgk.308.2019.02.18.05.56.27; Mon, 18 Feb 2019 05:56:43 -0800 (PST) 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=CVO9oBzp; 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 S1733198AbfBRNy2 (ORCPT + 99 others); Mon, 18 Feb 2019 08:54:28 -0500 Received: from mail.kernel.org ([198.145.29.99]:34330 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733176AbfBRNyZ (ORCPT ); Mon, 18 Feb 2019 08:54:25 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.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 1B7D920842; Mon, 18 Feb 2019 13:54:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1550498064; bh=cZEjMsv0a9fBzHaLUek698UUgzFvP3U3VV3rbi7ffH0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CVO9oBzp5Ic6T88GU+KnS7VYji4gmMPTYWtH6QS0IheEFUZ9/5/ehlpMGAVFVJ1J2 VGgcpIqvIRBkJfdAHgFd5fxk5BgoC+4nwrWpRiiKorOWm3mpNrTcHtN9GO/WMMlmJS 3VqZbCZvnIE1iaVtEfqkbmFQqMI2LbgwX0Iegb+s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Julien Thierry , Russell King , "David A. Long" , Sasha Levin Subject: [PATCH 4.14 12/62] ARM: 8796/1: spectre-v1,v1.1: provide helpers for address sanitization Date: Mon, 18 Feb 2019 14:43:18 +0100 Message-Id: <20190218133506.884592404@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190218133505.801423074@linuxfoundation.org> References: <20190218133505.801423074@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ Commit afaf6838f4bc896a711180b702b388b8cfa638fc upstream. Introduce C and asm helpers to sanitize user address, taking the address range they target into account. Use asm helper for existing sanitization in __copy_from_user(). Signed-off-by: Julien Thierry Signed-off-by: Russell King Signed-off-by: David A. Long Reviewed-by: Julien Thierry Signed-off-by: Sasha Levin --- arch/arm/include/asm/assembler.h | 11 +++++++++++ arch/arm/include/asm/uaccess.h | 26 ++++++++++++++++++++++++++ arch/arm/lib/copy_from_user.S | 6 +----- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/arch/arm/include/asm/assembler.h b/arch/arm/include/asm/assembler.h index b17ee03d280b..88286dd483ff 100644 --- a/arch/arm/include/asm/assembler.h +++ b/arch/arm/include/asm/assembler.h @@ -467,6 +467,17 @@ THUMB( orr \reg , \reg , #PSR_T_BIT ) #endif .endm + .macro uaccess_mask_range_ptr, addr:req, size:req, limit:req, tmp:req +#ifdef CONFIG_CPU_SPECTRE + sub \tmp, \limit, #1 + subs \tmp, \tmp, \addr @ tmp = limit - 1 - addr + addhs \tmp, \tmp, #1 @ if (tmp >= 0) { + subhss \tmp, \tmp, \size @ tmp = limit - (addr + size) } + movlo \addr, #0 @ if (tmp < 0) addr = NULL + csdb +#endif + .endm + .macro uaccess_disable, tmp, isb=1 #ifdef CONFIG_CPU_SW_DOMAIN_PAN /* diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h index cf50b030c62c..a5807b67ca8a 100644 --- a/arch/arm/include/asm/uaccess.h +++ b/arch/arm/include/asm/uaccess.h @@ -99,6 +99,32 @@ static inline void set_fs(mm_segment_t fs) #define __inttype(x) \ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL)) +/* + * Sanitise a uaccess pointer such that it becomes NULL if addr+size + * is above the current addr_limit. + */ +#define uaccess_mask_range_ptr(ptr, size) \ + ((__typeof__(ptr))__uaccess_mask_range_ptr(ptr, size)) +static inline void __user *__uaccess_mask_range_ptr(const void __user *ptr, + size_t size) +{ + void __user *safe_ptr = (void __user *)ptr; + unsigned long tmp; + + asm volatile( + " sub %1, %3, #1\n" + " subs %1, %1, %0\n" + " addhs %1, %1, #1\n" + " subhss %1, %1, %2\n" + " movlo %0, #0\n" + : "+r" (safe_ptr), "=&r" (tmp) + : "r" (size), "r" (current_thread_info()->addr_limit) + : "cc"); + + csdb(); + return safe_ptr; +} + /* * Single-value transfer routines. They automatically use the right * size if we just have the right pointer type. Note that the functions diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S index a826df3d3814..6709a8d33963 100644 --- a/arch/arm/lib/copy_from_user.S +++ b/arch/arm/lib/copy_from_user.S @@ -93,11 +93,7 @@ ENTRY(arm_copy_from_user) #ifdef CONFIG_CPU_SPECTRE get_thread_info r3 ldr r3, [r3, #TI_ADDR_LIMIT] - adds ip, r1, r2 @ ip=addr+size - sub r3, r3, #1 @ addr_limit - 1 - cmpcc ip, r3 @ if (addr+size > addr_limit - 1) - movcs r1, #0 @ addr = NULL - csdb + uaccess_mask_range_ptr r1, r2, r3, ip #endif #include "copy_template.S" -- 2.19.1