From patchwork Tue Jul 23 17:58:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11054841 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C848E13A4 for ; Tue, 23 Jul 2019 17:59:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B8BD0286C6 for ; Tue, 23 Jul 2019 17:59:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ACBBA286F1; Tue, 23 Jul 2019 17:59:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 23570286C6 for ; Tue, 23 Jul 2019 17:59:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D80038E0008; Tue, 23 Jul 2019 13:59:10 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D32E28E0002; Tue, 23 Jul 2019 13:59:10 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C21668E0008; Tue, 23 Jul 2019 13:59:10 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yb1-f199.google.com (mail-yb1-f199.google.com [209.85.219.199]) by kanga.kvack.org (Postfix) with ESMTP id A05F88E0002 for ; Tue, 23 Jul 2019 13:59:10 -0400 (EDT) Received: by mail-yb1-f199.google.com with SMTP id i70so33952721ybg.5 for ; Tue, 23 Jul 2019 10:59:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=uxuxpoqA/C7rk06bc2rM9al5Hb55km4kp2za7lpV0D8=; b=VDrHwuNY56y/7To2ydIpaeudUrbJtV3LKKSPHDt7XXIpSo9JSixU8ikmobtzAdHIq6 Z9TZKAIpEpRH4DIJRPkUiKpiKaoLJVfuT1lAv90tfn2tFqNFtMDVXtu4fzbz6ZDJ6GGz VY6bLX6yLiVFaj/dMXYYYKQjImnQqfxSm7h3Bpgj/PuokF1ZHZ1ypkMng65DifiYH8EF uARBgXU+gTFp/7Wduy7vD/sM1YJkW7uZEWZf/vjq86EY3senGJl4OmpGrv5JE47GEfyK 1t4s40USL7uDF8IZB+iesPCR8aLdeXkHMBOcXrahqOpgcIxmAIL+gZkmMGeSVM3RYtNH 9VNA== X-Gm-Message-State: APjAAAXXKkWBX6P0TJ6O9JDqaUzQHz4XbOLc781v5gTkWZpCEOZoGBNb 4tlRdeirYv+a3IOpTRmG6N4tHSVur0t66YGxMAlkMikY+H9uB4SP+MhwEFuqDzyADxaAQZBWGjO KjJaN28WpxNP49xckK2UIUu4K2zeCru7jiy/kl74oMxqaKx4GC1HQIJ+E2EPE/CzWEQ== X-Received: by 2002:a81:23ca:: with SMTP id j193mr46703873ywj.332.1563904750341; Tue, 23 Jul 2019 10:59:10 -0700 (PDT) X-Received: by 2002:a81:23ca:: with SMTP id j193mr46703851ywj.332.1563904749719; Tue, 23 Jul 2019 10:59:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563904749; cv=none; d=google.com; s=arc-20160816; b=TulpxJyj4GWMOfqRmPkNjYNxzABCuqT/stIjVKNhqAvERa2KPcC+bBwUjuLpGYKCoU hyPJDSkhA8kyN/EUi8ScNTjYRv12IUYGsYi7YGws8z68Ol0DMA1CNidvaUvq2gGO7cHI TmcLDnzgS9+voD1PAVLXgz3Y/X3M9J8gAAtgEbcz5Z8YqDKmRYt3UC73MVkUEcMAjhYb Bvx2HfInFKwTLaOdIxI68uPajw0XQX128FOKOhgSJfRWXrOgQJZNj8HB+l5BAuPqC1rY CrNz2/eCboD3qvp9eKjyIhpu7ct5NvzKX6uIHyroiOlpQRyecFAtqePZUY8+Q/F/e4sW YTRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:dkim-signature; bh=uxuxpoqA/C7rk06bc2rM9al5Hb55km4kp2za7lpV0D8=; b=smfF9yG1av8bzVLrn+dyE+7B7736OAHsCWaTbxSgGThS8Ed7VfISUy2AHQfkcTOSL7 l98frl100REGGN8RJhQW7zOFsNvSvRic5XICuiNlsopPJGihLLLyD4iqWSxUT3qotO9x DNTv/EJVW5/U9gT+V7tx2CRifCnNCQB7jUAj7GgADzzW1x8M2CVxXRynsN5Op6WfIemF /bBfeDRhKDgCQWgO3HtzY4AszGTdo/blXkcsbsPaNCOz5JggdrL00dxMqQGe5sapFsx/ L7aF1OjljpTX3BU77GoK8KcjJMmg3nt9GfwyP3TDx8sSUXxGk7Ahq2PfCtA+2x+/hJTU OcTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=gvBkOkwz; spf=pass (google.com: domain of 37uo3xqokcfas5v9wg25d3y66y3w.u64305cf-442dsu2.69y@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=37Uo3XQoKCFAs5v9wG25D3y66y3w.u64305CF-442Dsu2.69y@flex--andreyknvl.bounces.google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from mail-sor-f73.google.com (mail-sor-f73.google.com. [209.85.220.73]) by mx.google.com with SMTPS id 187sor5817519ybu.19.2019.07.23.10.59.09 for (Google Transport Security); Tue, 23 Jul 2019 10:59:09 -0700 (PDT) Received-SPF: pass (google.com: domain of 37uo3xqokcfas5v9wg25d3y66y3w.u64305cf-442dsu2.69y@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) client-ip=209.85.220.73; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=gvBkOkwz; spf=pass (google.com: domain of 37uo3xqokcfas5v9wg25d3y66y3w.u64305cf-442dsu2.69y@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=37Uo3XQoKCFAs5v9wG25D3y66y3w.u64305CF-442Dsu2.69y@flex--andreyknvl.bounces.google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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=uxuxpoqA/C7rk06bc2rM9al5Hb55km4kp2za7lpV0D8=; b=gvBkOkwzaYNLh+oGcJAVB7MjFm6ggJ16J7ZtFWSs5smrgxbyTgnFANakPKwfHBaKJo Z3AeBj5hFUm+GIYoHcLDXyEq448i3WGfVM80s/ZYt3Ff7Lnffb2whFy1iyiq0vNB8tme ZgEAhcj6PmMNwScnzwOlSrD9vrs9BWD5XfY+Jc7tfz6fIGBdIIOc361XhF1FnJ2J5gIc R3XqyRsgPc72AURET11IAyvFYp4TC8kAAhKarnjk3baGMHuxZXMV89tXjZO+C8I9PfEc YEGyFP+vd3pK7Yts8v+bEOrkzxv2fC0rSmwv0ECVx3Gypru+tBZwBnoAh4W0hQ7k4cn/ 8ScQ== X-Google-Smtp-Source: APXvYqw9DwaHVI19t/YbteMrcIZMKltNbSnI88dDsWcfp8XIUhxn9zscDjBOZxYqaezV+ZapgNfd0Az5q5SxMU+h X-Received: by 2002:a5b:951:: with SMTP id x17mr48178059ybq.511.1563904749116; Tue, 23 Jul 2019 10:59:09 -0700 (PDT) Date: Tue, 23 Jul 2019 19:58:38 +0200 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.22.0.709.g102302147b-goog Subject: [PATCH v19 01/15] arm64: untag user pointers in access_ok and __uaccess_mask_ptr 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 , 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 , Andrey Konovalov X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP This patch is a part of a series that extends kernel ABI to allow to pass tagged user pointers (with the top byte set to something else other than 0x00) as syscall arguments. copy_from_user (and a few other similar functions) are used to copy data from user memory into the kernel memory or vice versa. Since a user can provided a tagged pointer to one of the syscalls that use copy_from_user, we need to correctly handle such pointers. Do this by untagging user pointers in access_ok and in __uaccess_mask_ptr, before performing access validity checks. Note, that this patch only temporarily untags the pointers to perform the checks, but then passes them as is into the kernel internals. Reviewed-by: Vincenzo Frascino Reviewed-by: Kees Cook Reviewed-by: Catalin Marinas Signed-off-by: Andrey Konovalov --- arch/arm64/include/asm/uaccess.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h index 5a1c32260c1f..a138e3b4f717 100644 --- a/arch/arm64/include/asm/uaccess.h +++ b/arch/arm64/include/asm/uaccess.h @@ -62,6 +62,8 @@ static inline unsigned long __range_ok(const void __user *addr, unsigned long si { unsigned long ret, limit = current_thread_info()->addr_limit; + addr = untagged_addr(addr); + __chk_user_ptr(addr); asm volatile( // A + B <= C + 1 for all A,B,C, in four easy steps: @@ -215,7 +217,8 @@ static inline void uaccess_enable_not_uao(void) /* * Sanitise a uaccess pointer such that it becomes NULL if above the - * current addr_limit. + * current addr_limit. In case the pointer is tagged (has the top byte set), + * untag the pointer before checking. */ #define uaccess_mask_ptr(ptr) (__typeof__(ptr))__uaccess_mask_ptr(ptr) static inline void __user *__uaccess_mask_ptr(const void __user *ptr) @@ -223,10 +226,11 @@ static inline void __user *__uaccess_mask_ptr(const void __user *ptr) void __user *safe_ptr; asm volatile( - " bics xzr, %1, %2\n" + " bics xzr, %3, %2\n" " csel %0, %1, xzr, eq\n" : "=&r" (safe_ptr) - : "r" (ptr), "r" (current_thread_info()->addr_limit) + : "r" (ptr), "r" (current_thread_info()->addr_limit), + "r" (untagged_addr(ptr)) : "cc"); csdb(); From patchwork Tue Jul 23 17:58:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11054849 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0620D14DB for ; Tue, 23 Jul 2019 17:59:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EB696286C6 for ; Tue, 23 Jul 2019 17:59:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DE4A7286E0; Tue, 23 Jul 2019 17:59:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 13424286C8 for ; Tue, 23 Jul 2019 17:59:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DCE8E8E0009; Tue, 23 Jul 2019 13:59:14 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D7F358E0002; Tue, 23 Jul 2019 13:59:14 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C48378E0009; Tue, 23 Jul 2019 13:59:14 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by kanga.kvack.org (Postfix) with ESMTP id 9F6968E0002 for ; Tue, 23 Jul 2019 13:59:14 -0400 (EDT) Received: by mail-qt1-f199.google.com with SMTP id x11so34704165qto.23 for ; Tue, 23 Jul 2019 10:59:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=mEM9r2TrIcyS5QiUJ5WsI/WGUVLPWWhwkAU6Ibh3jIs=; b=U3hjaImVYIuo+4StN8OaEhAFK73rMufJi/v+Eogi4/r4kAv7eo6aa8G2JUJ2p/21xz a6hZ0Fy1lSRk8n7vj+lti13FWIEGV58lHnUjBc4l44P3a0mXnMxF6MWpbm803VxCJkK3 dGquKKjWNa50HaXPUy+obk7xtgdGfwxLZXX/A1MshZN9/6taep340nWtvvPYJf9SBvix 1dHTHEbWZ1ObfKjZFY5WQ/A1RTsLI/nf8z+zIWcN7kc5S7wh9L9H/3anLbzbsAmXOe8M RAcQStrUBIqoAZzTDTwN4G/Y8H/txJBkNJV5KhyQxmZVmiSSuJsyui624TyIDa7f4IPr IEUA== X-Gm-Message-State: APjAAAW97nDeov+Y6hrR0XdgRcY8BKbq3xiPvFYyU2w3nHZneJRza0NF W7W34sHuqQtAX+ht4ZLuBYHNWq/Co33ItP+7wmYLzti/KsKctPISmujPetVm4ix0KGhpvzfND54 5TyFd8Mg1rsBZZgyPxWNAgg3oBa23dbvFWyFQZL+8Ejjm1KesVs/Prx19r2npuoeYZw== X-Received: by 2002:a37:a5c6:: with SMTP id o189mr51369721qke.455.1563904754305; Tue, 23 Jul 2019 10:59:14 -0700 (PDT) X-Received: by 2002:a37:a5c6:: with SMTP id o189mr51369685qke.455.1563904752960; Tue, 23 Jul 2019 10:59:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563904752; cv=none; d=google.com; s=arc-20160816; b=EwEF8Eh+O7WKJbbGMWnwHCUV90F/sNoYMwg8fScCwsOBUegRWxtAoIO+gOscxtCYky ELE13sjdev7PmEDXGKR0sni1XkKCEMXTtUVdLP9BpUMGvN7MmoC+97UQIM8QhLOFpR8r uWH6hUlu0xSJktkJvxAJht/SpY+QqaywhGKX6XiFuMDiWF+dnQh0S5b4e7jbz0e2j7iU 1SQTZdwgNXgYe82IOpB5+4zIp4Gl1bTQp4Dzh1ga3CXElzXg7P3dRA1wVgAxRRA4TiBf yGoyl+cuQIObvxB9X2u7NBkXfjXbdwqOUjteNXME+TB34JYcMcI22j6yzb89eX6sqdcw Zcag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:dkim-signature; bh=mEM9r2TrIcyS5QiUJ5WsI/WGUVLPWWhwkAU6Ibh3jIs=; b=ZQcWJ57xXj/aFdWJZEpPT13dZsoImOjCMyrJx8WibQK8+UcoUnPVSPLa9jqce743bG 8XFDnk5uVPo4EUFPlRJvgeAdqRdezvJKn8oVHu+4NDAFRmurdBZHS1GXYBnO6bUMYeFk ADLiQnVhG5IVeETMpCpS80UZoIqnZVYkRsBGF9ylYDyr3SuN13w/Z+Wf1Q+a+/nTvNys V6B/YS7lBdBQv8sBYTc7QCsqY/06PdYK/sKckuKjfMEUHJAENuf7WrODCU5+jcDnzx9P d5luPWKMPKUM5VmGk72L5aj70g8+3ZrjgQFCWLn5aqh4mcKHZTV73nakxU77/Yn/jqn5 gbfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=H5geBT1j; spf=pass (google.com: domain of 38eo3xqokcfmv8yczj58g619916z.x97638fi-775gvx5.9c1@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=38Eo3XQoKCFMv8yCzJ58G619916z.x97638FI-775Gvx5.9C1@flex--andreyknvl.bounces.google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from mail-sor-f73.google.com (mail-sor-f73.google.com. [209.85.220.73]) by mx.google.com with SMTPS id q14sor37180569qvf.10.2019.07.23.10.59.12 for (Google Transport Security); Tue, 23 Jul 2019 10:59:12 -0700 (PDT) Received-SPF: pass (google.com: domain of 38eo3xqokcfmv8yczj58g619916z.x97638fi-775gvx5.9c1@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) client-ip=209.85.220.73; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=H5geBT1j; spf=pass (google.com: domain of 38eo3xqokcfmv8yczj58g619916z.x97638fi-775gvx5.9c1@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=38Eo3XQoKCFMv8yCzJ58G619916z.x97638FI-775Gvx5.9C1@flex--andreyknvl.bounces.google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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=mEM9r2TrIcyS5QiUJ5WsI/WGUVLPWWhwkAU6Ibh3jIs=; b=H5geBT1j+ubrLFlbrsinXfwZ0W5BQqUsTQ4IaRG81Ui2ZwtPz7y/KxLSObtE6WVnKG iLhrcnu/dA6uvy2xcSWRBGEgliAGFYmCJj9eOifU6l6F5s22JsTp5wdsL4S09QNfUDVI UCiPujniwnzgr9cWOZtf0O60DfpKFiDJD1smf/WyvtqTOs+e49rV01Sy+tA1kalRfOYC 3saGMlUnkEYHG4EJGY2ZRToPTiWHH99XVusCT8uRMBFt4SPd2rqEw8UO4qGVRomxdtCq F9yP/y3PSBYaBJ+MgdczyCl0HRVmy2j6uCXJDxaojhfskG3cHHnyJgYo5kA7+x/3sY0a e1vw== X-Google-Smtp-Source: APXvYqzAUxNwopC91TOnVL5OWCCwX02ZC910lFa3yrWgPSH4oaNT26Uf7JNL1bImHscifmXrtCV+ZCB9Y2uf5vV7 X-Received: by 2002:a0c:8705:: with SMTP id 5mr54401806qvh.32.1563904752366; Tue, 23 Jul 2019 10:59:12 -0700 (PDT) Date: Tue, 23 Jul 2019 19:58:39 +0200 In-Reply-To: Message-Id: <1c05651c53f90d07e98ee4973c2786ccf315db12.1563904656.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.22.0.709.g102302147b-goog Subject: [PATCH v19 02/15] arm64: Introduce prctl() options to control the tagged user addresses ABI 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 , 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 , Andrey Konovalov X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Catalin Marinas It is not desirable to relax the ABI to allow tagged user addresses into the kernel indiscriminately. This patch introduces a prctl() interface for enabling or disabling the tagged ABI with a global sysctl control for preventing applications from enabling the relaxed ABI (meant for testing user-space prctl() return error checking without reconfiguring the kernel). The ABI properties are inherited by threads of the same application and fork()'ed children but cleared on execve(). A Kconfig option allows the overall disabling of the relaxed ABI. The PR_SET_TAGGED_ADDR_CTRL will be expanded in the future to handle MTE-specific settings like imprecise vs precise exceptions. Reviewed-by: Kees Cook Signed-off-by: Catalin Marinas Signed-off-by: Andrey Konovalov Signed-off-by: Catalin Marinas --- arch/arm64/Kconfig | 9 ++++ arch/arm64/include/asm/processor.h | 8 +++ arch/arm64/include/asm/thread_info.h | 1 + arch/arm64/include/asm/uaccess.h | 4 +- arch/arm64/kernel/process.c | 73 ++++++++++++++++++++++++++++ include/uapi/linux/prctl.h | 5 ++ kernel/sys.c | 12 +++++ 7 files changed, 111 insertions(+), 1 deletion(-) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 3adcec05b1f6..5d254178b9ca 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -1110,6 +1110,15 @@ config ARM64_SW_TTBR0_PAN zeroed area and reserved ASID. The user access routines restore the valid TTBR0_EL1 temporarily. +config ARM64_TAGGED_ADDR_ABI + bool "Enable the tagged user addresses syscall ABI" + default y + help + When this option is enabled, user applications can opt in to a + relaxed ABI via prctl() allowing tagged addresses to be passed + to system calls as pointer arguments. For details, see + Documentation/arm64/tagged-address-abi.txt. + menuconfig COMPAT bool "Kernel support for 32-bit EL0" depends on ARM64_4K_PAGES || EXPERT diff --git a/arch/arm64/include/asm/processor.h b/arch/arm64/include/asm/processor.h index fd5b1a4efc70..ee86070a28d4 100644 --- a/arch/arm64/include/asm/processor.h +++ b/arch/arm64/include/asm/processor.h @@ -296,6 +296,14 @@ extern void __init minsigstksz_setup(void); /* PR_PAC_RESET_KEYS prctl */ #define PAC_RESET_KEYS(tsk, arg) ptrauth_prctl_reset_keys(tsk, arg) +#ifdef CONFIG_ARM64_TAGGED_ADDR_ABI +/* PR_{SET,GET}_TAGGED_ADDR_CTRL prctl */ +long set_tagged_addr_ctrl(unsigned long arg); +long get_tagged_addr_ctrl(void); +#define SET_TAGGED_ADDR_CTRL(arg) set_tagged_addr_ctrl(arg) +#define GET_TAGGED_ADDR_CTRL() get_tagged_addr_ctrl() +#endif + /* * For CONFIG_GCC_PLUGIN_STACKLEAK * diff --git a/arch/arm64/include/asm/thread_info.h b/arch/arm64/include/asm/thread_info.h index 180b34ec5965..012238d8e58d 100644 --- a/arch/arm64/include/asm/thread_info.h +++ b/arch/arm64/include/asm/thread_info.h @@ -90,6 +90,7 @@ void arch_release_task_struct(struct task_struct *tsk); #define TIF_SVE 23 /* Scalable Vector Extension in use */ #define TIF_SVE_VL_INHERIT 24 /* Inherit sve_vl_onexec across exec */ #define TIF_SSBD 25 /* Wants SSB mitigation */ +#define TIF_TAGGED_ADDR 26 /* Allow tagged user addresses */ #define _TIF_SIGPENDING (1 << TIF_SIGPENDING) #define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED) diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h index a138e3b4f717..097d6bfac0b7 100644 --- a/arch/arm64/include/asm/uaccess.h +++ b/arch/arm64/include/asm/uaccess.h @@ -62,7 +62,9 @@ static inline unsigned long __range_ok(const void __user *addr, unsigned long si { unsigned long ret, limit = current_thread_info()->addr_limit; - addr = untagged_addr(addr); + if (IS_ENABLED(CONFIG_ARM64_TAGGED_ADDR_ABI) && + test_thread_flag(TIF_TAGGED_ADDR)) + addr = untagged_addr(addr); __chk_user_ptr(addr); asm volatile( diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c index 6a869d9f304f..ef06a303bda0 100644 --- a/arch/arm64/kernel/process.c +++ b/arch/arm64/kernel/process.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -38,6 +39,7 @@ #include #include #include +#include #include #include @@ -307,11 +309,18 @@ static void tls_thread_flush(void) } } +static void flush_tagged_addr_state(void) +{ + if (IS_ENABLED(CONFIG_ARM64_TAGGED_ADDR_ABI)) + clear_thread_flag(TIF_TAGGED_ADDR); +} + void flush_thread(void) { fpsimd_flush_thread(); tls_thread_flush(); flush_ptrace_hw_breakpoint(current); + flush_tagged_addr_state(); } void release_thread(struct task_struct *dead_task) @@ -541,3 +550,67 @@ void arch_setup_new_exec(void) ptrauth_thread_init_user(current); } + +#ifdef CONFIG_ARM64_TAGGED_ADDR_ABI +/* + * Control the relaxed ABI allowing tagged user addresses into the kernel. + */ +static unsigned int tagged_addr_prctl_allowed = 1; + +long set_tagged_addr_ctrl(unsigned long arg) +{ + if (!tagged_addr_prctl_allowed) + return -EINVAL; + if (is_compat_task()) + return -EINVAL; + if (arg & ~PR_TAGGED_ADDR_ENABLE) + return -EINVAL; + + update_thread_flag(TIF_TAGGED_ADDR, arg & PR_TAGGED_ADDR_ENABLE); + + return 0; +} + +long get_tagged_addr_ctrl(void) +{ + if (!tagged_addr_prctl_allowed) + return -EINVAL; + if (is_compat_task()) + return -EINVAL; + + if (test_thread_flag(TIF_TAGGED_ADDR)) + return PR_TAGGED_ADDR_ENABLE; + + return 0; +} + +/* + * Global sysctl to disable the tagged user addresses support. This control + * only prevents the tagged address ABI enabling via prctl() and does not + * disable it for tasks that already opted in to the relaxed ABI. + */ +static int zero; +static int one = 1; + +static struct ctl_table tagged_addr_sysctl_table[] = { + { + .procname = "tagged_addr", + .mode = 0644, + .data = &tagged_addr_prctl_allowed, + .maxlen = sizeof(int), + .proc_handler = proc_dointvec_minmax, + .extra1 = &zero, + .extra2 = &one, + }, + { } +}; + +static int __init tagged_addr_init(void) +{ + if (!register_sysctl("abi", tagged_addr_sysctl_table)) + return -EINVAL; + return 0; +} + +core_initcall(tagged_addr_init); +#endif /* CONFIG_ARM64_TAGGED_ADDR_ABI */ diff --git a/include/uapi/linux/prctl.h b/include/uapi/linux/prctl.h index 094bb03b9cc2..2e927b3e9d6c 100644 --- a/include/uapi/linux/prctl.h +++ b/include/uapi/linux/prctl.h @@ -229,4 +229,9 @@ struct prctl_mm_map { # define PR_PAC_APDBKEY (1UL << 3) # define PR_PAC_APGAKEY (1UL << 4) +/* Tagged user address controls for arm64 */ +#define PR_SET_TAGGED_ADDR_CTRL 55 +#define PR_GET_TAGGED_ADDR_CTRL 56 +# define PR_TAGGED_ADDR_ENABLE (1UL << 0) + #endif /* _LINUX_PRCTL_H */ diff --git a/kernel/sys.c b/kernel/sys.c index 2969304c29fe..c6c4d5358bd3 100644 --- a/kernel/sys.c +++ b/kernel/sys.c @@ -124,6 +124,12 @@ #ifndef PAC_RESET_KEYS # define PAC_RESET_KEYS(a, b) (-EINVAL) #endif +#ifndef SET_TAGGED_ADDR_CTRL +# define SET_TAGGED_ADDR_CTRL(a) (-EINVAL) +#endif +#ifndef GET_TAGGED_ADDR_CTRL +# define GET_TAGGED_ADDR_CTRL() (-EINVAL) +#endif /* * this is where the system-wide overflow UID and GID are defined, for @@ -2492,6 +2498,12 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3, return -EINVAL; error = PAC_RESET_KEYS(me, arg2); break; + case PR_SET_TAGGED_ADDR_CTRL: + error = SET_TAGGED_ADDR_CTRL(arg2); + break; + case PR_GET_TAGGED_ADDR_CTRL: + error = GET_TAGGED_ADDR_CTRL(); + break; default: error = -EINVAL; break; From patchwork Tue Jul 23 17:58:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11054851 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 69C44746 for ; Tue, 23 Jul 2019 17:59:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5961D286C6 for ; Tue, 23 Jul 2019 17:59:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4BF5D286E0; Tue, 23 Jul 2019 17:59:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C60AC286C6 for ; Tue, 23 Jul 2019 17:59:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 542A18E000A; Tue, 23 Jul 2019 13:59:17 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 4F55F8E0002; Tue, 23 Jul 2019 13:59:17 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 322A58E000A; Tue, 23 Jul 2019 13:59:17 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yw1-f69.google.com (mail-yw1-f69.google.com [209.85.161.69]) by kanga.kvack.org (Postfix) with ESMTP id 0FA968E0002 for ; Tue, 23 Jul 2019 13:59:17 -0400 (EDT) Received: by mail-yw1-f69.google.com with SMTP id i63so32797833ywc.1 for ; Tue, 23 Jul 2019 10:59:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=JFgaWDMGqAls6G489iThigfOi0kr7eFjggN3NFe6qBQ=; b=LZoWFVkVcivvxqPVLDgINbaGhvGW7DAE8YZYoq/Yr2dBNxRi8W2NFillsUVrzp9QD5 mzaaV9VpD2nR1vX1RxykoSFqEwP0Xg8YZ77J0x3gtZcqeEXcq3xY80n24BjdIhjJr9Hz cJs6e/nFmGpCYHU6cq5Hprx1Mf+NVGC1cblBqAVYqgj7E3ojfpDWAA6Rab3tL3r1Y8o8 mqTVVq97jMWVOwKqGIKYAJbDCf94klkamMcVosAKawnuA7ZgjHk+owWceEl3LpCBExaK a5A4hmafxhU5REkzadAiiBnManLyYXjrFhZrblu2y8Qcsn3dyOLx5S8/MsW1/q6sWp+D kEaA== X-Gm-Message-State: APjAAAUrNr014CmP+IV9VtI9E3n1gMy8L/CoJig1jcXX8QsqVhsLwkgq njbsmCiE+OwU6Qi04/sLIYZKOukIrpUGWLJTEbyjP4XtvUw7IVtx9HPgB5diH4XPkOUO9WXoqu3 Ns+GC5/MOaKWTdkY6V4iUp6HQYkJm/rIpyHe4J4zWUnNnCAbLNxnCX82sUql/wZqHsA== X-Received: by 2002:a25:8b01:: with SMTP id i1mr35734028ybl.478.1563904756767; Tue, 23 Jul 2019 10:59:16 -0700 (PDT) X-Received: by 2002:a25:8b01:: with SMTP id i1mr35734005ybl.478.1563904756165; Tue, 23 Jul 2019 10:59:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563904756; cv=none; d=google.com; s=arc-20160816; b=blDxVJTOkzLZQhaZ/3hjNZnuDPwU+xaEhlNnyUb6BhtRaKbHaRkAI8dsd5G2+U8c4q uwb1SIASR2wREx8EFSm83i3FeDN2TgMjT0KOS9MdkRrWhhgdq5mVjIavND2G92Famwjb 4SECozREzQrGMeA5Kp6cVm0SSQnQ/36vtwcz2Z04plFh8x1kMlDtw+/9zl84PQpA2hK8 Bq89aV/5ux7DKlkjLHZfS8/iD0dm9w2/rjiXWtctU2pR43aT6zUdcvoN2ixtC5gicbf0 xcQFCZslwkW7UfFEA4h2G5XKe/JUt0M+9VfMQgkbo8AqU2QbE1tZF4MccYmRNJEKdwvA 89xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:dkim-signature; bh=JFgaWDMGqAls6G489iThigfOi0kr7eFjggN3NFe6qBQ=; b=YoyP/cpPJ5hP2dTyWkQQmVy5nGIEaWGORc9MrePGPucZ3/yneCcOaGp37WjErz85GX LrE7cHcLqBGwg8er2bMCRS3LJER3JDcmXK+mZcn3jGZAydYqW1xmrvT7uYcrh7hKHNyG GLFJHE6sBqMAPigKRyGcfoWtjC/ErBpwS35v45xZKRv9cnwriodaNW94gQwLJqXP/4Sl SE9rNJRGZ7WZ0DxzN0jh3gjTSDoeuXSPD6uXkcmd2pvlv5YDSch4PkNMH/ScHT3aoxsS wft6t20rbxXKhb4872fLD/G+dCnXUBYReUN0Yygi8eO/qjg73eA/5k6gXZ78iBGX0rqE na5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="bdR5/fk0"; spf=pass (google.com: domain of 380o3xqokcfyyb1f2m8bj94cc492.0ca96bil-aa8jy08.cf4@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=380o3XQoKCFYyB1F2M8BJ94CC492.0CA96BIL-AA8Jy08.CF4@flex--andreyknvl.bounces.google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from mail-sor-f73.google.com (mail-sor-f73.google.com. [209.85.220.73]) by mx.google.com with SMTPS id w6sor12751600ywg.199.2019.07.23.10.59.16 for (Google Transport Security); Tue, 23 Jul 2019 10:59:16 -0700 (PDT) Received-SPF: pass (google.com: domain of 380o3xqokcfyyb1f2m8bj94cc492.0ca96bil-aa8jy08.cf4@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) client-ip=209.85.220.73; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="bdR5/fk0"; spf=pass (google.com: domain of 380o3xqokcfyyb1f2m8bj94cc492.0ca96bil-aa8jy08.cf4@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=380o3XQoKCFYyB1F2M8BJ94CC492.0CA96BIL-AA8Jy08.CF4@flex--andreyknvl.bounces.google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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=JFgaWDMGqAls6G489iThigfOi0kr7eFjggN3NFe6qBQ=; b=bdR5/fk0JGKoW7w0SFkFyWDsbkS1I0veDFpzyivmTwHIiT1ZA97yr7ZNBj0H2AShr3 pJNPC/lixw/WX323ImP4bsjq93mjJZOu3XmkpNpFXgCiVzkeEYaOnJlxDz/E8gDEr+0Z 7c+WyXnemQpO1dfLw6iPwN48OpAMyrI2pHKz9BmhLCsXRKcJ8hMZ0q56McGVdIPQVUpC wU6S0XoQlY0qPAb6VoXtHP5wFmiEaCJNy21C3scQNSBD97gIywyYsw0LYzCg0A9GdhDR +widw+4UdtR8VyNJh7brTEfaRq+BSrao4/hRns/7LOx28RgrtCz6SeEtUQ8FFyTY31id 9AMg== X-Google-Smtp-Source: APXvYqyP8TuTil7EZTQQhTgA2DwZYNvsIYk2hVJOr9gyh7gqwx0FC8mj4nBRBXxdbEE2muRKlx89y5GRj7Mj4rf4 X-Received: by 2002:a81:9c0b:: with SMTP id m11mr45173898ywa.3.1563904755656; Tue, 23 Jul 2019 10:59:15 -0700 (PDT) Date: Tue, 23 Jul 2019 19:58:40 +0200 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.22.0.709.g102302147b-goog Subject: [PATCH v19 03/15] lib: 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 , 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 , Andrey Konovalov X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP This patch is a part of a series that extends 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: Vincenzo Frascino Reviewed-by: Khalid Aziz Acked-by: Kees Cook Reviewed-by: Catalin Marinas 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 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; From patchwork Tue Jul 23 17:58:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11054855 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F2C5413A4 for ; Tue, 23 Jul 2019 17:59:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E253B286C6 for ; Tue, 23 Jul 2019 17:59:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D5EC0286E0; Tue, 23 Jul 2019 17:59:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 28436286C6 for ; Tue, 23 Jul 2019 17:59:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A99A78E000B; Tue, 23 Jul 2019 13:59:20 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A4AB38E0002; Tue, 23 Jul 2019 13:59:20 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 89F5C8E000B; Tue, 23 Jul 2019 13:59:20 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by kanga.kvack.org (Postfix) with ESMTP id 68F528E0002 for ; Tue, 23 Jul 2019 13:59:20 -0400 (EDT) Received: by mail-qt1-f200.google.com with SMTP id x1so39223338qts.9 for ; Tue, 23 Jul 2019 10:59:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=AkbJvDAOuVzgBhtZb883Z6kAaHzqiKQW54Ip7ZSyDSQ=; b=k6AklLBiY4IgloYgbHGHy+puWMNc+LXthNMi21lqtNGRJrAo6g1u9SziSea/XyhgAS yzCiSBzWpTw5ZUVKt+dHPo7xZV+3OhY8gW1hOk2slFPjNS2AYBkIQWEFDkg7dR1I3nWp WzmMUuSM7YNzFk5IAjbB19uf0wEUciC/TSsDdDowMomFY5jpjKDOKiKxSMXbZW0nyhXT 9dhaU1v4NCp0qKKpm/Y2kJWrBgLoPcjXZr9+Fl7FsXWX4C6swGWj8F7MvldfVsGSxpf7 Guz2Qu4wiOyvjIbKMUeQmbKXF9m9UalibOcDmCTMdfk794hpqVmsyK6LQuqt5B51mq6u Cltg== X-Gm-Message-State: APjAAAUcGFeMjuVMHFQaV7bAie5R34A/YfMFtcvthnLmht2nR1YpRAEf eGKRhuxSwxLPEO9Bh3+7tsTDIlRTSGTJ3MGTit/22akQ0LX+I1GXFKamUwD3v7PW29E41Ysf5TJ CEexU/5VKQomu6/Y3kjGk8XllLBxZyeWsZtqYQynn34MHC6OOVp0ZbvSKsb4Mwu9uOA== X-Received: by 2002:a0c:b0ef:: with SMTP id p44mr17092064qvc.27.1563904760168; Tue, 23 Jul 2019 10:59:20 -0700 (PDT) X-Received: by 2002:a0c:b0ef:: with SMTP id p44mr17092049qvc.27.1563904759454; Tue, 23 Jul 2019 10:59:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563904759; cv=none; d=google.com; s=arc-20160816; b=BHKWlVLGwrc7upQSJCYny0d19Iod5iYppa+KCy0tuNXgiGd5+qyGQo9dfOJ0BOIGMK LiUVed2NKIX8l6qJqbbuJY4hzn548aob3SjepKdQXEV9jeYjUVN6mGhz2BjbbVPSjEEi p4nOj8VrgQQHJaR5LLRmvIw96kzx2d3aHtgu2U/kEBiJTUJjCi4xytkwTuH1f0IyxKJV SdSO7mnuxfV9I8QvDIEeFsumeY6QF1vXYdB1h1Y+kioK1JaoMO/9worSOVxPevLGGZHu OmCFUDen5bkaB5FOCBenj2xVOypCvfNLtwA8Cxdgo4Qi81Tc+MrSicEeSAYnlvC1jeFI D0vw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:dkim-signature; bh=AkbJvDAOuVzgBhtZb883Z6kAaHzqiKQW54Ip7ZSyDSQ=; b=yIWHSVINLchzuDdFBHOMqEVfGjedq7954AikfxFufZd0YJSd1t0H0iblCXzcPPPdip 4rBB6a6IYlmSwekET1SMC1FNK0zFFnbhkgUw08AtfCHyyyn+HiXqmKaJlEo1uJyVYY6/ zucW0CaSLkwN1qpInWnWMOPohO0TiS6PtxAyxpvj+YGhME6AnX7UKpv83kv8iEDsWuJX KxAFjSjUq1fh2a6J9yMLaW1b1iYSAzohK7/V73WS0m/MvASVb4bLtrePTisusWR+FpT2 VUaMBQWF78npMcBjZ3Vu7yv2/PdVztP0TP03DMW4PQs0phwE7fb4rBO+J9rQ/N3an4PD MZNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=q4SIjzbb; spf=pass (google.com: domain of 39ko3xqokcfk1e4i5pbemc7ff7c5.3fdc9elo-ddbm13b.fi7@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=39ko3XQoKCFk1E4I5PBEMC7FF7C5.3FDC9ELO-DDBM13B.FI7@flex--andreyknvl.bounces.google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from mail-sor-f73.google.com (mail-sor-f73.google.com. [209.85.220.73]) by mx.google.com with SMTPS id z15sor24927700qka.71.2019.07.23.10.59.19 for (Google Transport Security); Tue, 23 Jul 2019 10:59:19 -0700 (PDT) Received-SPF: pass (google.com: domain of 39ko3xqokcfk1e4i5pbemc7ff7c5.3fdc9elo-ddbm13b.fi7@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) client-ip=209.85.220.73; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=q4SIjzbb; spf=pass (google.com: domain of 39ko3xqokcfk1e4i5pbemc7ff7c5.3fdc9elo-ddbm13b.fi7@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=39ko3XQoKCFk1E4I5PBEMC7FF7C5.3FDC9ELO-DDBM13B.FI7@flex--andreyknvl.bounces.google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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=AkbJvDAOuVzgBhtZb883Z6kAaHzqiKQW54Ip7ZSyDSQ=; b=q4SIjzbblqeI44AwtclbDFRtQ9wdJy9gPXjSP5D6CdGec7GwqRgc0qKMP+S9kknKlU 82fY8UfjDM6LghjHC28q6xcrb5XyIrOY2+w3WNydAgovI5kIS1vpjE5ULtrqoDRfxPtv zexvQyPzU4/fT0I0rupHVHVtbPsNH+ejeSr+2n5DT43Fq4f+3Y34+AINUwgLVB/IpeWl 2qiXbpB8hAKqk1Ls/rzeOI5t8QaLZwI3CzXqXR93GSUwR46IrtzAa49DUYYvDSaVfKfg X0K4wZzWqZQQjEWjIdDvveS7FBsn9qKvSIsR6zka2FAuEw6n9xebOF/L+bYdctZFTEvn BIZw== X-Google-Smtp-Source: APXvYqyEBnxjs/QWPPehEo5rVljMjvkTMucPtveM7x8Do5mUgC0Wj7RnkMWK4mXW3q6nZowCoKSh8LTGEiBYy9qe X-Received: by 2002:a37:4914:: with SMTP id w20mr50637396qka.156.1563904758910; Tue, 23 Jul 2019 10:59:18 -0700 (PDT) Date: Tue, 23 Jul 2019 19:58:41 +0200 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.22.0.709.g102302147b-goog Subject: [PATCH v19 04/15] mm: untag user pointers passed to memory syscalls 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 , 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 , Andrey Konovalov X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP This patch is a part of a series that extends kernel ABI to allow to pass tagged user pointers (with the top byte set to something else other than 0x00) as syscall arguments. This patch allows tagged pointers to be passed to the following memory syscalls: get_mempolicy, madvise, mbind, mincore, mlock, mlock2, mprotect, mremap, msync, munlock, move_pages. The mmap and mremap syscalls do not currently accept tagged addresses. Architectures may interpret the tag as a background colour for the corresponding vma. Reviewed-by: Khalid Aziz Reviewed-by: Vincenzo Frascino Reviewed-by: Catalin Marinas Reviewed-by: Kees Cook Signed-off-by: Andrey Konovalov Signed-off-by: Catalin Marinas --- mm/madvise.c | 2 ++ mm/mempolicy.c | 3 +++ mm/migrate.c | 2 +- mm/mincore.c | 2 ++ mm/mlock.c | 4 ++++ mm/mprotect.c | 2 ++ mm/mremap.c | 7 +++++++ mm/msync.c | 2 ++ 8 files changed, 23 insertions(+), 1 deletion(-) diff --git a/mm/madvise.c b/mm/madvise.c index 968df3aa069f..4b102a61bfbf 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -810,6 +810,8 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior) size_t len; struct blk_plug plug; + start = untagged_addr(start); + if (!madvise_behavior_valid(behavior)) return error; diff --git a/mm/mempolicy.c b/mm/mempolicy.c index f48693f75b37..74c134d0c84e 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -1360,6 +1360,7 @@ static long kernel_mbind(unsigned long start, unsigned long len, int err; unsigned short mode_flags; + start = untagged_addr(start); mode_flags = mode & MPOL_MODE_FLAGS; mode &= ~MPOL_MODE_FLAGS; if (mode >= MPOL_MAX) @@ -1517,6 +1518,8 @@ static int kernel_get_mempolicy(int __user *policy, int uninitialized_var(pval); nodemask_t nodes; + addr = untagged_addr(addr); + if (nmask != NULL && maxnode < nr_node_ids) return -EINVAL; diff --git a/mm/migrate.c b/mm/migrate.c index 8992741f10aa..8f59c24cb141 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1609,7 +1609,7 @@ static int do_pages_move(struct mm_struct *mm, nodemask_t task_nodes, goto out_flush; if (get_user(node, nodes + i)) goto out_flush; - addr = (unsigned long)p; + addr = (unsigned long)untagged_addr(p); err = -ENODEV; if (node < 0 || node >= MAX_NUMNODES) diff --git a/mm/mincore.c b/mm/mincore.c index 4fe91d497436..3cfa120ba0eb 100644 --- a/mm/mincore.c +++ b/mm/mincore.c @@ -257,6 +257,8 @@ SYSCALL_DEFINE3(mincore, unsigned long, start, size_t, len, unsigned long pages; unsigned char *tmp; + start = untagged_addr(start); + /* Check the start address: needs to be page-aligned.. */ if (start & ~PAGE_MASK) return -EINVAL; diff --git a/mm/mlock.c b/mm/mlock.c index a90099da4fb4..a72c1eeded77 100644 --- a/mm/mlock.c +++ b/mm/mlock.c @@ -674,6 +674,8 @@ static __must_check int do_mlock(unsigned long start, size_t len, vm_flags_t fla unsigned long lock_limit; int error = -ENOMEM; + start = untagged_addr(start); + if (!can_do_mlock()) return -EPERM; @@ -735,6 +737,8 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len) { int ret; + start = untagged_addr(start); + len = PAGE_ALIGN(len + (offset_in_page(start))); start &= PAGE_MASK; diff --git a/mm/mprotect.c b/mm/mprotect.c index bf38dfbbb4b4..19f981b733bc 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -465,6 +465,8 @@ static int do_mprotect_pkey(unsigned long start, size_t len, const bool rier = (current->personality & READ_IMPLIES_EXEC) && (prot & PROT_READ); + start = untagged_addr(start); + prot &= ~(PROT_GROWSDOWN|PROT_GROWSUP); if (grows == (PROT_GROWSDOWN|PROT_GROWSUP)) /* can't be both */ return -EINVAL; diff --git a/mm/mremap.c b/mm/mremap.c index fc241d23cd97..64c9a3b8be0a 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -606,6 +606,13 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len, LIST_HEAD(uf_unmap_early); LIST_HEAD(uf_unmap); + /* + * Architectures may interpret the tag passed to mmap as a background + * colour for the corresponding vma. For mremap we don't allow tagged + * new_addr to preserve similar behaviour to mmap. + */ + addr = untagged_addr(addr); + if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE)) return ret; diff --git a/mm/msync.c b/mm/msync.c index ef30a429623a..c3bd3e75f687 100644 --- a/mm/msync.c +++ b/mm/msync.c @@ -37,6 +37,8 @@ SYSCALL_DEFINE3(msync, unsigned long, start, size_t, len, int, flags) int unmapped_error = 0; int error = -EINVAL; + start = untagged_addr(start); + if (flags & ~(MS_ASYNC | MS_INVALIDATE | MS_SYNC)) goto out; if (offset_in_page(start)) From patchwork Tue Jul 23 17:58:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11054863 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A8099746 for ; Tue, 23 Jul 2019 17:59:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 981EC286C6 for ; Tue, 23 Jul 2019 17:59:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8C1C9286E0; Tue, 23 Jul 2019 17:59:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1021E286C6 for ; Tue, 23 Jul 2019 17:59:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AC1818E000C; Tue, 23 Jul 2019 13:59:23 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A72678E0002; Tue, 23 Jul 2019 13:59:23 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8EBB18E000C; Tue, 23 Jul 2019 13:59:23 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by kanga.kvack.org (Postfix) with ESMTP id 70D3C8E0002 for ; Tue, 23 Jul 2019 13:59:23 -0400 (EDT) Received: by mail-qt1-f198.google.com with SMTP id x7so39141694qtp.15 for ; Tue, 23 Jul 2019 10:59:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=4Wn1GFyfxt3NCYf4PGNTFvqYM1MN1tNvgEFxNqktnk8=; b=ehu0SF9H7sKnJ8MLn2PFWfgGQ7WaKm+cMCFfy0QzeKrqEnq9Jin0bLO5+d0f6iRpOq dpsf7M6Gw+s+sH2qnkG2Mm2mRaXj7ukdMw/JsbdZ8dGn2Xa4isYBcGK1I41RKdk6+taA 1NO3F+GmXzDIYmSadMkiLcw3+aOlxDzhf/dtQUvjir/Ct0OaEwQ0git7HXfuH5prQm1n iI7/y/HRJ32T/weuSV/AP9y7EBEfKTyujIQVrmCHtOb1K/66GUROzOiY9KDAHol6grJM bWH3g0l/Qxv0N+5OeWOscx1LS9nyMW5goGNtvTZ08RhLZNAnxyFX6dXlpOKNawT6mgBA xV1w== X-Gm-Message-State: APjAAAW+udCRfheZw8FDVhcsaY0hmcOPCWl1YBKG30n8+cY6+krQDUEk sdUvYzrAfJnnJuG8+vlnJl6Wi/Rwbiyo53Ew/umkJVpikyRup3K1TUXU2lijOilSHLZQYCDHIGf w2/1TSCqc69FMH/RlP+aTmTBG6sJj0AwxULZBh0558eM6H4WYV43KcgxycZsnnZx1WQ== X-Received: by 2002:a37:98c3:: with SMTP id a186mr51731249qke.498.1563904763233; Tue, 23 Jul 2019 10:59:23 -0700 (PDT) X-Received: by 2002:a37:98c3:: with SMTP id a186mr51731239qke.498.1563904762727; Tue, 23 Jul 2019 10:59:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563904762; cv=none; d=google.com; s=arc-20160816; b=NJQVvp+6NIQfqglfp3UOd0GHyk8jGIEGokIUEiu9Il0MuTxZQUXQ0/SjM0wHJN8GzI gMyhub5UQ8howHIsN3VQ/Kz+Go8oui4UFThSMHlyxpYgjc2oVA/Dtn4Jlv3LOVtfGJEp RitNFwq2yXriZfQNH5nEgtRpOYqk8Bw391Ddyq/6dQL9q1XoEL/a0IqA/t1LBG4MSC3c Hng3PKm8MrffEEAvGos7MYw1x0aZ+aGQZ6jekl1+Z0CT6EiXSmjUAY4vAJlwdNPLNEwU zXDm9k6ZyCNMvJAlJtgSpdPSVAvUiTCrBDdClSlrnV2o4lUKXIDNJ3WOmiaYIB4qYuC/ /SeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:dkim-signature; bh=4Wn1GFyfxt3NCYf4PGNTFvqYM1MN1tNvgEFxNqktnk8=; b=jjYMdLUSDO7PFSXsfqQ+0HTWGU3Mm9mgGHwwFqqSFOg+8HIzh0ADpVMOzd/Kuj7gv+ uJVEfYEE7gmr4B7vOI5aLGWO2gO9MoCDIWgsTkMRcXvXcqXKHcTJ5BcW5k+rQJS1Mjz1 bQ2f4Ijo6VwtjGNHMTknQx0VxKM7ZNAveFUSEI/MgCl937Bi9kdPLKWQQEl5vygc6o4W +Bab8kPcTK1HgM2pFZAQtAzosCKc4fSzVbArHMbuENi1C1KY061inJAX5NZrmOFalO5T IHCYh1/YsioKnMr0b7IYNJ4tk+rp2gADC5nOagnjJCcztbHN1uGXNaBj7w3FEsYUw5Aw fBDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=XwZfpnbX; spf=pass (google.com: domain of 3-ko3xqokcf05i8m9tfiqgbjjbg9.7jhgdips-hhfq57f.jmb@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3-ko3XQoKCF05I8M9TFIQGBJJBG9.7JHGDIPS-HHFQ57F.JMB@flex--andreyknvl.bounces.google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from mail-sor-f73.google.com (mail-sor-f73.google.com. [209.85.220.73]) by mx.google.com with SMTPS id c73sor24926420qkb.105.2019.07.23.10.59.22 for (Google Transport Security); Tue, 23 Jul 2019 10:59:22 -0700 (PDT) Received-SPF: pass (google.com: domain of 3-ko3xqokcf05i8m9tfiqgbjjbg9.7jhgdips-hhfq57f.jmb@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) client-ip=209.85.220.73; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=XwZfpnbX; spf=pass (google.com: domain of 3-ko3xqokcf05i8m9tfiqgbjjbg9.7jhgdips-hhfq57f.jmb@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3-ko3XQoKCF05I8M9TFIQGBJJBG9.7JHGDIPS-HHFQ57F.JMB@flex--andreyknvl.bounces.google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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=4Wn1GFyfxt3NCYf4PGNTFvqYM1MN1tNvgEFxNqktnk8=; b=XwZfpnbXFN1ibF12kJh4UX27GKqgHpAYVMgncvRg2XMsGuyHBAM2BbcbV2FMLG6KI2 Eail8AtVvVEkdWyRNAKDAPdYJBEXOQRcSGAF4Z+pO2ORJP6spfMGKAIf7M0K0GlZ5J+x 8yVEMOwDv+oyp2b+30vvjnV2SNVEvVcKU1T+4yjg+W1ok7J01teWzQ68jS7jmU8ro/kC Oxn9FlCYKBVtK3Jwi5MWr/zhUNuljezL1OPreJbqbiZZtnxrZ1CQ3LvL2shMV2iJ2vVT olnzEJp2mTvJs0fngbdCdc/sbDwJUI9/28M468SMn/xpTOjrRZ2LIWF7gDkmDS+GMcl9 Q1sg== X-Google-Smtp-Source: APXvYqy0Hkccu8SUSwSAcf0RwepBseg9rSnBcrNaRpXVNhE8d6jRb6uSi4vWmbN3MkxTqVVfEdk8tSl4b+EbX0xe X-Received: by 2002:a37:4f47:: with SMTP id d68mr50765232qkb.104.1563904762211; Tue, 23 Jul 2019 10:59:22 -0700 (PDT) Date: Tue, 23 Jul 2019 19:58:42 +0200 In-Reply-To: Message-Id: <4731bddba3c938658c10ff4ed55cc01c60f4c8f8.1563904656.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.22.0.709.g102302147b-goog Subject: [PATCH v19 05/15] mm: untag user pointers in mm/gup.c 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 , 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 , Andrey Konovalov X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP This patch is a part of a series that extends kernel ABI to allow to pass tagged user pointers (with the top byte set to something else other than 0x00) as syscall arguments. mm/gup.c provides a kernel interface that accepts user addresses and manipulates user pages directly (for example get_user_pages, that is used by the futex syscall). Since a user can provided tagged addresses, we need to handle this case. Add untagging to gup.c functions that use user addresses for vma lookups. Reviewed-by: Khalid Aziz Reviewed-by: Vincenzo Frascino Reviewed-by: Kees Cook Reviewed-by: Catalin Marinas Signed-off-by: Andrey Konovalov --- mm/gup.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mm/gup.c b/mm/gup.c index 98f13ab37bac..1c1c97ec63df 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -799,6 +799,8 @@ static long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm, if (!nr_pages) return 0; + start = untagged_addr(start); + VM_BUG_ON(!!pages != !!(gup_flags & FOLL_GET)); /* @@ -961,6 +963,8 @@ int fixup_user_fault(struct task_struct *tsk, struct mm_struct *mm, struct vm_area_struct *vma; vm_fault_t ret, major = 0; + address = untagged_addr(address); + if (unlocked) fault_flags |= FAULT_FLAG_ALLOW_RETRY; From patchwork Tue Jul 23 17:58:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11054867 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 79BDD13A4 for ; Tue, 23 Jul 2019 17:59:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6A7EB286C6 for ; Tue, 23 Jul 2019 17:59:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5D898286F1; Tue, 23 Jul 2019 17:59:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6078C286C6 for ; Tue, 23 Jul 2019 17:59:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 20E698E000D; Tue, 23 Jul 2019 13:59:27 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 1BFE88E0002; Tue, 23 Jul 2019 13:59:27 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 011188E000D; Tue, 23 Jul 2019 13:59:26 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-vk1-f199.google.com (mail-vk1-f199.google.com [209.85.221.199]) by kanga.kvack.org (Postfix) with ESMTP id D4BDF8E0002 for ; Tue, 23 Jul 2019 13:59:26 -0400 (EDT) Received: by mail-vk1-f199.google.com with SMTP id n185so19554950vkf.14 for ; Tue, 23 Jul 2019 10:59:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=/huzVrn6iDinNK3gESNF6fMWuVj1J0a8E8YliY+JUMI=; b=KiTmb/ruzm+9gbt6yGtdwjnHRvOCphLd5zPlyl0Z//C203juD3WPN4xfuFTle5lnP9 kJvZ2zeG5WdIItpCpSem6wI3bWCTK86jUG/K4SsZX1bWFglwxagMkryw/fT75YsPmawo Ut47ULPyIV9O1mVShsmGitPRP4iP3QmKbfdpuPPBcquLc3fO3eh3rukzhtHU6+HtvGC0 LqBNlNbmiCk5pQmlY3lvIU7pxjO1iRwBhO649o0vcgN62T9auqcqYW4BpsYldHrph/4w ohqjtv/TK3L95aA0ef3XsG7D8AleaobUZwS5POzrKz7O191tVVmllXxBnyfZSfJYVkRg kkZQ== X-Gm-Message-State: APjAAAWhdYqkNBgofsnAIZDOYnbFpVxQ0NhujLctjo3qiGLit3Cn0hk6 Rycmx4/EnCQGDY8nT6G37Ana+GkapDfWKHmGm+9o9GR52em2uhxqMs2HpnlnWaNIAGk0nfdEnmJ 9jcB7JKZzhJ++Vr4nQV+q+SVXAF9j4fppwOq30dQOu8q+IDnROa/Oav85vXa649X9Jw== X-Received: by 2002:a67:e3da:: with SMTP id k26mr49810864vsm.131.1563904766620; Tue, 23 Jul 2019 10:59:26 -0700 (PDT) X-Received: by 2002:a67:e3da:: with SMTP id k26mr49810823vsm.131.1563904766127; Tue, 23 Jul 2019 10:59:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563904766; cv=none; d=google.com; s=arc-20160816; b=Rh6NUfWhsVWn3ce04ub40MDfGehrtwkFIcW2B5bfB0byktCtsI5e1CCrAz7C/mWVeA 6FGU87drdCYcpj5B1/d70nG6tgsVaJvPmwyiKNCNVEh+7NBV6X2qk78qIDKTBlIh+jCZ x7fpGN85SIg/nmxaPk5NDHtUHQxc7AckGHBpSuGAfQpf8azFfCHDE+5Q9QJgNaBgx0Tg e1Cu32f2kMAawiMRk5FBRQsCyD7AWKW7Zyv4GoIh3BTyKA2zheZgUTbhW2DvqNU+eNz+ Z/ne/0pSOQ3phSMNrZ/IfwaVZH1ghY6un86hPhPkUOAChzZ92A6zWzksEcA97a/yVVxZ L7jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:dkim-signature; bh=/huzVrn6iDinNK3gESNF6fMWuVj1J0a8E8YliY+JUMI=; b=kLgWvhFzFT94Gfa2GCvxnoshvhHaHd6qGuXHr3f4oxIw1d6vRBpadJQmbK1kW7N0JA QOwnXH3BsGxq/CSUgFdSQIRTYnG2zvWBx1QTSoaBfC6AN3g6N2kxAZ6PAw5Q+8v1VXR3 NHk8MGQY4nmEg7KegEaIgCvLi1N2LjeU6tKVFZawWdEV8rfw+/D6SlSna15315Uak53Q 5vJJJ1hV0Mkztuz8Niy8WxRIlC4ARSFSr7b8F3aYVf4Yk118UNw+7HEovujXx4dst+xe q/v3hsMhH70oOzThUoDoE/kWBQ1bJGjIOu5XRZYwvUh6/JVRPAl0NRcjdfD/6gIJy+9j I/pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Y7zAf+Eq; spf=pass (google.com: domain of 3_uo3xqokcga8lbpcwiltjemmejc.amkjglsv-kkit8ai.mpe@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3_Uo3XQoKCGA8LBPCWILTJEMMEJC.AMKJGLSV-KKIT8AI.MPE@flex--andreyknvl.bounces.google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from mail-sor-f73.google.com (mail-sor-f73.google.com. [209.85.220.73]) by mx.google.com with SMTPS id 111sor21746543uar.30.2019.07.23.10.59.26 for (Google Transport Security); Tue, 23 Jul 2019 10:59:26 -0700 (PDT) Received-SPF: pass (google.com: domain of 3_uo3xqokcga8lbpcwiltjemmejc.amkjglsv-kkit8ai.mpe@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) client-ip=209.85.220.73; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Y7zAf+Eq; spf=pass (google.com: domain of 3_uo3xqokcga8lbpcwiltjemmejc.amkjglsv-kkit8ai.mpe@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3_Uo3XQoKCGA8LBPCWILTJEMMEJC.AMKJGLSV-KKIT8AI.MPE@flex--andreyknvl.bounces.google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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=/huzVrn6iDinNK3gESNF6fMWuVj1J0a8E8YliY+JUMI=; b=Y7zAf+EqSsPzgFlPRtHiU2eaf3uvF3mBfxNqtK2dkyuo3VTBYXjjpviaGnsQe0yYUQ RZjdFooS3ZC7uUt58aVI/4cdpsAs60vswb3AsNKQ+PFZtVBvzHw5kY0TqkqeCmyj7riF mtQh5FnaNVG9iaAtW+G98/NdplTTfZ9IkSgAzb8usp7NHgKVNq41drkIZNhCHbFrZwbP oh8Z0GVIBTZb34XQapQJ/Cc8NMSc6thxgEsgQUYNQcR1lgRqwCY4KcosdJFpWo+DlmgQ eRBAMO05IGodFWFysR4D+7FGT50746wIbh4QySN2wsOGOenRi1KIej0OqRFaxZbG5kzF UnOg== X-Google-Smtp-Source: APXvYqza4RkKEiX9RSMJ4O0WeYRSe7jZPKwJC2E9aqA1oTke3kgtphbjO4en0GBzP/IdlZCHDhS+pYVnwN9x8xEl X-Received: by 2002:ab0:1c2:: with SMTP id 60mr34283049ual.78.1563904765450; Tue, 23 Jul 2019 10:59:25 -0700 (PDT) Date: Tue, 23 Jul 2019 19:58:43 +0200 In-Reply-To: Message-Id: <28f05e49c92b2a69c4703323d6c12208f3d881fe.1563904656.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.22.0.709.g102302147b-goog Subject: [PATCH v19 06/15] mm: untag user pointers in get_vaddr_frames 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 , 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 , Andrey Konovalov X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP This patch is a part of a series that extends kernel ABI to allow to pass tagged user pointers (with the top byte set to something else other than 0x00) as syscall arguments. get_vaddr_frames uses provided user pointers for vma lookups, which can only by done with untagged pointers. Instead of locating and changing all callers of this function, perform untagging in it. Reviewed-by: Khalid Aziz Reviewed-by: Vincenzo Frascino Acked-by: Catalin Marinas Reviewed-by: Kees Cook Signed-off-by: Andrey Konovalov --- mm/frame_vector.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/frame_vector.c b/mm/frame_vector.c index c64dca6e27c2..c431ca81dad5 100644 --- a/mm/frame_vector.c +++ b/mm/frame_vector.c @@ -46,6 +46,8 @@ int get_vaddr_frames(unsigned long start, unsigned int nr_frames, if (WARN_ON_ONCE(nr_frames > vec->nr_allocated)) nr_frames = vec->nr_allocated; + start = untagged_addr(start); + down_read(&mm->mmap_sem); locked = 1; vma = find_vma_intersection(mm, start, start + 1); From patchwork Tue Jul 23 17:58:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11054871 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 658A3746 for ; Tue, 23 Jul 2019 17:59:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 52DC9286C6 for ; Tue, 23 Jul 2019 17:59:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 446BF286E0; Tue, 23 Jul 2019 17:59:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C0DF0286C6 for ; Tue, 23 Jul 2019 17:59:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 62DC28E000E; Tue, 23 Jul 2019 13:59:30 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 5B8338E0002; Tue, 23 Jul 2019 13:59:30 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 47ECD8E000E; Tue, 23 Jul 2019 13:59:30 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by kanga.kvack.org (Postfix) with ESMTP id 27AE08E0002 for ; Tue, 23 Jul 2019 13:59:30 -0400 (EDT) Received: by mail-qt1-f199.google.com with SMTP id h47so39125442qtc.20 for ; Tue, 23 Jul 2019 10:59:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=SnCe+Mtnf/4IPVX5vctz2kNHbLvxo+cXn+T1BQBMjSY=; b=d5sM4lFsBv+8K/X2jIQnR0t130sOVd+z3MY8E1zaENsuh3cQ1khD5gKsVPvfdvhPJB dTd5mIySSZxcczSHyTXhxWPg4lT9iqlSiC01Fc8s3fJGi0KL0vFe/3wRKu5nWbF6TTRk ddo43zxoPkdPSA7NToA5zf3V8s9r3QCsHti1QHNsUsWI2wLnMf1d9XkIo2xfYDBGPuVU tRlt/T/2TkNA5NK12wfeyb9LQb9zAgmj85CdczTMM/08VMCtbkFojv0EFVqOlKTJd1P8 /FL3tP58wFTOzps5bA5c7XwwtPJYq/n6wE0pTJH8CvLYY4b+K+d+WBPpoxpNbm6bq5Fa cEOQ== X-Gm-Message-State: APjAAAUETVtLzGyRifMJcgm93uZx+LuWYZy2gDeP2GCGWWcy8gAn/G3M ivdJ9LyTLWrMUzBQGLz6O3jt4aMwquK7Ds+imFrFsGqLaEiXnREIjmqN9QaA92bKhQmqNSP6LYX 8IeGVRVL5r8cN3T6XeiRKnlPZ6QWTndEyyc6SuJVGPvNopS2Jggyt5Wu3Gb/zyskXCA== X-Received: by 2002:a0c:acab:: with SMTP id m40mr56671319qvc.52.1563904769962; Tue, 23 Jul 2019 10:59:29 -0700 (PDT) X-Received: by 2002:a0c:acab:: with SMTP id m40mr56671310qvc.52.1563904769405; Tue, 23 Jul 2019 10:59:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563904769; cv=none; d=google.com; s=arc-20160816; b=AOqQUs3JR2STxdo4lXrm4PlyAAjkZD2v+eJ3DA+u+lieWmFPFBjiZ+pHUj/roixUCU 3CRe3a6gocZpijHM/EQaNWmYUPbDC7xpbju3UTK1HuRKLk96UE5DqefyqCc+cbMgV3Gv 5l143WsI+ez5jJ5Cg8spkzG8mBC1qlHEgmnzqhXy3od8fLbf9tYitMuM4teJ0n0vj6OA nZKG7VRJsG6vFY7AIgLwIqFFTaSRB8OYp/wD0RV7mLeNJtDMn294Bx5tptERlHukTt89 rtR/rFGGXdydsLhiGg5rYaHi8HaQQG5WJ0xCOZic2xVq9JQhgwMn997Y0i6oh6LV2pqg +HQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:dkim-signature; bh=SnCe+Mtnf/4IPVX5vctz2kNHbLvxo+cXn+T1BQBMjSY=; b=0tk820CNnGdb7/T4JJ4Kb1ACTJbFuXH7YpLDp2+Jtm3wdO0NAZ85DgHxSPnP3bvAd7 13xLpuMN0H5WvC4c8W5rfEgHyflejiojCsBQRmuIV9YWSSQ+/86PgvW3ooc9MUV5b+t0 kQrP3cd3uTi8hVdw6gams1798SoqsCEbTLzaZkMqvqV7SHST4rmrIW4RY/p0rYQZPiL3 kPjHbb7Tt3m/Q8CqVrc3OI6VU+CG2vIByfjKHFtldHpv3xFzsxRpEGTfUQtmKeP9hIUJ xa/G11mAKDUkSbFoYh8040uO3MN62IeJ18KUHK2IYF3iO6WhjIp9cuomkqtR8lO1d/wl mdYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=H4TiQUgR; spf=pass (google.com: domain of 3aes3xqokcgmboesfzlowmhpphmf.dpnmjovy-nnlwbdl.psh@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3AEs3XQoKCGMBOESFZLOWMHPPHMF.DPNMJOVY-NNLWBDL.PSH@flex--andreyknvl.bounces.google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from mail-sor-f73.google.com (mail-sor-f73.google.com. [209.85.220.73]) by mx.google.com with SMTPS id d14sor58030730qtq.31.2019.07.23.10.59.29 for (Google Transport Security); Tue, 23 Jul 2019 10:59:29 -0700 (PDT) Received-SPF: pass (google.com: domain of 3aes3xqokcgmboesfzlowmhpphmf.dpnmjovy-nnlwbdl.psh@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) client-ip=209.85.220.73; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=H4TiQUgR; spf=pass (google.com: domain of 3aes3xqokcgmboesfzlowmhpphmf.dpnmjovy-nnlwbdl.psh@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3AEs3XQoKCGMBOESFZLOWMHPPHMF.DPNMJOVY-NNLWBDL.PSH@flex--andreyknvl.bounces.google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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=SnCe+Mtnf/4IPVX5vctz2kNHbLvxo+cXn+T1BQBMjSY=; b=H4TiQUgRdi4EHpYB8nTtg37yn9l3JyAu6VKcW2CQCTgny+vzJbtQEYhMy5VYJWq/CI KrIVgxdlW5aj4Az2DGaszv74HRn6o+lrlFDsTrBfmff9rY/9V5Ds2Mgw7VHb0yVnzniX zHDvZt7zGQFLcaS9bQ85+7iz8VxXg9au1eNOrVwptdD22wpczsG2wyPaMM6iHM1fn6oB qEapo2f+2AfPvvpteYPs6gKu7O45lNfI0gMeElG1uz04IPRB0pwyBE+bIPD+sqfvkwBv pd2Qci5+NW7JO2WHQGIVKZzYhqd9oRhn7n0TTqLXoH+DCmlggKEuaPlzaJC7NBCKpdOt X82Q== X-Google-Smtp-Source: APXvYqysiVBCmSbfWLll2amFKEEXBGqGWfbcKcVshytrTMG9pLoartROQI2FKjRVOxEkpepSHwC8IxHzKKAn6one X-Received: by 2002:ac8:66ce:: with SMTP id m14mr12433817qtp.206.1563904768802; Tue, 23 Jul 2019 10:59:28 -0700 (PDT) Date: Tue, 23 Jul 2019 19:58:44 +0200 In-Reply-To: Message-Id: <1de225e4a54204bfd7f25dac2635e31aa4aa1d90.1563904656.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.22.0.709.g102302147b-goog Subject: [PATCH v19 07/15] fs/namespace: untag user pointers in copy_mount_options 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 , 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 , Andrey Konovalov X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP This patch is a part of a series that extends kernel ABI to allow to pass tagged user pointers (with the top byte set to something else other than 0x00) as syscall arguments. In copy_mount_options a user address is being subtracted from TASK_SIZE. If the address is lower than TASK_SIZE, the size is calculated to not allow the exact_copy_from_user() call to cross TASK_SIZE boundary. However if the address is tagged, then the size will be calculated incorrectly. Untag the address before subtracting. Reviewed-by: Khalid Aziz Reviewed-by: Vincenzo Frascino Reviewed-by: Kees Cook Reviewed-by: Catalin Marinas Signed-off-by: Andrey Konovalov --- fs/namespace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/namespace.c b/fs/namespace.c index 6464ea4acba9..b32eb26af8bf 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -2994,7 +2994,7 @@ void *copy_mount_options(const void __user * data) * the remainder of the page. */ /* copy_from_user cannot cross TASK_SIZE ! */ - size = TASK_SIZE - (unsigned long)data; + size = TASK_SIZE - (unsigned long)untagged_addr(data); if (size > PAGE_SIZE) size = PAGE_SIZE; From patchwork Tue Jul 23 17:58:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11054873 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D665F746 for ; Tue, 23 Jul 2019 17:59:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C7D66286C6 for ; Tue, 23 Jul 2019 17:59:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BA8C8286F1; Tue, 23 Jul 2019 17:59:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3483C286C6 for ; Tue, 23 Jul 2019 17:59:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D80C98E000F; Tue, 23 Jul 2019 13:59:33 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D09448E0002; Tue, 23 Jul 2019 13:59:33 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BFABC8E000F; Tue, 23 Jul 2019 13:59:33 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by kanga.kvack.org (Postfix) with ESMTP id 9843D8E0002 for ; Tue, 23 Jul 2019 13:59:33 -0400 (EDT) Received: by mail-qk1-f198.google.com with SMTP id 5so37135897qki.2 for ; Tue, 23 Jul 2019 10:59:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=mo6ZyD7PJiiiTnkBfnFT33xmRSSjLb2erTRpgEGb4jw=; b=AP4yQG3ynMtfmwSOB/wBxM/Z0Mp5sksPGnuKuH0Sb+JJuuA+q0u8WtCIHQhpXe1mTe Bc7mS7UvYTTt2bFxm00zJ6zLgzzSRoDV2jSEVbta6gOtDcYDVYxcDNw20JvgWi//63Ga +tK97IX/c2g2IQRywLdeUAwi2lWw3wN97hEKKkD/NaMPirGPd0l7mW6kECN5oc1v1oNh q8jiJnmWRH/UfLxV6pbQfvmBNhYwRSvpTzpb6uoq82yDZS/ZEY+DK4xFBXnOiXbFknhS Xbl1sWnCXxjrSXh8E/TG0t0h/66NDFPh7yBfuieZghWZo8yYIC0S8l6d8JEamnWjC7/G pLqw== X-Gm-Message-State: APjAAAWLfVeZnm8GrkQUrCd2lePqXWJZ31nTBoxLkdyZ1GKTtlTgmhel 2Caox1EpJIwjS4AeD53eqwd1yVqf99qjHtVH57iS28lwygfcrIivDmkloMKIww6LjSlBSSfzNUX XUQv0lmrwA9skEdFT/OTHBmLd7sMsYYRI9zFqqBDfa4JWWV2PbOiZJQ+xXAVVQ3L7Sw== X-Received: by 2002:a37:a692:: with SMTP id p140mr49586643qke.432.1563904773333; Tue, 23 Jul 2019 10:59:33 -0700 (PDT) X-Received: by 2002:a37:a692:: with SMTP id p140mr49586629qke.432.1563904772579; Tue, 23 Jul 2019 10:59:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563904772; cv=none; d=google.com; s=arc-20160816; b=fm8GxGaBg/z0rX7/wB4uLBD18kFvgFoX9MivmaklgJo0qKDruTmK9+kGpTWfNiGhBN Ri6f6q8BlYB0NzedN3AewN8Unv/NsaZB88Zvqllpl4y7zjahlnRV3FvOfI8P7xqiTXaC kUPbPVpEo2w4iraQQyOu1aqldbJHr9y2XrB+SN9e7SSlrS44FsfP/geX/6za1zRILXLZ wwvfk++0se1MV5LP+HPHljyR2wCujBjLOb5p/csTovaRfZMutbld7PqpHdjOzpMFrvKl 4J5KyydMY0kws+HjiIhyfYrZodNlxdyNfe8mvVo9HX8YHl601WDBOK4fsUAIrhpzO+Qz C7sA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:dkim-signature; bh=mo6ZyD7PJiiiTnkBfnFT33xmRSSjLb2erTRpgEGb4jw=; b=cDBEVWVobXUKrJuAzcoecCdITWWVUayy9ovbVVO7UOJQmdZB8DXXWeVKGyKjERLxo5 zrKewoXZMY0DgdBpF0vmRWitkXXpjhr5UaDMpKN0+nJSC1PU3/iexZP0u4onBk6sAOWJ KQQzNpbVFXf5OCqwEBnxvr2AMck87Uv6akJzsSdqAmdUCsaVFptYy04X7RTrmlmyVKgm xzWrQVv+2yzK3X1+YDGm7mevkwG3+LXgy0kwlx26OJ08V+my7rUreo+xEvv8oF7mNlh4 tkLxFWpdaUMZIG+fpjbWBdhTJqIglgJ8xolOtWojyj24mE7v41s7WCUTfjIBBFxPMFNe lZSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=cRcOEH0i; spf=pass (google.com: domain of 3bes3xqokcgcfsiwjdpsaqlttlqj.htrqnszc-rrpafhp.twl@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3BEs3XQoKCGcFSIWJdPSaQLTTLQJ.HTRQNSZc-RRPaFHP.TWL@flex--andreyknvl.bounces.google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from mail-sor-f73.google.com (mail-sor-f73.google.com. [209.85.220.73]) by mx.google.com with SMTPS id f84sor25234583qkb.28.2019.07.23.10.59.32 for (Google Transport Security); Tue, 23 Jul 2019 10:59:32 -0700 (PDT) Received-SPF: pass (google.com: domain of 3bes3xqokcgcfsiwjdpsaqlttlqj.htrqnszc-rrpafhp.twl@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) client-ip=209.85.220.73; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=cRcOEH0i; spf=pass (google.com: domain of 3bes3xqokcgcfsiwjdpsaqlttlqj.htrqnszc-rrpafhp.twl@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3BEs3XQoKCGcFSIWJdPSaQLTTLQJ.HTRQNSZc-RRPaFHP.TWL@flex--andreyknvl.bounces.google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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=mo6ZyD7PJiiiTnkBfnFT33xmRSSjLb2erTRpgEGb4jw=; b=cRcOEH0iv2407FEeEXiGtfbNaRtJQIzg5XbYICzGVGc43sPOA3+CZIMWAHKgebQ1Fd NhXvQ2XcNcF8R9x/znx8/B+ZWBuFc0pppCQj6IxF/91ZQehMjq/FUgtTO1kgaD+sdo+u g0fX97ge7Kl52ZUaa6b+4pEh6IxUyFSuMDNJlzhUpxY5RLeNi8LIb5QOqygzH5YcXwTw u/vwHZkzfH96V/r4aumfuyQXlNmESoQtl9/gLW/U3oOdnKUbG/Ywu4Xo6BgLwOzrtBVU Gf76BaPylfmhv0ijCpRq3ZN2WZ9BE8VMsOdxcjRzxf/93AljoTsAfpUOJtPXkeNJ+1FY hU+A== X-Google-Smtp-Source: APXvYqwqXUnbT9S2ecddRPfsS72rTxoBtLQXpIQx9JM0kIhhjvtv5eSOcsPLQ4y/4499Xb23XuIGaF+KOaOVjXRR X-Received: by 2002:a37:47d1:: with SMTP id u200mr49170508qka.21.1563904772061; Tue, 23 Jul 2019 10:59:32 -0700 (PDT) Date: Tue, 23 Jul 2019 19:58:45 +0200 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.22.0.709.g102302147b-goog Subject: [PATCH v19 08/15] userfaultfd: untag user pointers 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 , 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 , Andrey Konovalov , Mike Rapoport X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP This patch is a part of a series that extends kernel ABI to allow to pass tagged user pointers (with the top byte set to something else other than 0x00) as syscall arguments. userfaultfd code use provided user pointers for vma lookups, which can only by done with untagged pointers. Untag user pointers in validate_range(). Reviewed-by: Mike Rapoport Reviewed-by: Vincenzo Frascino Reviewed-by: Catalin Marinas Reviewed-by: Kees Cook Signed-off-by: Andrey Konovalov --- fs/userfaultfd.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index ccbdbd62f0d8..6284a4e719cb 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -1271,21 +1271,23 @@ static __always_inline void wake_userfault(struct userfaultfd_ctx *ctx, } static __always_inline int validate_range(struct mm_struct *mm, - __u64 start, __u64 len) + __u64 *start, __u64 len) { __u64 task_size = mm->task_size; - if (start & ~PAGE_MASK) + *start = untagged_addr(*start); + + if (*start & ~PAGE_MASK) return -EINVAL; if (len & ~PAGE_MASK) return -EINVAL; if (!len) return -EINVAL; - if (start < mmap_min_addr) + if (*start < mmap_min_addr) return -EINVAL; - if (start >= task_size) + if (*start >= task_size) return -EINVAL; - if (len > task_size - start) + if (len > task_size - *start) return -EINVAL; return 0; } @@ -1335,7 +1337,7 @@ static int userfaultfd_register(struct userfaultfd_ctx *ctx, goto out; } - ret = validate_range(mm, uffdio_register.range.start, + ret = validate_range(mm, &uffdio_register.range.start, uffdio_register.range.len); if (ret) goto out; @@ -1524,7 +1526,7 @@ static int userfaultfd_unregister(struct userfaultfd_ctx *ctx, if (copy_from_user(&uffdio_unregister, buf, sizeof(uffdio_unregister))) goto out; - ret = validate_range(mm, uffdio_unregister.start, + ret = validate_range(mm, &uffdio_unregister.start, uffdio_unregister.len); if (ret) goto out; @@ -1675,7 +1677,7 @@ static int userfaultfd_wake(struct userfaultfd_ctx *ctx, if (copy_from_user(&uffdio_wake, buf, sizeof(uffdio_wake))) goto out; - ret = validate_range(ctx->mm, uffdio_wake.start, uffdio_wake.len); + ret = validate_range(ctx->mm, &uffdio_wake.start, uffdio_wake.len); if (ret) goto out; @@ -1715,7 +1717,7 @@ static int userfaultfd_copy(struct userfaultfd_ctx *ctx, sizeof(uffdio_copy)-sizeof(__s64))) goto out; - ret = validate_range(ctx->mm, uffdio_copy.dst, uffdio_copy.len); + ret = validate_range(ctx->mm, &uffdio_copy.dst, uffdio_copy.len); if (ret) goto out; /* @@ -1771,7 +1773,7 @@ static int userfaultfd_zeropage(struct userfaultfd_ctx *ctx, sizeof(uffdio_zeropage)-sizeof(__s64))) goto out; - ret = validate_range(ctx->mm, uffdio_zeropage.range.start, + ret = validate_range(ctx->mm, &uffdio_zeropage.range.start, uffdio_zeropage.range.len); if (ret) goto out; From patchwork Tue Jul 23 17:58:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11054883 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2442913A4 for ; Tue, 23 Jul 2019 17:59:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 153EF286E0 for ; Tue, 23 Jul 2019 17:59:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 07CD3286F3; Tue, 23 Jul 2019 17:59:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7DB3F286F1 for ; Tue, 23 Jul 2019 17:59:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6057F8E0010; Tue, 23 Jul 2019 13:59:39 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 5BA6D8E0002; Tue, 23 Jul 2019 13:59:39 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4CD968E0010; Tue, 23 Jul 2019 13:59:39 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by kanga.kvack.org (Postfix) with ESMTP id 2C8728E0002 for ; Tue, 23 Jul 2019 13:59:39 -0400 (EDT) Received: by mail-qt1-f199.google.com with SMTP id l16so32413217qtq.16 for ; Tue, 23 Jul 2019 10:59:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=bNeVrTrPvpjyJWHVtXYqgQlj6F1/0IzkZ0bc3aEFST0=; b=HMh1vdF0jHcMrh5XLeZeiKYktf+hgRwMYmxYAzFFNwwxSZeGnJm40CnuiGdCgGDzL9 PXRFXHizS5HaRYeH6Viw2pOHMCf4AlRfhTmJXbkrLIyzKBKt4AYkAADVXPoKnuyXtB9n WwesP31ZUvPiS5lSPuEa2R/lP1ZK+olR0ZpqXt3NAv4q9bqilskfzbe+aOypRWhyEXwA /iM2s8r4LpNxxRbUmxZLsssvgXvm2YVtpDx3qmAInz4KWbvqrfKNkJ0rsop7oQsagt5J 9GazzCbFlK2IL9Y5jIooZIuo5XaUl7UzjdAWnlXmM9K7jzyp6GjuqjlsRg5xHhZSVzF+ HYcA== X-Gm-Message-State: APjAAAW7bEnlug6Qcc3UrWGpijkfMQoR8ZpUwuJKNxfVedoVwadL3gZZ Hxff16hT4qAXd9/1hqQHPAWrzXTeDKrh7wqAMblKzOa93U55jjKyaVbozjLtKe91V7rTOSFAvON qK92P+h2ZvvqXQASTRmr8K/xx/1xcz9FM08XOj14mbRIRaZHMYugH9pd3qag2+FggLg== X-Received: by 2002:a05:6214:3f0:: with SMTP id cf16mr55329580qvb.211.1563904778937; Tue, 23 Jul 2019 10:59:38 -0700 (PDT) X-Received: by 2002:a05:6214:3f0:: with SMTP id cf16mr55329537qvb.211.1563904775923; Tue, 23 Jul 2019 10:59:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563904775; cv=none; d=google.com; s=arc-20160816; b=OxBOB07l3F1Yexg4XRbuhvMQMr95YWCYMq9kuRcqX5x9HOQ7W3HjEoBGaOhprwtLXp +loN6SbEqie2WaBNe5MCNPX4HteW9r5B/X95+bBsW3ZWqNnUqrq40Z41lw9Gw3M2Sver gSH+f97Nxz7AofteS3Szbg5hWtAD3JupRmup93pZNf/DbKfyxfx1/H0NkYA0fEJGC2Yc 2iEIdKUQ7B/w96B7li+WdrCJfqbmUmSLSI/qfpuGZKwH3MU8OUlA7eFihjqe5Nms23mD V9WLrbJhJ8WC+b+Pc63ELlhpK4ufvRa16E6sA0Pi8ev95tOey730VV/3kuhS8C4jYvpO 7/MQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:dkim-signature; bh=bNeVrTrPvpjyJWHVtXYqgQlj6F1/0IzkZ0bc3aEFST0=; b=Yy4r+5mIbfo1nOySPyquxbb5Bi+Qd0sITHcgjA26tXkqZqvdhwIee7f3YGYYHrimRF 7wFxG+emj6ZUyGI5q8kp6EUG3ls5X0owAErIofChXgWaiOfId65jfJXNnFwAiu63WibV W2iQuzqNH8RZ5U7MCVALm/2PO7OxnpTXFkHhJD4UC+nGkN3dxijOSLgfU8fRxFNhbJah D8mbUBUVvSzPr/VTXe9UJ/367SqV6U1H8wpneA6UyjQdJjTmxOBNmvfnCfufP8k+gKsI vYm2gZz/ACwshAmNl5CTURx/hnbrim6UO5CjC+I6F+XbJQLHYSAbfcmUoDuD0pe1CNtw zyBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=uWaCwrDk; spf=pass (google.com: domain of 3b0s3xqokcgoivlzmgsvdtowwotm.kwutqvcf-uusdiks.wzo@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3B0s3XQoKCGoIVLZMgSVdTOWWOTM.KWUTQVcf-UUSdIKS.WZO@flex--andreyknvl.bounces.google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from mail-sor-f73.google.com (mail-sor-f73.google.com. [209.85.220.73]) by mx.google.com with SMTPS id j8sor25114521qkl.7.2019.07.23.10.59.35 for (Google Transport Security); Tue, 23 Jul 2019 10:59:35 -0700 (PDT) Received-SPF: pass (google.com: domain of 3b0s3xqokcgoivlzmgsvdtowwotm.kwutqvcf-uusdiks.wzo@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) client-ip=209.85.220.73; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=uWaCwrDk; spf=pass (google.com: domain of 3b0s3xqokcgoivlzmgsvdtowwotm.kwutqvcf-uusdiks.wzo@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3B0s3XQoKCGoIVLZMgSVdTOWWOTM.KWUTQVcf-UUSdIKS.WZO@flex--andreyknvl.bounces.google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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=bNeVrTrPvpjyJWHVtXYqgQlj6F1/0IzkZ0bc3aEFST0=; b=uWaCwrDkBN5GRSLhaw7WQwMKcK3AhPqO/fzElVN3JcPy98UFLj7JeXsg8P+SLlr/8N uTaOa6VggUuncDHcvq/dm+VjbWoXQVCEMVj3yqEv0lzhkp6ZqhxIJZIXWJox0QqwZPpw oblQlXNCYt4tHVrvlJypYdteLVvehIkVLfAlFHjgdjHvnPpCAD6GJOEurxmklM0IOqwa r3we5GB8/FJKwWzwzqUCJtO6E9+uXUbwxjMkihzlNrMKNzLhjZggf+0ZB/LMAafHfS91 EJUlnCmBt8+isj3aFtdbAWI7Fy268Gzi52Ek2+IZaH/c0AJ5vAsChMY+9qCOx6dYD5bK 14lw== X-Google-Smtp-Source: APXvYqyRt/sslYOExeWvOFH4KfKnKxW+V8w8qG436u1Li2H+fm4BIS46hHRf2O8j3VSTAztC1lSBD2N1vfHNfs72 X-Received: by 2002:a05:620a:522:: with SMTP id h2mr54247961qkh.329.1563904775319; Tue, 23 Jul 2019 10:59:35 -0700 (PDT) Date: Tue, 23 Jul 2019 19:58:46 +0200 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.22.0.709.g102302147b-goog Subject: [PATCH v19 09/15] drm/amdgpu: untag user pointers 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 , 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 , Andrey Konovalov X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP This patch is a part of a series that extends kernel ABI to allow to pass tagged user pointers (with the top byte set to something else other than 0x00) as syscall arguments. In amdgpu_gem_userptr_ioctl() and amdgpu_amdkfd_gpuvm.c/init_user_pages() an MMU notifier is set up with a (tagged) userspace pointer. The untagged address should be used so that MMU notifiers for the untagged address get correctly matched up with the right BO. This patch untag user pointers in amdgpu_gem_userptr_ioctl() for the GEM case and in amdgpu_amdkfd_gpuvm_ alloc_memory_of_gpu() for the KFD case. This also makes sure that an untagged pointer is passed to amdgpu_ttm_tt_get_user_pages(), which uses it for vma lookups. Reviewed-by: Kees Cook Suggested-by: Felix Kuehling Acked-by: Felix Kuehling Signed-off-by: Andrey Konovalov --- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c index 1d3ee9c42f7e..00468ebf8b76 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c @@ -1103,7 +1103,7 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu( alloc_flags = 0; if (!offset || !*offset) return -EINVAL; - user_addr = *offset; + user_addr = untagged_addr(*offset); } else if (flags & (ALLOC_MEM_FLAGS_DOORBELL | ALLOC_MEM_FLAGS_MMIO_REMAP)) { domain = AMDGPU_GEM_DOMAIN_GTT; diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c index 939f8305511b..d7855842fd51 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c @@ -291,6 +291,8 @@ int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data, uint32_t handle; int r; + args->addr = untagged_addr(args->addr); + if (offset_in_page(args->addr | args->size)) return -EINVAL; From patchwork Tue Jul 23 17:58:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11054887 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 51F8813A4 for ; Tue, 23 Jul 2019 17:59:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 42224286C8 for ; Tue, 23 Jul 2019 17:59:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 36129286FD; Tue, 23 Jul 2019 17:59:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3D62F286C8 for ; Tue, 23 Jul 2019 17:59:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 829648E0011; Tue, 23 Jul 2019 13:59:40 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 7B2E18E0002; Tue, 23 Jul 2019 13:59:40 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 62B828E0011; Tue, 23 Jul 2019 13:59:40 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yw1-f70.google.com (mail-yw1-f70.google.com [209.85.161.70]) by kanga.kvack.org (Postfix) with ESMTP id 412CE8E0002 for ; Tue, 23 Jul 2019 13:59:40 -0400 (EDT) Received: by mail-yw1-f70.google.com with SMTP id x20so32697060ywg.23 for ; Tue, 23 Jul 2019 10:59:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=JHpRt1iV1Yui2063ArtK5NZw3fPfTbQsXHZ/X8tSe2c=; b=VMhlgkCwCEd0wn7niOl8GLDbiq+ku4j1E8o7pKQ6Zx7zpYIEmdFFzer3gklPBJsmxI P19ht1un6fTFCRGBzJgfpL3ytoZRfw6O6rFFdNxzYRBJvIkahvrX5tE2PxuppfykSFUo K8ZqZGDBj8J60II3IuLWBcnTsrLDRAlipLUY47QIkytVP3e36KATZ6iaBMus8847oPiR XF8sJdv3ThpUa+4dVASx//yOVVpS0cmXqTwLi7WZvEvdpOOV7jPPKZVBXLA6ffqzfVnr Qwi7Ov4/Dude3/IGWVpuy25bkX6/r80eIPbZ33io2B5lAQW5V2Qp3PLFTteOgodIdQAi J/Wg== X-Gm-Message-State: APjAAAWDWiA4qIZn13sOgs5a9kGPdcxRFQSosZB34gf6tFxr/O0US3pK 7BZlPbDC9wwBj6eVGD7BFcfZmyZtf0tPCXGnvRyOt1K+Tp4wacB/c3pjbMEFdwcJsW7nnBYi9n8 c2nNynakDBM/WcOM3I2vRlQxHXHQZDxerRi0OzHAEG+OAVxUlibBUmQ+jvHa7hE05Vw== X-Received: by 2002:a0d:e6cb:: with SMTP id p194mr47431473ywe.83.1563904780060; Tue, 23 Jul 2019 10:59:40 -0700 (PDT) X-Received: by 2002:a0d:e6cb:: with SMTP id p194mr47431436ywe.83.1563904779083; Tue, 23 Jul 2019 10:59:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563904779; cv=none; d=google.com; s=arc-20160816; b=nSbQ4ijddN4oaPIyz8oLG7R/ocjy1qoSYq/BPWXEnOxOS2L8OSiY/vxKx0V4+P8Woj C7oYCPz3yK8UDXdRgA4Nl5CjfH01UeN6a9Fd+0xEnNl1/Dc+HUKV0G1SrSyIojqWCr8/ er9kA5W2SVAQxfdXQMGJGY4xTIrP+rGNeGGTHfd49o/HXmPDAG3r8OuAucaHnBacVfnL Yo9rCoB4IMbex1ILGS7hzvSuJvVxnc1rX5HkT07wYBAiZ6GO1vISmKNC1JFG14uV45dm e0J7HBpfGhnfd37xL7vccVewNqQxVTy9pnp+ukssj9Bh5xiJOXc9rOgNNZ6O7ZHh6wZu eQKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:dkim-signature; bh=JHpRt1iV1Yui2063ArtK5NZw3fPfTbQsXHZ/X8tSe2c=; b=Yqc46pFTvJ5ZYdKlnmP6sQbsll1q88vNl3UiLZsdG8k4aMSHaQLG2Xe69vrkMCRjpP TVHOOka9t48IkuSfhZlRn4ereVWHwWQEAWFvd6T4imR9yBa1fEtiPZlgn5zkztoQVh6U 4pathoY4QYvHLkcBoSengMBtglEqgl048NL0urtb5YaV+sXeqOp9HhexfuDpZKF0sEud AoPa1alWGMoAAdlkUL2lw2iiYGGf2vxIYfU3Qh53nbmDM7480AbT332qkkycFbg2sdjc AYMSBz4rexxuNB/4dAuP2e1eWRcKZi9IKvFYp/DnZ615pCgth8xdfBhPKSpJZOgW0lh2 Emag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=a1Wmmrmp; spf=pass (google.com: domain of 3cks3xqokcg0lyocpjvygwrzzrwp.nzxwtyfi-xxvglnv.zcr@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3Cks3XQoKCG0LYOcPjVYgWRZZRWP.NZXWTYfi-XXVgLNV.ZcR@flex--andreyknvl.bounces.google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from mail-sor-f73.google.com (mail-sor-f73.google.com. [209.85.220.73]) by mx.google.com with SMTPS id n83sor13176376ywc.6.2019.07.23.10.59.39 for (Google Transport Security); Tue, 23 Jul 2019 10:59:39 -0700 (PDT) Received-SPF: pass (google.com: domain of 3cks3xqokcg0lyocpjvygwrzzrwp.nzxwtyfi-xxvglnv.zcr@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) client-ip=209.85.220.73; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=a1Wmmrmp; spf=pass (google.com: domain of 3cks3xqokcg0lyocpjvygwrzzrwp.nzxwtyfi-xxvglnv.zcr@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3Cks3XQoKCG0LYOcPjVYgWRZZRWP.NZXWTYfi-XXVgLNV.ZcR@flex--andreyknvl.bounces.google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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=JHpRt1iV1Yui2063ArtK5NZw3fPfTbQsXHZ/X8tSe2c=; b=a1WmmrmprQZ/rcrg4bnGXYSWuW8VRJo8q/rb7ZTLQKZa1K7I67ixfos045Wbs17Hsc 4ubobzNkIuAipJMS7ZPZPbwqhOEcQBYGSdXPH8NmRc6nBI3x8EfWx1KUwQ8GdoHMrOVu pQBBRoSlOoWQvrJK6Ndgh0M+u5SrtS+Z7XLFtzHXYzmOZcoQreZcqxEy8gyvJGE0ittV 1ErCh2wjdbyE4mfBH/bts1VkhHwv8KlRuO+94TszgBwo8vjAMA7AFwRnm9ELenbWUlad Ar6m6acLtYRugfggNK1CttVM0dqBedFHVAahPgUmqPuarVGgg9aYEhjvXatkNn9RUbXS DjvQ== X-Google-Smtp-Source: APXvYqzQ4z/ZiuFK+6sqRZERC5QgYRRFA4U1Dnbp9V3f1PKQeQRLZSu3TG/nr3g90hvkMvcrT8eNvmOVLDqS9X26 X-Received: by 2002:a0d:d616:: with SMTP id y22mr43437325ywd.365.1563904778592; Tue, 23 Jul 2019 10:59:38 -0700 (PDT) Date: Tue, 23 Jul 2019 19:58:47 +0200 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.22.0.709.g102302147b-goog Subject: [PATCH v19 10/15] drm/radeon: untag user pointers in radeon_gem_userptr_ioctl 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 , 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 , Andrey Konovalov X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP This patch is a part of a series that extends kernel ABI to allow to pass tagged user pointers (with the top byte set to something else other than 0x00) as syscall arguments. In radeon_gem_userptr_ioctl() an MMU notifier is set up with a (tagged) userspace pointer. The untagged address should be used so that MMU notifiers for the untagged address get correctly matched up with the right BO. This funcation also calls radeon_ttm_tt_pin_userptr(), which uses provided user pointers for vma lookups, which can only by done with untagged pointers. This patch untags user pointers in radeon_gem_userptr_ioctl(). Reviewed-by: Khalid Aziz Reviewed-by: Kees Cook Suggested-by: Felix Kuehling Acked-by: Felix Kuehling Signed-off-by: Andrey Konovalov --- drivers/gpu/drm/radeon/radeon_gem.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/gpu/drm/radeon/radeon_gem.c b/drivers/gpu/drm/radeon/radeon_gem.c index d8bc5d2dfd61..89353098b627 100644 --- a/drivers/gpu/drm/radeon/radeon_gem.c +++ b/drivers/gpu/drm/radeon/radeon_gem.c @@ -296,6 +296,8 @@ int radeon_gem_userptr_ioctl(struct drm_device *dev, void *data, uint32_t handle; int r; + args->addr = untagged_addr(args->addr); + if (offset_in_page(args->addr | args->size)) return -EINVAL; From patchwork Tue Jul 23 17:58:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11054889 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C195613A4 for ; Tue, 23 Jul 2019 17:59:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B2B32286F1 for ; Tue, 23 Jul 2019 17:59:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A5950286F9; Tue, 23 Jul 2019 17:59:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 315D2286F1 for ; Tue, 23 Jul 2019 17:59:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 73E6B8E0012; Tue, 23 Jul 2019 13:59:43 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 717178E0002; Tue, 23 Jul 2019 13:59:43 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5415F8E0012; Tue, 23 Jul 2019 13:59:43 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-vk1-f200.google.com (mail-vk1-f200.google.com [209.85.221.200]) by kanga.kvack.org (Postfix) with ESMTP id 3076B8E0002 for ; Tue, 23 Jul 2019 13:59:43 -0400 (EDT) Received: by mail-vk1-f200.google.com with SMTP id l80so19578475vkl.0 for ; Tue, 23 Jul 2019 10:59:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=zUOcAU6p00loQ1nrwWD7GDrs3KRhifPlQNEkBCXrSQU=; b=n6DNkaCdntybi2RBTFtM+r2cz4neg50/J5m38F3IK2wy8H67XiFSBHFC9UfAR/xmVZ CfmpO0e693Cttdk5pR9fNEkz51lEYb1/I6YqH1rSVxWvA4u8ypxAKmZ3XF1QS9udR0a+ GRxvUACcNoA3Fta9QnQLKLWnsZ1Q9+9+LT/IYOxF6NDJn+ufS7dEu2GS7z7Gk/Yd7kDe Z0a8wBgSt4JpGC2MMWbiXZW5/m22FFnzhXcYR48H/gEEReFE9wWaVhOQrbsBQ8QG1Lpy ypdgPLEfBZVRWruI8rl4yGYsTzme36UljbgOar8cs/UEsd22wJRit7aXOu5PYLF0wL/m 1zIw== X-Gm-Message-State: APjAAAUyg3JN3Uo5XxaoZOSJr4OwMxFYYAMDnAp1Rq01sj6j1WTH4g8l KqqzUbmJ1ieFhWLNw6iJwWrLCTk593XwWyIHq1rmezOP06WVjecFTszmil4Fl/B7n2JwHaPBxZL 1N3zJ9EsdZHMawxgGcjeQOmq5nm6jeP4gESZrOavuZXou5EC90Zc/kFCKQQicmep5Ow== X-Received: by 2002:a67:ec42:: with SMTP id z2mr48631416vso.218.1563904782960; Tue, 23 Jul 2019 10:59:42 -0700 (PDT) X-Received: by 2002:a67:ec42:: with SMTP id z2mr48631373vso.218.1563904782405; Tue, 23 Jul 2019 10:59:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563904782; cv=none; d=google.com; s=arc-20160816; b=OrgudGr5AC+OHsDiRbnYT2QkgEFHOsCGMOi23OGoPdgL5YyYJUBYrX4kxFRVRCfzIU q1zvxcanGGkZG/95Z6zP4MQJcqeZmYntn8tbxNK0cBjXvCFHftcspigcBpOlGO/GLSM3 jQD3vaZdNgyGDqUZ92rOtpHW9AWaqIbK3Bn/xQssTA24SH0q/FCfQ8I7K5418zrSoL47 Cx+EF95T9msfG44DvlMyAanARsVf/rNZ7GugWeZ4rmD1M6XuyVW7XlgPRK0tF9YNF7hW mRNpBUiKJOo3cJETMMLQxFyniVNYm1EayreVz1RS35LtW13dz6Hn4DZjLD7C1iqUPUCf zv5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:dkim-signature; bh=zUOcAU6p00loQ1nrwWD7GDrs3KRhifPlQNEkBCXrSQU=; b=XgBPep2LG+oPcsqocPGCyaSjRWgsvzmbeDQqmQho7YYbZ9rUxdtxbJBlGzFd+yj6pR c/av4mNWDJtAz19i2O+J1XQ4jIiVcmyH4pCGPyS1UZ9TXuexocFMcyZrQotNPEUzp7gh lM2MhXtx1AUALJ9hHWOSDkjwtrsx+0/0H/KpLfcM8LJ0MCQIMVzVqiScG7C2SDNq6Cuv tSJALFzFCVkwug8Jy/c2Jkf9BGkiIX2TayHkdHyGGO/HTln4/cfQzx5dUlHqssHduRL6 EB6TX+fA7WcnXMsAOct8y4CjC4g2pOrA0NKiiz7MEFywB8bEXmtnw2AjEsYkB+prnwFO mYJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=VYKldQtW; spf=pass (google.com: domain of 3dus3xqokchaobrfsmybjzuccuzs.qcazwbil-aayjoqy.cfu@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3DUs3XQoKCHAObRfSmYbjZUccUZS.QcaZWbil-aaYjOQY.cfU@flex--andreyknvl.bounces.google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from mail-sor-f73.google.com (mail-sor-f73.google.com. [209.85.220.73]) by mx.google.com with SMTPS id i22sor7624119vsq.28.2019.07.23.10.59.42 for (Google Transport Security); Tue, 23 Jul 2019 10:59:42 -0700 (PDT) Received-SPF: pass (google.com: domain of 3dus3xqokchaobrfsmybjzuccuzs.qcazwbil-aayjoqy.cfu@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) client-ip=209.85.220.73; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=VYKldQtW; spf=pass (google.com: domain of 3dus3xqokchaobrfsmybjzuccuzs.qcazwbil-aayjoqy.cfu@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3DUs3XQoKCHAObRfSmYbjZUccUZS.QcaZWbil-aaYjOQY.cfU@flex--andreyknvl.bounces.google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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=zUOcAU6p00loQ1nrwWD7GDrs3KRhifPlQNEkBCXrSQU=; b=VYKldQtWxdBSrLk5sLC9xz+aQwiA+p9laEjbuJhQ+y14MW59AQItVZb4XUBX4o3STS L9JnHbRkn9qNr1J9IZZM0iJZeAOF+VZrFXTsiwFOiScu2zQivLlflg4hR7bzjUfOiPul +YlOCB2JPa3W1380wQB/LrhFWVtaDyOhlYe6qKxweJSR67HRGh68c9IWX3GDOjZKGFb5 Q62/4pR5YzdGLIAhcCOdymu1+C97aJhL6hmlz2Cb/a02TQdVA66PchqiCSNf3yPDUKCI sPIwmB/L8x0Lmk1aIlxXadTx8+U7n7WnYlELCxDnDvSJNs7fU1kWK2fSsF6MBML60HXD zTzw== X-Google-Smtp-Source: APXvYqwKLPKDYRl/Wu0ROV1RQ4E/ZMl8ZV1EzuXeG4/TJA26mw9Ne5fKh3z8AD7u+iNI3pn1/I9GUafVuAQJAaix X-Received: by 2002:a67:d60e:: with SMTP id n14mr49253950vsj.213.1563904781800; Tue, 23 Jul 2019 10:59:41 -0700 (PDT) Date: Tue, 23 Jul 2019 19:58:48 +0200 In-Reply-To: Message-Id: <7969018013a67ddbbf784ac7afeea5a57b1e2bcb.1563904656.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.22.0.709.g102302147b-goog Subject: [PATCH v19 11/15] IB/mlx4: untag user pointers in mlx4_get_umem_mr 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 , 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 , Andrey Konovalov , Jason Gunthorpe X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP This patch is a part of a series that extends kernel ABI to allow to pass tagged user pointers (with the top byte set to something else other than 0x00) as syscall arguments. mlx4_get_umem_mr() uses provided user pointers for vma lookups, which can only by done with untagged pointers. Untag user pointers in this function. Reviewed-by: Jason Gunthorpe Acked-by: Catalin Marinas Reviewed-by: Kees Cook Signed-off-by: Andrey Konovalov --- drivers/infiniband/hw/mlx4/mr.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/infiniband/hw/mlx4/mr.c b/drivers/infiniband/hw/mlx4/mr.c index 753479285ce9..6ae503cfc526 100644 --- a/drivers/infiniband/hw/mlx4/mr.c +++ b/drivers/infiniband/hw/mlx4/mr.c @@ -377,6 +377,7 @@ static struct ib_umem *mlx4_get_umem_mr(struct ib_udata *udata, u64 start, * again */ if (!ib_access_writable(access_flags)) { + unsigned long untagged_start = untagged_addr(start); struct vm_area_struct *vma; down_read(¤t->mm->mmap_sem); @@ -385,9 +386,9 @@ static struct ib_umem *mlx4_get_umem_mr(struct ib_udata *udata, u64 start, * cover the memory, but for now it requires a single vma to * entirely cover the MR to support RO mappings. */ - vma = find_vma(current->mm, start); - if (vma && vma->vm_end >= start + length && - vma->vm_start <= start) { + vma = find_vma(current->mm, untagged_start); + if (vma && vma->vm_end >= untagged_start + length && + vma->vm_start <= untagged_start) { if (vma->vm_flags & VM_WRITE) access_flags |= IB_ACCESS_LOCAL_WRITE; } else { From patchwork Tue Jul 23 17:58:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11054897 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E79C613A4 for ; Tue, 23 Jul 2019 17:59:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D98E2286C8 for ; Tue, 23 Jul 2019 17:59:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CCA92286F3; Tue, 23 Jul 2019 17:59:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8581F286E0 for ; Tue, 23 Jul 2019 17:59:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F096A8E0013; Tue, 23 Jul 2019 13:59:46 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E1BA38E0002; Tue, 23 Jul 2019 13:59:46 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D0BBF8E0013; Tue, 23 Jul 2019 13:59:46 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yb1-f199.google.com (mail-yb1-f199.google.com [209.85.219.199]) by kanga.kvack.org (Postfix) with ESMTP id A73508E0002 for ; Tue, 23 Jul 2019 13:59:46 -0400 (EDT) Received: by mail-yb1-f199.google.com with SMTP id y9so19897101ybq.7 for ; Tue, 23 Jul 2019 10:59:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=HpinGwuxMTqrT/lGIW6pacs7O2cDdG9/5Ty+RZAfASg=; b=jGOoYkNlV/BRG6ZzgrDUhwBpHX3AlCB2QfdXe4t2ARyyOaEoxkxsEqPrYQ05NF3ek+ W2z35REUL27QZ3uzgS/0BkrMxQconzW2cQBQnFqKUGbGmbnA+oQNyFp+lhebQN47I7yg 0+onug6lS7FEBef/8wBTyYehIx7v+7HRdfZGzCXpjLeggIp0XmbFsLxML0ITw2xvl8II SysnaqsUSTKw/Uh27cJPy0Ef8MBIqY61iLZyg6V599KIk5h3PjcTXI9mvH93FGRQyRQ9 d3d7c476WIQKHZFwHr/4dqaP2f9qIWJ0SNd+ITSuH1UhBWbVyoMynM5TlT5YFHMHpCxJ ATJA== X-Gm-Message-State: APjAAAV0KWCmXF/Kuw11qzwRfLNfJ8BhLU4NS+cfgF3pzllrqTtvfkw7 TakSkaWuMxB18RQcds0rJPsVoZKHbbmW5cRqS8nJiS1FA/IWqaVuwaYiFVuXr2UsG+tP5ldFW2U JObqDP/So6v/afglj+6FwYWsRbzANHT23Azzw9P+DNC/kgw/tkvsFc82zNWhrhlX0xg== X-Received: by 2002:a81:5c0a:: with SMTP id q10mr47561152ywb.474.1563904786469; Tue, 23 Jul 2019 10:59:46 -0700 (PDT) X-Received: by 2002:a81:5c0a:: with SMTP id q10mr47561135ywb.474.1563904785984; Tue, 23 Jul 2019 10:59:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563904785; cv=none; d=google.com; s=arc-20160816; b=o8AGjyDcQV9/8WQ0R0zU3nnoWhAS59Q5IUEw+JuQ8bycoHUtX8CWK6OCGjEcXbZ8n2 8s28DPPD1mri2vcpzEszUdApvchVXFRz8J7i69MtJpQbfalcYhSyZRIYq5v+E2Et/RMf WhEkWOszk1rlH2Xy3eRLTkrwEmZxK8z0JF/zurZ4tzcOWJI8GOYy85EAmtgPiBJxOf9L M5qG9fWTrXPIoi00EO/SC1ZoqWUsox7FGUuYgwo7ec2lOLVwtpFJ8RsvHL5AhvpB4TFF OCNvjZLSI9EZUV3Na1kLO8pfNI3FDMWttdCa/kQ3GUlU4QxY07ayJs+XJYPj0tTKZ7y8 RbPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:dkim-signature; bh=HpinGwuxMTqrT/lGIW6pacs7O2cDdG9/5Ty+RZAfASg=; b=E/vPa2EfmlmtMbObMZrsmOGKY0xe229m3o6ZmjFT7boNUFITFAk9JeP25CNmyCSW+y oON89X7giZthqfSU6oTpGB/3L0IyvDagm2HHicQHFkP8jEbrhVqTx4Ig8yQ2CZpzceMq hQVveXJnJeii8NazfhnW004te/aQtjcti1Ln7Z6hpMorxvuwD7HO3q4BHlZmwvIztsp2 CvbQ4r7TbeeylAy9s7wd3ZFM84KlNSK0pyP1w1gip+LiftFSJOPixQ7JBbCHWFX0igUN wwXG+XC7DDuUABprt7obOEM8we50v5HkFiav1K3gaV7R4DetHX0qhi8I4hUoKJGo4Fvk sbRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="ce/6WmN6"; spf=pass (google.com: domain of 3eus3xqokchqsfvjwqcfndyggydw.ugedafmp-eecnsuc.gjy@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3EUs3XQoKCHQSfVjWqcfndYggYdW.Ugedafmp-eecnSUc.gjY@flex--andreyknvl.bounces.google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from mail-sor-f73.google.com (mail-sor-f73.google.com. [209.85.220.73]) by mx.google.com with SMTPS id h11sor12855966ywb.89.2019.07.23.10.59.45 for (Google Transport Security); Tue, 23 Jul 2019 10:59:45 -0700 (PDT) Received-SPF: pass (google.com: domain of 3eus3xqokchqsfvjwqcfndyggydw.ugedafmp-eecnsuc.gjy@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) client-ip=209.85.220.73; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="ce/6WmN6"; spf=pass (google.com: domain of 3eus3xqokchqsfvjwqcfndyggydw.ugedafmp-eecnsuc.gjy@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3EUs3XQoKCHQSfVjWqcfndYggYdW.Ugedafmp-eecnSUc.gjY@flex--andreyknvl.bounces.google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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=HpinGwuxMTqrT/lGIW6pacs7O2cDdG9/5Ty+RZAfASg=; b=ce/6WmN6TyK+cE8ZhsNWx985tcmb8TsBUG67QVHPvfluZ/ESLePB0+Iu2kpzcDEd4Q YbgyS6kgeVvVFCMr/LAOnm0UHsRKQhmlp8Muf9Haj3921fIO1R3W8RTR8Ay/3UNeJg77 3oj3IZF7aFzplHspAYys2RygkkcmZ5oyq8CPcTBqzS7rp1MfCHQ9R/Uyt21zik3yW2ex viSYi5ZHeqKSa6InOONOnbkuTpjEw9pZIBEPGTBapLOkb92OQ042RHOMLo5PTXbS7p7j huNarTmfeFDbiHSfiNnedUTa6Tx9rh0fc8dZU+mkH0hxVq24fx81n5unKjL7cIn91yBU G6/Q== X-Google-Smtp-Source: APXvYqzHKD7+vuBXgJcq/Tk4Un/3kb/bP9xO8IxzyxfANBAOcEtBJXWYvzpx9hfbGP7jrgSdMTzC7LW89o7yIBsc X-Received: by 2002:a81:7854:: with SMTP id t81mr13003915ywc.2.1563904785456; Tue, 23 Jul 2019 10:59:45 -0700 (PDT) Date: Tue, 23 Jul 2019 19:58:49 +0200 In-Reply-To: Message-Id: <100436d5f8e4349a78f27b0bbb27e4801fcb946b.1563904656.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.22.0.709.g102302147b-goog Subject: [PATCH v19 12/15] media/v4l2-core: untag user pointers in videobuf_dma_contig_user_get 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 , 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 , Andrey Konovalov , Mauro Carvalho Chehab X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP This patch is a part of a series that extends kernel ABI to allow to pass tagged user pointers (with the top byte set to something else other than 0x00) as syscall arguments. videobuf_dma_contig_user_get() uses provided user pointers for vma lookups, which can only by done with untagged pointers. Untag the pointers in this function. Reviewed-by: Khalid Aziz Reviewed-by: Kees Cook Acked-by: Mauro Carvalho Chehab Signed-off-by: Andrey Konovalov --- drivers/media/v4l2-core/videobuf-dma-contig.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/media/v4l2-core/videobuf-dma-contig.c b/drivers/media/v4l2-core/videobuf-dma-contig.c index 76b4ac7b1678..aeb2f497c683 100644 --- a/drivers/media/v4l2-core/videobuf-dma-contig.c +++ b/drivers/media/v4l2-core/videobuf-dma-contig.c @@ -157,6 +157,7 @@ static void videobuf_dma_contig_user_put(struct videobuf_dma_contig_memory *mem) static int videobuf_dma_contig_user_get(struct videobuf_dma_contig_memory *mem, struct videobuf_buffer *vb) { + unsigned long untagged_baddr = untagged_addr(vb->baddr); struct mm_struct *mm = current->mm; struct vm_area_struct *vma; unsigned long prev_pfn, this_pfn; @@ -164,22 +165,22 @@ static int videobuf_dma_contig_user_get(struct videobuf_dma_contig_memory *mem, unsigned int offset; int ret; - offset = vb->baddr & ~PAGE_MASK; + offset = untagged_baddr & ~PAGE_MASK; mem->size = PAGE_ALIGN(vb->size + offset); ret = -EINVAL; down_read(&mm->mmap_sem); - vma = find_vma(mm, vb->baddr); + vma = find_vma(mm, untagged_baddr); if (!vma) goto out_up; - if ((vb->baddr + mem->size) > vma->vm_end) + if ((untagged_baddr + mem->size) > vma->vm_end) goto out_up; pages_done = 0; prev_pfn = 0; /* kill warning */ - user_address = vb->baddr; + user_address = untagged_baddr; while (pages_done < (mem->size >> PAGE_SHIFT)) { ret = follow_pfn(vma, user_address, &this_pfn); From patchwork Tue Jul 23 17:58:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11054903 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6C2DF746 for ; Tue, 23 Jul 2019 17:59:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 595C0286C8 for ; Tue, 23 Jul 2019 17:59:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4CB28286F3; Tue, 23 Jul 2019 17:59:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C036C286C8 for ; Tue, 23 Jul 2019 17:59:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 173BF8E0014; Tue, 23 Jul 2019 13:59:50 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 127678E0002; Tue, 23 Jul 2019 13:59:50 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F0A848E0014; Tue, 23 Jul 2019 13:59:49 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by kanga.kvack.org (Postfix) with ESMTP id C994D8E0002 for ; Tue, 23 Jul 2019 13:59:49 -0400 (EDT) Received: by mail-qk1-f198.google.com with SMTP id n190so37138833qkd.5 for ; Tue, 23 Jul 2019 10:59:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=IHvI+dZahLSsu4iMw8K110v852ALNB6rzz3nOC21G6Y=; b=KEE09a67ocR6DgZyQ/vXOVzh4YjlM1E3f7xdIwLH5mPeiPazEIUf7lnNW6ZyCJAo5+ WtvAXNi9EVRE55Gw+9sTorj9GNuQOcoq3B0+K+Vvjk1hvlNxSJJJiMw13oPLm5hLZ0uS HR/ZoEJ03D3FgZepvigA5ENsyGta0KZjKULOm2LuXcYTQg2MI5nUZPem5VpwPqiXabOS 2HZAJ1g2GUeSCEMS1nbVSGpxBmn8G2S8phd+B9QL+owRFS+klkhQSk08lJa4iMyYgn7Y IrFTqah0tRGQpXdRZIphNBEQfoYb0WrekJbHj6glk8TsSP4ReloyW4trPnsNMAmR9XDq WpGw== X-Gm-Message-State: APjAAAUo/GZeV6ja/s0A7Xu+zkV39sxgwXqRWeYDasTIgpEDV4AKNk9m x084PbUFaxgDf2kVQUYmlzRV4Hncseek4Hbgkbhvs2JfZmxXHjLVs1Q/t05/mlV0xBobUFPBikJ CrruRxYZc4mOTNMGvxyKrQ39l8R0VcHurITiazWGfp26SJEX3ye2GjcDJH/QlOyNHKA== X-Received: by 2002:a0c:d94e:: with SMTP id t14mr53410266qvj.18.1563904789611; Tue, 23 Jul 2019 10:59:49 -0700 (PDT) X-Received: by 2002:a0c:d94e:: with SMTP id t14mr53410255qvj.18.1563904789121; Tue, 23 Jul 2019 10:59:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563904789; cv=none; d=google.com; s=arc-20160816; b=VWUYXd8lm26qh/UlzaR8+gWDrkTf8TYNjjb30iQBbWzNY//vjHGM2lMUf9TO+B/XE0 gTiGkjWOZWv8btWQRbxRJFOfggCH6HF16nk/2+LjXnoE7qAqPyCR/CQhjr40sGdlnN7O 6O0IoydEQeQ7WWgqM/BiDtrCx4r7qjkv1FWCWHSuum47b4PIANV7+WL2Dm44aTio3NQG +6nQkLPC4OqhrLQ0CwUUaYjwrwpy005lVufrSpz6u2Dmn6QN57TZB/pmvV7m3p3vNond Mn/IsLdBtwUyBx7dXOZ/JZoS5/cJ5GQRgQIlFkNvEbBrL6UM6EPFtFqJkj+7ALz4keCL PM/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:dkim-signature; bh=IHvI+dZahLSsu4iMw8K110v852ALNB6rzz3nOC21G6Y=; b=fmjExz0eMOIXGxsgDpho0j/Y6Z/XLLj7/8LJG0cu5+Kfb6sMeT5Q5WBL1FKIi8qPXm mCK3qrAFXuZ8P/iye9D/jmFqRYpWfTST893BySgli8tinqMsqFFW/vSc6gEeO6PwLn2E mdLeXpLEQI+vJyjduufURWc6/hdlXyAWzLPDvTDiZ3Yk4lgmb+skpURN4/KVJE7qKHPL Kbfv0rtHfXBzBXsHgY7MqPDQS3KoOspHHQAGqeAOjCBQmZfemeIsPBuCCuoLUKUWVn6O hdR387ruPYvHDWp5a6RImepqWMWaNpuajbXIL+wohF40ZtbUqxUYGZAbTbKQ8zru6MNu r3KQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=mF8OyWPt; spf=pass (google.com: domain of 3fes3xqokchcviymztfiqgbjjbgz.xjhgdips-hhfqvxf.jmb@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3FEs3XQoKCHcViYmZtfiqgbjjbgZ.Xjhgdips-hhfqVXf.jmb@flex--andreyknvl.bounces.google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from mail-sor-f73.google.com (mail-sor-f73.google.com. [209.85.220.73]) by mx.google.com with SMTPS id h3sor38015305qvc.37.2019.07.23.10.59.49 for (Google Transport Security); Tue, 23 Jul 2019 10:59:49 -0700 (PDT) Received-SPF: pass (google.com: domain of 3fes3xqokchcviymztfiqgbjjbgz.xjhgdips-hhfqvxf.jmb@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) client-ip=209.85.220.73; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=mF8OyWPt; spf=pass (google.com: domain of 3fes3xqokchcviymztfiqgbjjbgz.xjhgdips-hhfqvxf.jmb@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3FEs3XQoKCHcViYmZtfiqgbjjbgZ.Xjhgdips-hhfqVXf.jmb@flex--andreyknvl.bounces.google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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=IHvI+dZahLSsu4iMw8K110v852ALNB6rzz3nOC21G6Y=; b=mF8OyWPtPa27KaGkiSCnss6c8b+Y3jxSBp/iDga+MY7c9cKbX9nGHJwK2xlzSk0dvM 46/b1IA06ke81wJzctvuMT0KvjYlT0hkwU/YFyMD3O3ZkppaxsJ6Qh96lV4fTWRGdGnB ViGf78WRhfhot+50mrRcEJP8ehDMTkQZYjXXgXUH6rOFs4T1KVaDzPVU6ktcbKr8zaRJ i3A/F+iOLc+6M6QJ7QteIj4THksgVZVnbx5C2fEtCjTVS1TOypq05pLtbtct8EtWO8pG Q61f0pOK8VaMaWwFM4favMJo4cb+2j4wmdeEX5CGZBr0ScIwqtpQSHdV7dFwlIUR9Dz4 yLvg== X-Google-Smtp-Source: APXvYqzRyHp7WBTqlPGt29onShJXh3Cp/pE5/lej0P3nE1XW0gw1bUQxpG45N1NN4OdbAYc7oUndTzJUESDpF144 X-Received: by 2002:a0c:ffc5:: with SMTP id h5mr55634338qvv.43.1563904788555; Tue, 23 Jul 2019 10:59:48 -0700 (PDT) Date: Tue, 23 Jul 2019 19:58:50 +0200 In-Reply-To: Message-Id: <4b993f33196b3566ac81285ff8453219e2079b45.1563904656.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.22.0.709.g102302147b-goog Subject: [PATCH v19 13/15] tee/shm: untag user pointers in tee_shm_register 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 , 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 , Andrey Konovalov X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP This patch is a part of a series that extends kernel ABI to allow to pass tagged user pointers (with the top byte set to something else other than 0x00) as syscall arguments. tee_shm_register()->optee_shm_unregister()->check_mem_type() uses provided user pointers for vma lookups (via __check_mem_type()), which can only by done with untagged pointers. Untag user pointers in this function. Reviewed-by: Kees Cook Acked-by: Jens Wiklander Signed-off-by: Andrey Konovalov --- drivers/tee/tee_shm.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/tee/tee_shm.c b/drivers/tee/tee_shm.c index 2da026fd12c9..09ddcd06c715 100644 --- a/drivers/tee/tee_shm.c +++ b/drivers/tee/tee_shm.c @@ -254,6 +254,7 @@ struct tee_shm *tee_shm_register(struct tee_context *ctx, unsigned long addr, shm->teedev = teedev; shm->ctx = ctx; shm->id = -1; + addr = untagged_addr(addr); start = rounddown(addr, PAGE_SIZE); shm->offset = addr - start; shm->size = length; From patchwork Tue Jul 23 17:58:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11054909 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4460114DB for ; Tue, 23 Jul 2019 17:59:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 35EF8286C8 for ; Tue, 23 Jul 2019 17:59:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 291C7286F3; Tue, 23 Jul 2019 17:59:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AF951286E0 for ; Tue, 23 Jul 2019 17:59:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 590E08E0015; Tue, 23 Jul 2019 13:59:53 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 5421A8E0002; Tue, 23 Jul 2019 13:59:53 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 457EC8E0015; Tue, 23 Jul 2019 13:59:53 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by kanga.kvack.org (Postfix) with ESMTP id 24E3A8E0002 for ; Tue, 23 Jul 2019 13:59:53 -0400 (EDT) Received: by mail-qt1-f197.google.com with SMTP id s9so39165614qtn.14 for ; Tue, 23 Jul 2019 10:59:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=bykoKqk+RfxIttYDE7/GdnEkPwV+NEF/LkGgW6aheBM=; b=giMVhOktPHlmh0ouBUgnffuPgL9CGKw1yOKAbGH8XbKdWX9xZhseTR4RZMJHBQR95g ADR5sGgt4HbLNVoSXEsJYtKlBdzOeAqF1qtv9uPt0lUKuoPxLPvKSDitWpx0Y/m1ov27 Y0rWkoGDVjGe32LxYZbonkMKi6lrjz6DSOsuNurCFIZ1uCYU6Vk3PWHaIiDcJVP3FISy spCyVTmErLBZou78VYOeUmYnpNC8sTHMUNrIFwWIYF1rZHv8TBBlKqN8cN2VtK1i+Tly vVB/Zc+F47Sq8rhe21x8ZX/MyQutlNXoGsf8uCX7iW+zPWpigVCqU4fwXu1QdVw0D56f 7gzQ== X-Gm-Message-State: APjAAAXig8UhZZv4ZrvkDMYdg4EPtjN4QgIzucGizmuPk/YXJy94XqSq GwlfdnqG0ttrk8caFZMe13/MAVmdc/GRILp9s2YtKei2amotr0c/hFyCyWJfD/PSFmASgto1DfU izhG+/g1K7Va/3bJA3hbXbZ04clFeNwwuX6Cde+9nweRb9ykL7J5OqpARi+gntTNaPw== X-Received: by 2002:a0c:ae5a:: with SMTP id z26mr54966638qvc.65.1563904792907; Tue, 23 Jul 2019 10:59:52 -0700 (PDT) X-Received: by 2002:a0c:ae5a:: with SMTP id z26mr54966624qvc.65.1563904792278; Tue, 23 Jul 2019 10:59:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563904792; cv=none; d=google.com; s=arc-20160816; b=TydopOLJh5jtCvs1rj7X8oNipfOx/OZSQCy87wnwpTY2Q2FHFFsJQLPQL3WK5MeJHM 2BiGdtvUt/MqQJTp6ybIX6hAtLcYvlnYO85Kr7EkhXUt8oKqyq2warmC5Bxwoc5dUIvI KdZBgZAp7yaZfL90z2npMEWFT/hdT+hLl6zvJd1wiyp7S/84rJKA5YMV7uqmSSYeCTMu xSqquttcF9yg9g1eEavYqrpAQOQwR3Stv6863o4htWKlwGw1XEPDBFxXwL9H4X0DtMPR xCnj/vSC2Fq9Umggf+oVgXJPvm5cjQMn958OPprFgqbKQXVl8y6NCLATzyjZGTy7TPF5 BjAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:dkim-signature; bh=bykoKqk+RfxIttYDE7/GdnEkPwV+NEF/LkGgW6aheBM=; b=QXzp7BME/ngc0z5qpPuPuT0k2h90ltXCY+jYxKyzXN+ZRpGok2MS9K7CRAKjWgX/CO DXaWK0Ahi2k8I9bWS8cwuQeNcjPAJxVAzeBgAQyk6nobHtQmhY6Fn5OgiiwnM8MVYwXC 9dBlkbf4p88jVNSIUejWFYG/z0oKCKLntI1+Ulk6tP1mwxJ37S08ehIxm7eSehIlwXWo rIlQ2BwHWTnmjnQOcqlNnKeyAgz3FPodcvFs/dFCOglUtNqFMSClJabcDl7PXuFlYWFW iYppVWXyBcP68twV2r61UqFXHwLMrGrzT38biYRROKB8OhlRoqdNUc1voo9liSdwwgYR ugqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=t2L6A3co; spf=pass (google.com: domain of 3f0s3xqokchoylbpcwiltjemmejc.amkjglsv-kkityai.mpe@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3F0s3XQoKCHoYlbpcwiltjemmejc.amkjglsv-kkitYai.mpe@flex--andreyknvl.bounces.google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from mail-sor-f73.google.com (mail-sor-f73.google.com. [209.85.220.73]) by mx.google.com with SMTPS id i6sor58164535qtm.38.2019.07.23.10.59.52 for (Google Transport Security); Tue, 23 Jul 2019 10:59:52 -0700 (PDT) Received-SPF: pass (google.com: domain of 3f0s3xqokchoylbpcwiltjemmejc.amkjglsv-kkityai.mpe@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) client-ip=209.85.220.73; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=t2L6A3co; spf=pass (google.com: domain of 3f0s3xqokchoylbpcwiltjemmejc.amkjglsv-kkityai.mpe@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3F0s3XQoKCHoYlbpcwiltjemmejc.amkjglsv-kkitYai.mpe@flex--andreyknvl.bounces.google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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=bykoKqk+RfxIttYDE7/GdnEkPwV+NEF/LkGgW6aheBM=; b=t2L6A3co0IUcO5jJEupAYqmfSwA1Pmfl3+ZcIn/5Q85mp2WLmhw1iqLCswQ9as3aOF a0D+pYMEhkdmm+KSqXmSiU/lD0Pz3h6uvkPAeVEHs1IFoAwnv5BA1YbF3d7nwG6M8iRR Z5NEOhmfG5y3nopQ695DATYQQfXAIYJG7yd7F+lB9VoEza1F669VXhs6jrCa2pvOvN6l r1p+w7pUdDXihW/3CqVYzRnheU9A6fqtUiCr4NASapwor3nhJC+/jeMNYPGIPNIFjoFu E4g9GrA8tUOQtGrCF4JaEQ7hr5aZJYBDV43aYbaG/BPoNEA3mTX8DLrogiBkcDNJOYJ5 rrBA== X-Google-Smtp-Source: APXvYqzy6KvMjkfI7Gkvl5k12zd++ICAyNUe8J8soJHrycJkzCW148ZA79khH20QvBebUrjeGJ/TSw9Gqxxo1fEA X-Received: by 2002:ac8:7251:: with SMTP id l17mr54199388qtp.277.1563904791730; Tue, 23 Jul 2019 10:59:51 -0700 (PDT) Date: Tue, 23 Jul 2019 19:58:51 +0200 In-Reply-To: Message-Id: <87422b4d72116a975896f2b19b00f38acbd28f33.1563904656.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.22.0.709.g102302147b-goog Subject: [PATCH v19 14/15] vfio/type1: untag user pointers in vaddr_get_pfn 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 , 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 , Andrey Konovalov , Eric Auger X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP This patch is a part of a series that extends kernel ABI to allow to pass tagged user pointers (with the top byte set to something else other than 0x00) as syscall arguments. vaddr_get_pfn() uses provided user pointers for vma lookups, which can only by done with untagged pointers. Untag user pointers in this function. Reviewed-by: Eric Auger Reviewed-by: Vincenzo Frascino Reviewed-by: Catalin Marinas Reviewed-by: Kees Cook Signed-off-by: Andrey Konovalov --- drivers/vfio/vfio_iommu_type1.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index 054391f30fa8..67a24b4d0fa4 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -368,6 +368,8 @@ static int vaddr_get_pfn(struct mm_struct *mm, unsigned long vaddr, down_read(&mm->mmap_sem); + vaddr = untagged_addr(vaddr); + vma = find_vma_intersection(mm, vaddr, vaddr + 1); if (vma && vma->vm_flags & VM_PFNMAP) { From patchwork Tue Jul 23 17:58:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11054913 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7F16B746 for ; Tue, 23 Jul 2019 17:59:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7137A286C8 for ; Tue, 23 Jul 2019 17:59:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6548C286F9; Tue, 23 Jul 2019 17:59:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D1D15286C8 for ; Tue, 23 Jul 2019 17:59:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9FD7E8E0016; Tue, 23 Jul 2019 13:59:57 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9ADAC8E0002; Tue, 23 Jul 2019 13:59:57 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 89CBC8E0016; Tue, 23 Jul 2019 13:59:57 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by kanga.kvack.org (Postfix) with ESMTP id 566DF8E0002 for ; Tue, 23 Jul 2019 13:59:57 -0400 (EDT) Received: by mail-pg1-f198.google.com with SMTP id t18so16467484pgu.20 for ; Tue, 23 Jul 2019 10:59:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=jOShWl3tVsknYDB/YoUvrUIV3eQMt6LYV5d/jQUs6fk=; b=qVVkv4i6hBWZGddV8hLms5WpHc9z+5e1nAwdSK7Y5tnK6yPQ/iX26U2kh1RstONwmR in7LLc7162EgJ+qYP8UTMXACwZ03OHP8ZkL2gPIKECIS9GTo+9Oah69VASDyuobSrzvE uZKtBVrKi18rHbCIZozTF5rbGh6WLm4qEBUpew6STYJ0qc5FfNBd/iHh3p52ix6Sd58d o3xD4hd0eFu+C4qvbUa8us48ulRPBnkQq7U2UoPjyBksl1VV49ERE11/mgJ8Bmbo8l8i qdQPk7Zux23BOjICWAtS0xOhPpQO1ePLq938aBza0nBG61S1x3V+BIBhpmGMW1YHgf5T yfEg== X-Gm-Message-State: APjAAAXzYcLE9nFZtXXxtR4cdodkjWW98jyjY4UoNgrQ6emDP0+xXLNN 6+hwdxcevRXizC3QTuNoLLYm5xOlP3gWhCyinBcZmA2+yt+ty5DX3PIw5W1UsZLOVPRrFmUKd0V 9vbZuXnDHKAAH5qH9qUOc/hp7bmK4/Gsn2AzxQ752omQC+Qwx1rLdy+HWnF4q8Dgu+A== X-Received: by 2002:aa7:8a99:: with SMTP id a25mr7068332pfc.127.1563904797026; Tue, 23 Jul 2019 10:59:57 -0700 (PDT) X-Received: by 2002:aa7:8a99:: with SMTP id a25mr7068305pfc.127.1563904796371; Tue, 23 Jul 2019 10:59:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563904796; cv=none; d=google.com; s=arc-20160816; b=YwefM/HTxqnE29CFwp8gqAqAcZws5q0gWX2zinGFu2dQItRY2gaVU3iCmLOep7yRru cDePJoMnDwyCFOyvvSUh2k3/qGBeTqz0o/wpcx8ZJ2bsk8WoqvHHE4G5+492mxZJmQS2 YyLgcsN7URUxU59YNoAJSEvaILPwBSGOCPQWsduai+o+Y6CZlnoxVrCPCdJUfm3xMSX3 1QLWehF2r9rs812mrWoFU7FyW6SyWvFa74b/8kYSxCvD/VNcrVuGIgLcQrg3dwytVQMf ZgHTUlMz95CS3vCu8IrgIRUJF/bCc2j3d9SQupXZwY/rquL9hGslgUbmFIKKAnd2WkG5 K/jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:dkim-signature; bh=jOShWl3tVsknYDB/YoUvrUIV3eQMt6LYV5d/jQUs6fk=; b=qaqJKQfJSkdMsbePitUECZllnDFYxNWqkh1BJSD0apuXSvG1Hna1oOUWfiqpjSgLvx Ofmz1XWtP+VYaoEocp2WCuAO3mKxd9ZKAkNjlFPk8FXNnniV+QurMb+ZAkpv2CGGtepz NV22Po+TNz3W+tHSeOoGAnW07JupsxOj4BdXu8Um8XZPqZ9IkReUsvmXv5PIn/MazCBZ giRdiDDwRSTv0sI8PfELqOIKfuxCWc7OjEKpC5xHsf3eZN3ykZ7a3aqY5/TLSUxdfu6a gNkSv0E/MQ764q4zdyhImvGClthsfGgZneDUWxXvL0HrpEbSWDaygzsU9EBjett/Ojej j0HQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=h3Kq7We2; spf=pass (google.com: domain of 3g0s3xqokch4cpftg0mpxniqqing.eqonkpwz-oomxcem.qti@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3G0s3XQoKCH4cpftg0mpxniqqing.eqonkpwz-oomxcem.qti@flex--andreyknvl.bounces.google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from mail-sor-f73.google.com (mail-sor-f73.google.com. [209.85.220.73]) by mx.google.com with SMTPS id b3sor23660910pgc.45.2019.07.23.10.59.56 for (Google Transport Security); Tue, 23 Jul 2019 10:59:56 -0700 (PDT) Received-SPF: pass (google.com: domain of 3g0s3xqokch4cpftg0mpxniqqing.eqonkpwz-oomxcem.qti@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) client-ip=209.85.220.73; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=h3Kq7We2; spf=pass (google.com: domain of 3g0s3xqokch4cpftg0mpxniqqing.eqonkpwz-oomxcem.qti@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3G0s3XQoKCH4cpftg0mpxniqqing.eqonkpwz-oomxcem.qti@flex--andreyknvl.bounces.google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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=jOShWl3tVsknYDB/YoUvrUIV3eQMt6LYV5d/jQUs6fk=; b=h3Kq7We2lcnT64/ZTs7I4tdBthajlqrQq0s3uG0rcdUUGUvc4KeWtl8Lap+IaEU0xC yYJQXzHFT7D2Jqscee4HDCwPCbx8Wu4vGwr8iHjoxORK9KGqLusafVkNZ/vi+rdiyHeG jdIKwPH4OSoAMEvF/wL6dPzkou8jWXYcRntfsmvla/c6SEeJlZfF2ghZPEbGkeY9ptz1 cvZXKirYuxY3KSRTfpbbshoiYk3G2vA59VITNzPxXSGn8hhh7sloFpM7Eqe6wa8z0eYK HPQ0vNQ1FWKABTpWUeLw9Zvt3IMDsn825fB13HkZ/3l6+zJgRTNpYSRvvg1VGXgpvW9L /8xQ== X-Google-Smtp-Source: APXvYqxAti31RDws7lqydpjpU2QNSIYIBexpp6X7xTgogP1B1IYuH3vnzKrv44nIChFaGEFwrbMkdTHOIZSmLzhz X-Received: by 2002:a65:5a44:: with SMTP id z4mr77715645pgs.41.1563904795339; Tue, 23 Jul 2019 10:59:55 -0700 (PDT) Date: Tue, 23 Jul 2019 19:58:52 +0200 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.22.0.709.g102302147b-goog Subject: [PATCH v19 15/15] selftests, arm64: add a selftest for passing tagged pointers to kernel 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 , 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 , Andrey Konovalov X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP This patch is a part of a series that extends kernel ABI to allow to pass tagged user pointers (with the top byte set to something else other than 0x00) as syscall arguments. This patch adds a simple test, that calls the uname syscall with a tagged user pointer as an argument. Without the kernel accepting tagged user pointers the test fails with EFAULT. Reviewed-by: Catalin Marinas Acked-by: Kees Cook Signed-off-by: Andrey Konovalov --- tools/testing/selftests/arm64/.gitignore | 1 + tools/testing/selftests/arm64/Makefile | 11 +++++++ .../testing/selftests/arm64/run_tags_test.sh | 12 ++++++++ tools/testing/selftests/arm64/tags_test.c | 29 +++++++++++++++++++ 4 files changed, 53 insertions(+) create mode 100644 tools/testing/selftests/arm64/.gitignore create mode 100644 tools/testing/selftests/arm64/Makefile create mode 100755 tools/testing/selftests/arm64/run_tags_test.sh create mode 100644 tools/testing/selftests/arm64/tags_test.c diff --git a/tools/testing/selftests/arm64/.gitignore b/tools/testing/selftests/arm64/.gitignore new file mode 100644 index 000000000000..e8fae8d61ed6 --- /dev/null +++ b/tools/testing/selftests/arm64/.gitignore @@ -0,0 +1 @@ +tags_test diff --git a/tools/testing/selftests/arm64/Makefile b/tools/testing/selftests/arm64/Makefile new file mode 100644 index 000000000000..a61b2e743e99 --- /dev/null +++ b/tools/testing/selftests/arm64/Makefile @@ -0,0 +1,11 @@ +# SPDX-License-Identifier: GPL-2.0 + +# ARCH can be overridden by the user for cross compiling +ARCH ?= $(shell uname -m 2>/dev/null || echo not) + +ifneq (,$(filter $(ARCH),aarch64 arm64)) +TEST_GEN_PROGS := tags_test +TEST_PROGS := run_tags_test.sh +endif + +include ../lib.mk diff --git a/tools/testing/selftests/arm64/run_tags_test.sh b/tools/testing/selftests/arm64/run_tags_test.sh new file mode 100755 index 000000000000..745f11379930 --- /dev/null +++ b/tools/testing/selftests/arm64/run_tags_test.sh @@ -0,0 +1,12 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 + +echo "--------------------" +echo "running tags test" +echo "--------------------" +./tags_test +if [ $? -ne 0 ]; then + echo "[FAIL]" +else + echo "[PASS]" +fi diff --git a/tools/testing/selftests/arm64/tags_test.c b/tools/testing/selftests/arm64/tags_test.c new file mode 100644 index 000000000000..22a1b266e373 --- /dev/null +++ b/tools/testing/selftests/arm64/tags_test.c @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#include +#include +#include + +#define SHIFT_TAG(tag) ((uint64_t)(tag) << 56) +#define SET_TAG(ptr, tag) (((uint64_t)(ptr) & ~SHIFT_TAG(0xff)) | \ + SHIFT_TAG(tag)) + +int main(void) +{ + static int tbi_enabled = 0; + struct utsname *ptr, *tagged_ptr; + int err; + + if (prctl(PR_SET_TAGGED_ADDR_CTRL, PR_TAGGED_ADDR_ENABLE, 0, 0, 0) == 0) + tbi_enabled = 1; + ptr = (struct utsname *)malloc(sizeof(*ptr)); + if (tbi_enabled) + tagged_ptr = (struct utsname *)SET_TAG(ptr, 0x42); + err = uname(tagged_ptr); + free(ptr); + + return err; +}