From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8A180C31E46 for ; Wed, 12 Jun 2019 14:28:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6ECA82082C for ; Wed, 12 Jun 2019 14:28:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2437514AbfFLO2X (ORCPT ); Wed, 12 Jun 2019 10:28:23 -0400 Received: from foss.arm.com ([217.140.110.172]:54180 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731463AbfFLO2W (ORCPT ); Wed, 12 Jun 2019 10:28:22 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id EFE382B; Wed, 12 Jun 2019 07:28:21 -0700 (PDT) Received: from [10.1.196.72] (e119884-lin.cambridge.arm.com [10.1.196.72]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E45733F557; Wed, 12 Jun 2019 07:28:16 -0700 (PDT) Subject: Re: [PATCH v17 02/15] lib, arm64: untag user pointers in strn*_user To: Andrey Konovalov , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-rdma@vger.kernel.org, linux-media@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: Catalin Marinas , Will Deacon , Mark Rutland , Andrew Morton , Greg Kroah-Hartman , Kees Cook , Yishai Hadas , Felix Kuehling , Alexander Deucher , Christian Koenig , Mauro Carvalho Chehab , Jens Wiklander , Alex Williamson , Leon Romanovsky , Luc Van Oostenryck , Dave Martin , Khalid Aziz , enh , Jason Gunthorpe , Christoph Hellwig , Dmitry Vyukov , Kostya Serebryany , Evgeniy Stepanov , Lee Smith , Ramana Radhakrishnan , Jacob Bramley , Ruben Ayrapetyan , Robin Murphy , Kevin Brodsky , Szabolcs Nagy References: From: Vincenzo Frascino Message-ID: <0bbc5f4f-9812-463c-48c1-4929bef801da@arm.com> Date: Wed, 12 Jun 2019 15:28:15 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On 12/06/2019 12:43, 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. > > Reviewed-by: Khalid Aziz > Acked-by: Kees Cook > Reviewed-by: Catalin Marinas > Signed-off-by: Andrey Konovalov Reviewed-by: Vincenzo Frascino > --- > 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 023ba9f3b99f..dccb95af6003 100644 > --- a/lib/strncpy_from_user.c > +++ b/lib/strncpy_from_user.c > @@ -6,6 +6,7 @@ > #include > #include > #include > +#include > > #include > #include > @@ -108,7 +109,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 7f2db3fe311f..28ff554a1be8 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; > -- Regards, Vincenzo