Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2663562yba; Mon, 6 May 2019 09:35:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqypsKkHZTMAdIqQyVgsVKoq2lPWaRYzl1krmZNXQjSM9QjLc+ffqGq4FUg0K0lrJZSpRTAM X-Received: by 2002:a63:4c45:: with SMTP id m5mr32670920pgl.78.1557160519890; Mon, 06 May 2019 09:35:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557160519; cv=none; d=google.com; s=arc-20160816; b=Inn4qRvUZyw/EDXykkW+ni0yDDRfB28paWRvUeqvJWbHzvQppCn6/tQOhF4LYGA9h3 b84s4Lcg2CqSZ/XeJBh//VS572KfzPZY5Vswj14CW5A6gh8BdF5YcImwFytIO6cTSH9R bgiueFvs5LWJovXhXi55NNiH1ndOc6rV9r5VMuBCdiqechx6Qhu0BGKD2BlXbE4IhOc9 2hBtoE2PbMfhJi3NLPLSA+SxCcRwQDC3ggtsbBMUemEeiR0mG04DrEAlF0iDv4dxOZjF 6CYqtyhn0kZLisRNmhYjwgw/4tvtcmgOFv60NhJZwg0aeOGG15t9NLdf1OjBxGApQ7Vv icGA== 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=x8HMVSO2lCP9thpVq0jteC8wa+ruR/qG5sfvMEzcSf4=; b=UydagVMAXP3Bl2ExIfnpIe+uc6scqf8uE4be5n2O/Hff0f2PZdO/sPEklHoW+qsTUJ fYvYS0TTLdYNdYPH6v7xsYTECxk17lznKc4jrfDsCu75gOv0jl5saj8fH2fLTdVGcuTi aR/IGq0PoeZRe5gD7asNupIYsYoqTwqbuzQHY3SQbeZX3EpUHkWu0q74GWHNEo9GVdbY FJIjpqiEpFv3UIFqU77fRnQzbor2ey1UTf4qlgL78gzP6XN4x1ugejXW9srjyvWYSXAj FDIyfYqjkzwj4kDYHFrQPghUvnRuHQ8cnIfmbUPzU0fq+TGarSZlYA+QksO9e0w87EsI E+xA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=e90YIYJE; 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 r12si15040670pfn.135.2019.05.06.09.35.04; Mon, 06 May 2019 09:35:19 -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=e90YIYJE; 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 S1727084AbfEFQda (ORCPT + 99 others); Mon, 6 May 2019 12:33:30 -0400 Received: from mail-yw1-f73.google.com ([209.85.161.73]:32872 "EHLO mail-yw1-f73.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726744AbfEFQbR (ORCPT ); Mon, 6 May 2019 12:31:17 -0400 Received: by mail-yw1-f73.google.com with SMTP id c4so26406133ywd.0 for ; Mon, 06 May 2019 09:31:17 -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=x8HMVSO2lCP9thpVq0jteC8wa+ruR/qG5sfvMEzcSf4=; b=e90YIYJEqCjuv0dQNXe7JfByZ3LYw/uoix1gLG6qHxakrZEGoit4yh6fTDsfYia+jH wb7igUzrFQvpjJl955zqS3eb64AMNM806CURkcixGS6z1rzCJzMGBiAz82rRhlhjgKjR 9cdDyeo/3JMugM0eGAxc56H2X/rF/Gu5NZJ6OlTvycYfBxRjWeovYDz5GGyc2/popU6X Q4rJTvbhNlqr5zqGtmKCjWUttV6dsKWcbk2qBw0aV1In8VLH8mRF5MiPk8iCO4KWMnPF BSI3N1BBXtSHWlnz3+Iji+1TK5JldUspg0pnnlvUCK4PaDa6c2GsK9cElOVCY5yx3kNx bcTw== 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=x8HMVSO2lCP9thpVq0jteC8wa+ruR/qG5sfvMEzcSf4=; b=b6PHwXvVmLNg6m4yrGzNzPtce8LLQuOl8+4tsOGE+4B2LW1tVfLKgkfhll3H+skADf oM7bra6XsUIhla/oWUZid9buGss9ibcE+t9NQSsYvFgiZq+c9FpMIMZ4KFV+P3G645eG NyZ78rugmsHd9zVACcAOxJ3usf5ryOTBB0i6w3P8Fm4N/U+Rh2+uSmkGflXNylb/mlnV UCkYfip8EYeE5o7BzletGiSFSGZgdx2bBVKzduu7/7olczGG4MJVs3tgpkSM83Z/Dbdw X21ZOuY9l4xzIMZ09q2tJnqbhabupPm0zS96MX8NC48ih1M8kFnCzciQbKpum8tU4cCe 77zQ== X-Gm-Message-State: APjAAAWy12oFjoBEHAy2/u/L0VucIwBrDh0sUCoUa04ORQn8RqHWRn8A aoTv2jNmuXZd6uxf4C3+yfQKe7bsV0VAJkDA X-Received: by 2002:a5b:8c2:: with SMTP id w2mr16278460ybq.201.1557160276487; Mon, 06 May 2019 09:31:16 -0700 (PDT) Date: Mon, 6 May 2019 18:30:49 +0200 In-Reply-To: Message-Id: <861418ff7ed7253356cb8267de5ee2d4bd84196d.1557160186.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.21.0.1020.gf2820cf01a-goog Subject: [PATCH v15 03/17] lib, arm64: untag user pointers in strn*_user From: Andrey Konovalov To: 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 , Vincenzo Frascino , 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 , Dmitry Vyukov , Kostya Serebryany , Evgeniy Stepanov , Lee Smith , Ramana Radhakrishnan , Jacob Bramley , Ruben Ayrapetyan , Robin Murphy , 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.1020.gf2820cf01a-goog