Received: by 2002:ac0:a679:0:0:0:0:0 with SMTP id p54csp1497911imp; Fri, 22 Feb 2019 04:55:42 -0800 (PST) X-Google-Smtp-Source: AHgI3IbBhgQd99iSz26glhTHRlSCIjUJRTzqeEZAZQdgc3H0B7mWFS/KVr63h0mqryDXFFoWb2B9 X-Received: by 2002:a17:902:46a4:: with SMTP id p33mr4113600pld.48.1550840142080; Fri, 22 Feb 2019 04:55:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550840142; cv=none; d=google.com; s=arc-20160816; b=SLcaZKRNX3DR2UCb/u+zjpPBFrBLrQiW6ViEOESa9NZLfBB8GOYGG8P6LFDAfmVSWX pRCwnaRyHo4/ASli62PraSKKzYknk378zd2tUoTRLEpYjGTOToBK64gGBQS8wYUKBXEE L+4k107RueVMzzCoAEhRr4JauO7TBafOB2Ci1k4OMIUZzamx3tfDlR/d2uRB/ymhd8q2 liYcOnlY5lcfE32VmCtoODvDmzYAPc0rLYuHbNjQp+mhHEI3ciwYZfgoBdPM/K3tK909 opnGsz+OsdSxuXdozmjSSWOjPK6JwhnH47EsBq9WRqxYZtBJQRkxT7wN37ukrAYHFtg5 CRGA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=LYedl6oW+X0hODfB6yBlRZE+wsBGKemR/gV1w08gXes=; b=AGMhPxYdRvKZmLBFBf53xTpcb/zbIOUp1W1lvL9Ojy4KAtZjzIbgQN428YHZresxWX ia4IK+K6QG6XqrJjLLfbvIFzn1tL9dXf+Sc6URutym9I6RnST6A6f2s+HAYdADDJ7naG EX/ZW0/bFhVDGXDVoOkGWGpAhtZtRCIRv+yOaczFBFuiUPmQ5I6GJQvqK5QPbw/linbx TeB18BtoEJRIT0dS3o6CPgLv+vvMEhVx/PiFJEHdZ3E4rlK1xvGSybBbUSO5LKrBEBE3 WGRp7Eltci2fXmWAf+mB6yA1ImcaDu/nxj3n3+Rh60xcyxnEQtd0AO/EpulZ3MmISwfj J9uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=IZO5qs1i; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x6si1334921pfm.219.2019.02.22.04.55.27; Fri, 22 Feb 2019 04:55:42 -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=@google.com header.s=20161025 header.b=IZO5qs1i; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727113AbfBVMxh (ORCPT + 99 others); Fri, 22 Feb 2019 07:53:37 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:33432 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726812AbfBVMxf (ORCPT ); Fri, 22 Feb 2019 07:53:35 -0500 Received: by mail-wr1-f67.google.com with SMTP id i12so2292748wrw.0 for ; Fri, 22 Feb 2019 04:53:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LYedl6oW+X0hODfB6yBlRZE+wsBGKemR/gV1w08gXes=; b=IZO5qs1iTdFS0J8b6mUPkT96MHj4TvOOl4p+NkYj+K5QoPzgtV+ykf7Zu+OkLcqN2H XG3Gh3bG0jBem6M7NTIzz/wK5zl+vCUUNfkfJALSmU8Wj9A1u4sBy3ay4BW4/EmB0HRO rjkA4MwD6TdBTXlf++HuBJnMCfJk5iZzI3+4sXCvRuZvNLxSnSX00w7f+r2eMb9tbUeZ wKQkxlkxUte2ekBF+Cqk930FiD2BqGhYurasbJZ5Cy6szPm8dYUDDnFl+i7USfSEW4tE b+242VIYnFJCUhKNVLIKvM7y8Jwt7Fku92E8DCxmA2ENAr03DmnPf5Nks+jfBd0lKf0N y0ng== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=LYedl6oW+X0hODfB6yBlRZE+wsBGKemR/gV1w08gXes=; b=QlY41TBF0q176oGV3c+6U44XnTb+0laMVXsY0B0MhQhLtD4eL2Z1WSTdn8/LbWr6io X81VRaotSNSWdsZpKBJlpaT3jKncrMcQNhIEY89NNq4knr9uGxLmwOvMfv2wnNpoy1GL rSC80U64HQuuMPJuiOWWKbB6E093OIaj45Q7Q1+ZKlXRnyLHoc3ynfuN+ce1FjRvjUmi SRRSj5QCTbmtBIkxYQcDFdD7CgiUXCUq5/4LmwWHyCh8DmmJWikOZAPxzcYUuiyyXV92 UuwxifoumJwx3bsvkS0G5Ud86mZFp8H0Fo9nm1gQWkdxL8ws76xkv4oUafkOTEzqnk6t eecg== X-Gm-Message-State: AHQUAubxKSkxCfS0pnUGoAGuOpr53kbBeYUTwONc2wxd3jWRLrH6ZfAk l2MEZsAYSzjxYegCITuzk8QmqA== X-Received: by 2002:adf:e90b:: with SMTP id f11mr2972186wrm.36.1550840013762; Fri, 22 Feb 2019 04:53:33 -0800 (PST) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:13:8ce:d7fa:9f4c:492]) by smtp.gmail.com with ESMTPSA id o14sm808209wrp.34.2019.02.22.04.53.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Feb 2019 04:53:32 -0800 (PST) From: Andrey Konovalov To: Catalin Marinas , Will Deacon , Mark Rutland , Robin Murphy , Kees Cook , Kate Stewart , Greg Kroah-Hartman , Andrew Morton , Ingo Molnar , "Kirill A . Shutemov" , Shuah Khan , Vincenzo Frascino , linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Dmitry Vyukov , Kostya Serebryany , Evgeniy Stepanov , Lee Smith , Ramana Radhakrishnan , Jacob Bramley , Ruben Ayrapetyan , Chintan Pandya , Luc Van Oostenryck , Dave Martin , Kevin Brodsky , Szabolcs Nagy , Andrey Konovalov Subject: [PATCH v10 02/12] arm64: untag user pointers in access_ok and __uaccess_mask_ptr Date: Fri, 22 Feb 2019 13:53:14 +0100 Message-Id: X-Mailer: git-send-email 2.21.0.rc0.258.g878e2cd30e-goog In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org copy_from_user (and a few other similar functions) are used to copy data from user memory into the kernel memory or vice versa. Since a user can provided a tagged pointer to one of the syscalls that use copy_from_user, we need to correctly handle such pointers. Do this by untagging user pointers in access_ok and in __uaccess_mask_ptr, before performing access validity checks. Note, that this patch only temporarily untags the pointers to perform the checks, but then passes them as is into the kernel internals. Reviewed-by: Catalin Marinas Signed-off-by: Andrey Konovalov --- arch/arm64/include/asm/uaccess.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h index 547d7a0c9d05..9b9291abda88 100644 --- a/arch/arm64/include/asm/uaccess.h +++ b/arch/arm64/include/asm/uaccess.h @@ -95,7 +95,7 @@ static inline unsigned long __range_ok(const void __user *addr, unsigned long si return ret; } -#define access_ok(addr, size) __range_ok(addr, size) +#define access_ok(addr, size) __range_ok(untagged_addr(addr), size) #define user_addr_max get_fs #define _ASM_EXTABLE(from, to) \ @@ -227,7 +227,8 @@ static inline void uaccess_enable_not_uao(void) /* * Sanitise a uaccess pointer such that it becomes NULL if above the - * current addr_limit. + * current addr_limit. In case the pointer is tagged (has the top byte set), + * untag the pointer before checking. */ #define uaccess_mask_ptr(ptr) (__typeof__(ptr))__uaccess_mask_ptr(ptr) static inline void __user *__uaccess_mask_ptr(const void __user *ptr) @@ -235,10 +236,11 @@ static inline void __user *__uaccess_mask_ptr(const void __user *ptr) void __user *safe_ptr; asm volatile( - " bics xzr, %1, %2\n" + " bics xzr, %3, %2\n" " csel %0, %1, xzr, eq\n" : "=&r" (safe_ptr) - : "r" (ptr), "r" (current_thread_info()->addr_limit) + : "r" (ptr), "r" (current_thread_info()->addr_limit), + "r" (untagged_addr(ptr)) : "cc"); csdb(); -- 2.21.0.rc0.258.g878e2cd30e-goog