Received: by 2002:ac0:a874:0:0:0:0:0 with SMTP id c49csp732519ima; Fri, 15 Mar 2019 12:52:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqxwpUSUSCYxpCIDYL3JJqeLAX52NU5VhYi6HboR2XBrT9/yj2uRR7I7PGLdGnro2klHFY/z X-Received: by 2002:a63:535c:: with SMTP id t28mr5199475pgl.128.1552679576252; Fri, 15 Mar 2019 12:52:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552679576; cv=none; d=google.com; s=arc-20160816; b=wSDla9Jzr9zUcpPtO5ycn/zxvOh+bErdb8U7KMm/PSJTpgvp73LfWs85TIseCVfiMc Fg9yvEwHcYaqURK/DzKw9qFEoyzdD9CsQpZHCCpU6fxDXiZXJjKOl5cGKnFuf7NTkE/K c2uuNxekTREJZVRKh97NT/eYeVuan3RI16p6ej3u7UYWPMLxScFq5kjr5vuFbtKRfZ/A hecmPQZAqnqmJVOXSZwtzIjhzM9uj5k76K9hF6Oqyr7OsDS94UrGK80yRIa0yZfHRf3H 6tBP9q8Kb54oJetLPQZXxcNqbwcqKDz+7/CO02Yw7dovOBL9fZezqn3uP9aXDgdgeskz MwNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=yc2TKKK3uyNjx4k/SCg2YsIAkDocczWLqEwyHrZeSHg=; b=G3kFJYS3m6gBwse4+6ZIL20wbud/BDiR/tA1VLUcW3bAqXerCGqQlNanndhAjJL+NF 9UW+8amFu8QIJebFyd2pZ8s7UDE7bRo809/AL06/oLJK2h4fvmAkr6F99YqJ0BrnxR5F 9T3B5tnLBl3N5Jah6DlShWZ33HaZnQO4JDImx9kafeACBaQQogDaT79dpNdZIM3fXj0R L/PR8WfaX0LLDCNU0kXVI7y2fanqZtISE5NxEAP3UHDqfwPIMh6txZ6yVirouglFv8Qv pVeNi1CyQ4Z1O9yN1gGQv8p75+Un8ryXqTPs+MvqwDNteRyFqrTQ0GvKTHMIgezys9NT yV9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=HPKtN+Ac; 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 v6si2723694pfn.272.2019.03.15.12.52.38; Fri, 15 Mar 2019 12:52:56 -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=HPKtN+Ac; 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 S1727356AbfCOTv6 (ORCPT + 99 others); Fri, 15 Mar 2019 15:51:58 -0400 Received: from mail-qt1-f201.google.com ([209.85.160.201]:45416 "EHLO mail-qt1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727282AbfCOTvy (ORCPT ); Fri, 15 Mar 2019 15:51:54 -0400 Received: by mail-qt1-f201.google.com with SMTP id 35so9646261qty.12 for ; Fri, 15 Mar 2019 12:51:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=yc2TKKK3uyNjx4k/SCg2YsIAkDocczWLqEwyHrZeSHg=; b=HPKtN+AcCirGFFQHEZAu/mCbNrjYIKj90qShdg/IiFhxen49J0Qdpnr1pcKG7a6Z8e JeJ2qVhpKVo0e4MFSlZbzLIR2woDetJaTNND5bdihZ/qbAWcocsa2cvfjheYeB4rsRtq VupfRDNmC+dOLdGj40kTGJqU/K4oyQ4V3HkdkM9xosZcLU7jdIpJBpWnC76XUdwc2cRx PrBSQsPpZWMh+HxdTYEIi4nHU5c8m+m6PJBso4DlJCsFDkKaGHF5sF+vigRkHjI5UG0U RhfFgSuDuzmav8L6Qcw6zbyS+BybgMK3vA4F1h2a+P/7Y7SKXtGu14CbY9cr1/NstkUy Z8Lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=yc2TKKK3uyNjx4k/SCg2YsIAkDocczWLqEwyHrZeSHg=; b=UZaG2ryiReWypLEuef/ZDwJheerj5CKf6S1CMmsfXX+qW5ODenqXhqnLlArxwFFgQG W4SEpSQ+G15jgPVI1jcQREymTYZk9F1beDRz6JZCsmfIqrFqzT6H+NbHl6+TnG51R+Gn Rzi6NcxyhkxV2rU6OcMhcPTF7liSFBWtxsfyJDjAwLE/wAhOO2L36FAzNv+tjc/BjuZm MTJrRqP4Z6VNkDA163OgvJbn4emrpWpPbtUKYN/jV2457A8yIm3MuouzTFiG5PHQ0zy9 21b22ISGTSP0P5JfyaZOnrzn3uolisY9fn/cchOXRKGY/kZamfwMVNGsWLxxovLubjlS /3WA== X-Gm-Message-State: APjAAAWIHIyN5aSEi/Y6pwPKZzQqjTp3nPdgo0pOht3aVb5N7FILL7Yi OOtf4dLMfug55DNwh9D3rX0syMUNCWkLSysR X-Received: by 2002:ac8:28c9:: with SMTP id j9mr3165248qtj.21.1552679513588; Fri, 15 Mar 2019 12:51:53 -0700 (PDT) Date: Fri, 15 Mar 2019 20:51:27 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.21.0.360.g471c308f928-goog Subject: [PATCH v11 03/14] lib, arm64: untag user pointers in strn*_user 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 , 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 , Kevin Brodsky , Szabolcs Nagy , Andrey Konovalov Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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; -- 2.21.0.360.g471c308f928-goog