Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp617567img; Mon, 18 Mar 2019 10:20:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqxZ2JK7jbgx/CdcyeAIazc8Mu0+Emb9YTD9WEodIesRAdK0E/BTfABVwNnJyt2xy9JAE4mn X-Received: by 2002:a62:1e82:: with SMTP id e124mr20202387pfe.258.1552929657933; Mon, 18 Mar 2019 10:20:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552929657; cv=none; d=google.com; s=arc-20160816; b=J9J+/41p5Q1UHy5HfVURrp+ygfTLcD0RVN9J2wVPsYZWMGMIW+9eNBuP1Bq8FP+dMa Po6KG7FW7fw5QGZMYie7BiiM5uKWB2kKjZvQ/r8ASjNPh+w/ZW0NrUUMj4WDqeSYhSyt 503d1nn5n+nt2Zv+l1noG+eoKvK7Vi3A2c2H6cP4t48092YUIlqaoBOi7N67nlI9XtGh onBmdvGq+gsMrtWP9YdhDiAXJEb0MNHx3cx3mpwGWYcrTGvHt5uuv6QgmTKdITJfOfMD KQ0q+MN5MzsmY7jagCMlFwuwoOcdCvvMDKs/WfwlM6vXc7j2PS3Jjejtut3IgpaporCk GiFw== 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=k1ksHzqcIFCs0rlhYrsau26vl3ocVueBBoKnHNKxr50=; b=RNzd2dkIEiigZ4SFHwJaIROz14NME1HFWFnQIMBMylH8LDdW2a1xl4/zzs0/tmYFlK SnjWkI8mCSMLthxoSCXgLuRV5Trvd2dNYgOGwppu+mccu4kxkG+1Vx9wHS1QIGfiWufb urVWjwhcTuGJoHQrBllf2vtNadEPrGAd0qGQKmRgvxAULUq6XopEGn0ZPZkMtDQWYPWo w6/oVYy81AWCDYZPOH7k1eMv/4DAKg61LmV1ykB4pNQ2ADiE9PHfZcqlXvVD3hp0zweD eDJrnuCLEZTGGHyawXLNY+Teukne4o7K3FQXret30NrKXPQufoepdSiJr9lqCRlalfP0 W8Dw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=oz1fvLMf; 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 e1si9988489pfd.0.2019.03.18.10.20.43; Mon, 18 Mar 2019 10:20:57 -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=oz1fvLMf; 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 S1727815AbfCRRSB (ORCPT + 99 others); Mon, 18 Mar 2019 13:18:01 -0400 Received: from mail-it1-f201.google.com ([209.85.166.201]:56387 "EHLO mail-it1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727805AbfCRRR7 (ORCPT ); Mon, 18 Mar 2019 13:17:59 -0400 Received: by mail-it1-f201.google.com with SMTP id j18so15135837itl.6 for ; Mon, 18 Mar 2019 10:17:58 -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=k1ksHzqcIFCs0rlhYrsau26vl3ocVueBBoKnHNKxr50=; b=oz1fvLMfcGfF81Olx8UNQHEZSNueq6Qn8HIXigOddOJDAD2tg4UjJfuFuQZjoILWrg CZQbFlcBOVlSuoBIyl+jHf6+DdY1aYxqiZ+PbKmfk+lr5pHfcoSSl29R6PrgmkRv2+Vt jaBUYlq/IjUpt3LjnPub3yHlYsiou77HiwqH/RPJgcNyMlQiwfZhgtvbqZ2qkfe+w8YV JszqgrO+qE+QbtWQuzywwpj8p6QWhPyanRNQsRRsaA1VHxFYfquhluxhBFXc65JKlppp Ta4otXITXmaoRx/+KSZjVysEXe12wNPaDhCUR3L2hY/+Bjcp+T9no9YB/s9yH1290+KX DWGw== 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=k1ksHzqcIFCs0rlhYrsau26vl3ocVueBBoKnHNKxr50=; b=sT5ZrMGKE4y8CdQEu6VsTQguChwPaVY4Wsq3REznBerqRcdESk+Yl0vRfVH4vRVE+b eLpyqWxEn78JDqSAgRUIlIDpLtt1aLBRLJt7kDWFRBDdBe/VkBx8pvFZSeGkILfSWifF iNOVm+anp+KKO2tJckd1qErP6JJcHcU8FL4pOek4MVRKxQEH2PaVQPYF13ehx4fpfvwl 4bTuILnwt1rlApizxQznePtUMqdpiHSVP4QrqsF8zWyi1VreCwSV47l83Q3T8caee3fS Nk3zyQJP2NPVEJh4DLclQEj5A+xJTvinBJjWM+rHy0pkxRmK+Tf23wl+pfdGGV40sULU 9+HQ== X-Gm-Message-State: APjAAAUhCMHVhWslT1VxRXGNR3XKN7O2ugREkzgm9z+PBQZC3D/ptdP0 /XZkabnd7XRpYq1tNlPJ46h5sb8q0D6GiJ6C X-Received: by 2002:a24:29c5:: with SMTP id p188mr10832598itp.4.1552929478230; Mon, 18 Mar 2019 10:17:58 -0700 (PDT) Date: Mon, 18 Mar 2019 18:17:35 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.21.0.225.g810b269d1ac-goog Subject: [PATCH v12 03/13] 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.225.g810b269d1ac-goog