Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp511982imm; Thu, 30 Aug 2018 04:44:50 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZpcvkhw9MUpiEj6MIrhhKM0SQhv8IdZX3mjcnIlNageYTi+9oxTZ8tjfY4Y8V5wOkbtyq2 X-Received: by 2002:a17:902:1a2:: with SMTP id b31-v6mr9614185plb.279.1535629490226; Thu, 30 Aug 2018 04:44:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535629490; cv=none; d=google.com; s=arc-20160816; b=Rav3WxH2yoZREpK+6nM57wo3Bro8I0lgwJe3jyhB7U6JIazyXFpowiozRqzwcxuzaL Lmu3zpKM/zUvgreD/O5SfRSxo2F9CP3BULQXTHCNQHyVICHyeU9e1/QYdjqI4fXpCdSj u4itAaQkrJR135YBFXl/ZMXWHdqFoX+SCQpb9vIGLBI1DXydYZpIr75+zBVGo9YaIcpz 7Eg/DBepZSeQfMNFdeocAOWQcP5p0WY/LLQFHGqe068gEPVypQUyjKMKhedTVusOwYwo eAfDbpwfsu6XvxqKgQ9Z1znAdIWsHUCU84p1x+02P4Z1qi1g1cEtZ53+Hxhn1G/6qCuh VL+w== 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:arc-authentication-results; bh=LhBQZOJZ5CY1iejYHh5r+OO80KOFbC9w+x7Kw+7XH2c=; b=RZU4IllS00PhoGFCN/efCnfVJkEUoDi3H6ckpfMVze/Xgl3I5a4Qd77s9Nu//QG6Y0 MD9R/X74CtzGArmO7hxfIcSX81acGqorLXacHbLg6kVAiELJe8Pr7Suc81p/53wYRE4u sWBM6jOKpknAtHkZA5pJDcLpiXOnlbIUR0QgyC4n4y64CfhJkjvXiwlPmGSm9hkZ39W6 eff5u9mp2rP+Wwyt1YctQO/kJwTyLt2IH5wRKJNVDye0i4MIKPvJPP3FC9+EoQD7G3Fv K5l9utecS0rodfcxNipI82VKsR8qWAkQSM9KLX2sCz4XKoIJJpcCpIQP2r9YhOdAjoI3 30og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=qhLN0+Xl; 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 j30-v6si6750641pgj.586.2018.08.30.04.44.35; Thu, 30 Aug 2018 04:44:50 -0700 (PDT) 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=qhLN0+Xl; 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 S1728731AbeH3PoG (ORCPT + 99 others); Thu, 30 Aug 2018 11:44:06 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:50785 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728231AbeH3PnJ (ORCPT ); Thu, 30 Aug 2018 11:43:09 -0400 Received: by mail-wm0-f68.google.com with SMTP id s12-v6so1656965wmc.0 for ; Thu, 30 Aug 2018 04:41:26 -0700 (PDT) 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=LhBQZOJZ5CY1iejYHh5r+OO80KOFbC9w+x7Kw+7XH2c=; b=qhLN0+XlBq6jHDTlSlKfMMmJjUqASaVSiAZ0zywVXpAg+VpUOeqdiJHj/wArfR65XG Ut3JLptVruN/PBv/xjcMUVNG81WIKCO+dMG9qK6HWxTAtR/EtQB8CpaH9QF+IGCW4BWn YSmQMOUq6FSuRhvb8AempV8E+YLZPSUlE4hF2263DyPfege/APAPyWSrGUaOUqwNEiw3 O4IibHRF1/nN9/UDdjKaDCSYnTyG5+kjDhFJC2srV9nASdDLL5E5WdrKISQHKKrQN0eP M8nLl+weFtfn/3yYYPWxYTFB3bviLyYR2P+BrZHk7c4uvaVyPrL5NiMZclTO4/7ZClBg Xtfg== 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=LhBQZOJZ5CY1iejYHh5r+OO80KOFbC9w+x7Kw+7XH2c=; b=HRjAJAe7T+1d5+uyffDcRNaXXwPD/KDpffByQksgTQWe1K6E8eSBBiMwGlLNAbDQaL NFsGGAZB2kqvZr+CRGQ+t5OVszKt8eLA8T+vyQxP1GwUJUygtPqdMXXm2Rbw+BLpyVcQ oxDouGpPQz64vmjGd/KXEGzhwDiTSH+KLA2PNeOF+G4Zo/2yaTYutLQ8BtVgyihSVYkm CgKD4/X01Tv6q+aGecAZ6WotQhW8Z1CAZ489qS3w1fCR2Ai65YqgJOkX/WqaXbbl6MQc kGnPEsig3w8GEV0RnfmfVdgMsvFBHB/7kiLvYwMLMWIEnRXLyHfCGNX3eBc3D17CreqS cVMA== X-Gm-Message-State: APzg51Ad4BFAC5g6jwuePJPAneCa/r9310tHz26iQxRC4EJ9EVheEAFi N3oGbOP2Dd6ea61Nqn9rVoNPAg== X-Received: by 2002:a1c:7915:: with SMTP id l21-v6mr1693369wme.136.1535629285313; Thu, 30 Aug 2018 04:41:25 -0700 (PDT) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id z184-v6sm2175218wmz.0.2018.08.30.04.41.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Aug 2018 04:41:24 -0700 (PDT) From: Andrey Konovalov To: Catalin Marinas , Will Deacon , Mark Rutland , Robin Murphy , Al Viro , Andrey Konovalov , Kees Cook , Kate Stewart , Greg Kroah-Hartman , Andrew Morton , Ingo Molnar , "Kirill A . Shutemov" , Shuah Khan , 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 Subject: [PATCH v6 03/11] arm64: untag user addresses in access_ok and __uaccess_mask_ptr Date: Thu, 30 Aug 2018 13:41:08 +0200 Message-Id: <7a37e7363328f4aa10706c0294242eaa5e4e9e89.1535629099.git.andreyknvl@google.com> X-Mailer: git-send-email 2.19.0.rc0.228.g281dcd1b4d0-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. Signed-off-by: Andrey Konovalov --- arch/arm64/include/asm/uaccess.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h index 2d6451cbaa86..fa7318d3d7d5 100644 --- a/arch/arm64/include/asm/uaccess.h +++ b/arch/arm64/include/asm/uaccess.h @@ -105,7 +105,8 @@ static inline unsigned long __range_ok(const void __user *addr, unsigned long si #define untagged_addr(addr) \ ((__typeof__(addr))sign_extend64((__u64)(addr), 55)) -#define access_ok(type, addr, size) __range_ok(addr, size) +#define access_ok(type, addr, size) \ + __range_ok(untagged_addr(addr), size) #define user_addr_max get_fs #define _ASM_EXTABLE(from, to) \ @@ -237,7 +238,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) @@ -245,10 +247,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.19.0.rc0.228.g281dcd1b4d0-goog