Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp345492img; Mon, 18 Mar 2019 04:36:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqzP+2P6DNGE6Ppw8WWGoqE8CG9QJzcw06MXNFKpw2LkDiLbCBwc/pmIPuZkNv6E7A5lR+Aa X-Received: by 2002:a65:50c8:: with SMTP id s8mr17137819pgp.308.1552909009681; Mon, 18 Mar 2019 04:36:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552909009; cv=none; d=google.com; s=arc-20160816; b=bbuMaVkqeXDGD+z87a2XTpmfpGJeZsOIvgVnA/nQf74lS52YvHaK3nQte1B88UCrFk w2CWQrY0QSp+7PQLM3nRQzK6Da0GhXXattUxhcTi3f84ckBWw5qhCHpdr9jwiFUO5Sd/ WjctbhYI69NZD+iIGePIvVbrwyh0/G0VLxv5/RJvtI5RkoeJfoFbOH+cyloBTnJcTgMl Tm26biCwxMQkqUMlhPykuzl1gFGuQEEOF0c4GlLowQWWXxVa+w/1xICaQFNGJgIgrnXM ZUlTHe4v+ezp2Bs6e1DTueziyREVHJDUhl5cPV1evVce5CERGVPiZeGmNvwsPSm9bXYt vQNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=bxcVp1aXU07AX4ga6Cz1gLFYwiqZzn/6kcogjfOgwOs=; b=UxvpS+JFZ0cuRqo5QO+/m8ALYoVmUT880z/zV0GpsCTZpcFgnWzh6cLciM9YfWb2OY Uhkl+wfFAEzbB5YorG6Yjt3Vz3ZZ3QDKhn2CAdBEkayNcXeT4egUxsTcQR966pklJGT6 W9837lYW7hYK0An5D3ROEZ4vCmL5wfGvJ845KLzhmjsUrCwFDWYXL88mHE/HpSdLatnn 1IVnFgjUBEtcEp9grhhZRv0iAdKxkvq+1VE88UJXyuUty1ng2X0m9ag7iloksP19ClGf IC+Lq/6s476/ue5M0w1MTRqk9WGQ+A3GRRlcXGnE5G4Z078PMH2ko4bOv80qYT/d2CbC EpiQ== ARC-Authentication-Results: i=1; mx.google.com; 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 n19si8658929pgk.158.2019.03.18.04.36.34; Mon, 18 Mar 2019 04:36:49 -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; 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 S1727723AbfCRLeT (ORCPT + 99 others); Mon, 18 Mar 2019 07:34:19 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:60584 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727378AbfCRLdY (ORCPT ); Mon, 18 Mar 2019 07:33:24 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id DDA741650; Mon, 18 Mar 2019 04:33:23 -0700 (PDT) Received: from [10.1.199.35] (e107154-lin.cambridge.arm.com [10.1.199.35]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 973303F614; Mon, 18 Mar 2019 04:33:17 -0700 (PDT) Subject: Re: [PATCH v11 03/14] lib, arm64: untag user pointers in strn*_user To: Andrey Konovalov , 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 , Eric Dumazet , "David S. Miller" , Alexei Starovoitov , Daniel Borkmann , Steven Rostedt , Ingo Molnar , Peter Zijlstra , Arnaldo Carvalho de Melo , linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, netdev@vger.kernel.org, bpf@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 , Szabolcs Nagy References: From: Kevin Brodsky Message-ID: <5de82e7d-6091-e694-8397-fbcfd59f9d0b@arm.com> Date: Mon, 18 Mar 2019 11:33:14 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-GB Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 15/03/2019 19:51, Andrey Konovalov wrote: > This patch is a part of a series that extends arm64 kernel ABI to allow to > pass tagged user pointers (with the top byte set to something else other > than 0x00) as syscall arguments. > > strncpy_from_user and strnlen_user accept user addresses as arguments, and > do not go through the same path as copy_from_user and others, so here we > need to handle the case of tagged user addresses separately. > > Untag user pointers passed to these functions. > > Note, that this patch only temporarily untags the pointers to perform > validity checks, but then uses them as is to perform user memory accesses. Thank you for this new version, looks good to me. To give a bit of context to the readers, I asked Andrey to make this change, because it makes a difference with hardware memory tagging. Indeed, in that situation, it is always preferable to access the memory using the user-provided tag, so that tag checking can take place; if there is a mismatch, a tag fault will occur (which is handled in a way similar to a page fault). It is also preferable not to assume that an untagged user pointer (tag 0x0) bypasses tag checks. Kevin > > Signed-off-by: Andrey Konovalov > --- > lib/strncpy_from_user.c | 3 ++- > lib/strnlen_user.c | 3 ++- > 2 files changed, 4 insertions(+), 2 deletions(-) > > diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c > index 58eacd41526c..6209bb9507c7 100644 > --- a/lib/strncpy_from_user.c > +++ b/lib/strncpy_from_user.c > @@ -6,6 +6,7 @@ > #include > #include > #include > +#include > > #include > #include > @@ -107,7 +108,7 @@ long strncpy_from_user(char *dst, const char __user *src, long count) > return 0; > > max_addr = user_addr_max(); > - src_addr = (unsigned long)src; > + src_addr = (unsigned long)untagged_addr(src); > if (likely(src_addr < max_addr)) { > unsigned long max = max_addr - src_addr; > long retval; > diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c > index 1c1a1b0e38a5..8ca3d2ac32ec 100644 > --- a/lib/strnlen_user.c > +++ b/lib/strnlen_user.c > @@ -2,6 +2,7 @@ > #include > #include > #include > +#include > > #include > > @@ -109,7 +110,7 @@ long strnlen_user(const char __user *str, long count) > return 0; > > max_addr = user_addr_max(); > - src_addr = (unsigned long)str; > + src_addr = (unsigned long)untagged_addr(str); > if (likely(src_addr < max_addr)) { > unsigned long max = max_addr - src_addr; > long retval;