From patchwork Wed Jun 12 11:43:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10989519 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 BBB2676 for ; Wed, 12 Jun 2019 11:43:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A6F5B2894D for ; Wed, 12 Jun 2019 11:43:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9B03028A2E; Wed, 12 Jun 2019 11:43:43 +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 0E7E02894D for ; Wed, 12 Jun 2019 11:43:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 58B0C6B0005; Wed, 12 Jun 2019 07:43:41 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 53B136B0006; Wed, 12 Jun 2019 07:43:41 -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 428346B0007; Wed, 12 Jun 2019 07:43:41 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by kanga.kvack.org (Postfix) with ESMTP id 25DD26B0005 for ; Wed, 12 Jun 2019 07:43:41 -0400 (EDT) Received: by mail-qk1-f200.google.com with SMTP id c4so13506940qkd.16 for ; Wed, 12 Jun 2019 04:43:41 -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=pF1pY6g9sgHe6SSJdZReBxN/hHHz/1mBqQ4jLohhQOE=; b=O92sUj1DXynG0tVGzcK8yvKPzEKuAfzr76KKJaPxRJrr8/9y0JHbFtwuwenRgP67rt +tu5gDCLkYafntuKXUVnuTDyH1i/Zz4wjDG2GvZdKck2SRSwwNB9XLiK737mIhkNCaQI KUgemlA4WijD++e/OXdfmn36387Lo/RBqRDoT4uI23ddXm30gTbNQuSVRuOs/ntuexem w982AGJCXGGRLmEcHZC+EAd+jMZwEw18O7pYQsHo1G7VxG9gIYfCOOK8ENFPhXHGz0KD PUVMF9glhbUExC6OGDa70Vq5rUZrVIlLJA37i36UEXB1kvcPwXHX2ZMDjJT8s4hkJ6Lw fQ+g== X-Gm-Message-State: APjAAAV/JiO3NI/KbQ2nA8SIAJoryXoQWAOnatK73Cj/ntXlhKEUo5CO Jb/nV6L2n+5dGt3lDbHTshWKyrscpW5xkj40cYbfmYZjaBnt+nluC22k09qKXJX9f0O1WCM9Di/ /JOfRHqgIsxSTkYaalu8OPzOaLI4XRpswggya1AhkCfzViRqfgl95AH5M5rq0ur7VUQ== X-Received: by 2002:a05:620a:403:: with SMTP id 3mr64048088qkp.204.1560339820894; Wed, 12 Jun 2019 04:43:40 -0700 (PDT) X-Received: by 2002:a05:620a:403:: with SMTP id 3mr64048038qkp.204.1560339820295; Wed, 12 Jun 2019 04:43:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560339820; cv=none; d=google.com; s=arc-20160816; b=AGw4pWwJVTvgGJCSR2H9zAm13NlsiYnSAuTCgvmkzRoIiE3Nt5WCQd0mohmfosiaOe 4YXsukiwb5sDPRevVvKniFeN116jRH1ekdgYuw/66kcnai6wxQCBFAU6mp6eOas+IC+A eGdp4Bkil2ydyx9TABgjMWh9XcyDghvRXcajHvCcyCEqgy6tgkQYTC6KiOFssaOgqLRL 7c+GgkUUR/gzsuj2hEOb4v7kV1Zdh555A9x8jw78UU3ByiW4O7SdovvAH1FNSREe47ro Wjr1lLWDnxrh+mweqcO1vr7aLeZ5s1ZwLYcmRcMd17L+V7bvuWzRsGUo2xwjLsbqWMoD THEQ== 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=pF1pY6g9sgHe6SSJdZReBxN/hHHz/1mBqQ4jLohhQOE=; b=Qp9KoFg4l6I+0ZdkpzGwx1Gu/zqSmqnQHSp7BR6mjALBYRSlPobhGupPAxECB5xOVq oW5zKuN/dx9ZBxA0ng9SQXrjkLabqMWRpNyD7bPc2FEIckpspmhOWtd02lJb430XiM4r mVdsbMQakAmAoYqukUlrFXr/2hoRXxzuVo5l1z1tgPZF7dH2ZZ7ueUszTIHd1F+nnWpK TOPeYwnc6Kd2iUT7+wLHwW8i8YnicyxfOqqCpTeEGAG47zAbQeeR+dAYeMO+Us9+7X/N cJkL08vOhzTW1Gbk365G1dl6N+9u68oI2BQR8DnnzQZMRbqRNiGV9jsnZ5d0sAOGX80Y zlZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=iMRCrqRs; spf=pass (google.com: domain of 3a-uaxqokccgerhvicorzpksskpi.gsqpmryb-qqozego.svk@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3a-UAXQoKCCgERHVIcORZPKSSKPI.GSQPMRYb-QQOZEGO.SVK@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 f1sor8984937qkg.90.2019.06.12.04.43.40 for (Google Transport Security); Wed, 12 Jun 2019 04:43:40 -0700 (PDT) Received-SPF: pass (google.com: domain of 3a-uaxqokccgerhvicorzpksskpi.gsqpmryb-qqozego.svk@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=iMRCrqRs; spf=pass (google.com: domain of 3a-uaxqokccgerhvicorzpksskpi.gsqpmryb-qqozego.svk@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3a-UAXQoKCCgERHVIcORZPKSSKPI.GSQPMRYb-QQOZEGO.SVK@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=pF1pY6g9sgHe6SSJdZReBxN/hHHz/1mBqQ4jLohhQOE=; b=iMRCrqRsfaLBvoWwOfr75mSJ/VPfvlbAFbDtrOANqSuL+z1aGCJpTI0vsQBJ49zvkV 9E9fBJ+sa0296EIJ5umEi+BHGLGKU1WldUfLsc5lzjtqovn6xo5wnnj4Lmb0O9PgfLXm rcwLyJjNEekU9EtCutlVconxtA95VHk5TlDWuAVOA+JWDgv52TV4yWWRYEX7ZgqRnURM Eul1F8JBswSLtsZ6lUMRapd1H2weXhkqX5JahODOopa1MhAlxblNV2Op319cxPCbAAUf 9L64VhEstL8JTyQhso+M/6lNjrHhHWa2qS+F7je7+fvMkiPQ8oGbPBPAqN2Cie9HgxaI uOrg== X-Google-Smtp-Source: APXvYqwDKTUvtDmA6SMmQkKz65W969SZufp61k02G9fCL+2/fp67qf94d2M1YkNH+hXtOrCQMRSpsi3TuTa5t/Fk X-Received: by 2002:a37:6b42:: with SMTP id g63mr50597391qkc.80.1560339819968; Wed, 12 Jun 2019 04:43:39 -0700 (PDT) Date: Wed, 12 Jun 2019 13:43:18 +0200 In-Reply-To: Message-Id: <9ed583c1a3acf014987e3aef12249506c1c69146.1560339705.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.22.0.rc2.383.gf4fbbf30c2-goog Subject: [PATCH v17 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 arm64 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: Kees Cook Reviewed-by: Catalin Marinas Signed-off-by: Andrey Konovalov Reviewed-by: Vincenzo Frascino --- 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 e5d5f31c6d36..df729afca0ba 100644 --- a/arch/arm64/include/asm/uaccess.h +++ b/arch/arm64/include/asm/uaccess.h @@ -73,6 +73,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: @@ -226,7 +228,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) @@ -234,10 +237,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 Wed Jun 12 11:43:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10989523 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 757F51708 for ; Wed, 12 Jun 2019 11:43:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 63C532894D for ; Wed, 12 Jun 2019 11:43:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 56AE028A2E; Wed, 12 Jun 2019 11:43: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 D14BA2894D for ; Wed, 12 Jun 2019 11:43:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D78276B0006; Wed, 12 Jun 2019 07:43:44 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D290E6B0007; Wed, 12 Jun 2019 07:43:44 -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 C3FCF6B0008; Wed, 12 Jun 2019 07:43:44 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-oi1-f198.google.com (mail-oi1-f198.google.com [209.85.167.198]) by kanga.kvack.org (Postfix) with ESMTP id 9C95B6B0006 for ; Wed, 12 Jun 2019 07:43:44 -0400 (EDT) Received: by mail-oi1-f198.google.com with SMTP id a198so5313598oii.15 for ; Wed, 12 Jun 2019 04:43:44 -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=UjHW3gvZNVNgT5aLmmsHnPxo+B7J7BC6tuQvc/RhPNk=; b=Yeu79ihtJ6S+NMKopSoQMGX3SiVQZ/x+elIhdlGLD4Y4isaCsL9UGeAfC7Uc2S5VOx uqYHftdUX1DPRXVpcNbZHGhU6nMrBZ4XU/J6YL96cwv8CS2zWDNxI1+lem0xiw7PcxRk 4WXeHTVkw3ELVeXYRAT2ItRLwCthen0lEXvbDC2c34j6gXGvvn8HfA2S3GiVOr1uEqI3 8RGNc7+8qtw6v8eJNGIURfdV4rEgBKChf4Dmyu2SGfEMzngte5XGIOmH5jgTL1uJ9dBW LmpYixPYVnMVKwYAgBlEa696n42QoJHjA3EXwCjHNmnvSajkMRtKKfknSG5rhjILIBUV va9A== X-Gm-Message-State: APjAAAVosTK/hW2jiiyI2CaVBjnx6vfgcAtOHuBTWOdD77JZel4PIhjX A+uRxJ9GaMMYfiqQfgC0aveq48iUO+iRJLwgDYg9WPEo9lV6WVpKDebQTOJLFUq2kkbvubsa0Ng 1z2dbkQ6akeiggKZZh/18nYNji7CralLl5UlmX88lntTJL/WjyMsm3qWWQxvlRGcXPw== X-Received: by 2002:a9d:6385:: with SMTP id w5mr16448223otk.227.1560339824197; Wed, 12 Jun 2019 04:43:44 -0700 (PDT) X-Received: by 2002:a9d:6385:: with SMTP id w5mr16448196otk.227.1560339823506; Wed, 12 Jun 2019 04:43:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560339823; cv=none; d=google.com; s=arc-20160816; b=q1jbG+2U04U5SbQTG9NBjsXwoBKRZ0N4wWdV+tDuxmDeagvJrs6AHao3Ot3cy4lhto mg7pVdZjs1D8VB7/hMX44zcXT2KIAUTFT4jHFuNNmeoF9lrgqgKiRZ6Jc+1bZaHELG5P 5Nq43Z2GBK37WQWv+sy1h/DUGtIv5d7DdQGN+YE/3sj7VoAFuv0k8GfOLKT9p/DC9r74 qXHOubTX1vWER4IhWiDCMQwtIF/UJMATcxbJ60B3a7aVMirCl/zgUd/aNo9o8hFLnD0u Ap5NgN2l91oYDhWksA75OqD0gAjQugYpJ18u+lwvB3N5fp1xc5rIx1psdrsWddJxlBfB PbDw== 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=UjHW3gvZNVNgT5aLmmsHnPxo+B7J7BC6tuQvc/RhPNk=; b=gevAvPpRB21BXQrknQALqNqB+D6LeBUmNyN21rN30aPQMpR4gv3k9J5ZbRYdwtBcHD 3g7po9/CLRJk2BT0iu17gD2b5k2zp1hc5XyzahlBNZ2x7uPUw+BGMDTj6q93wyL8dlZG jtIChTBSY2AKw5Jn1Db9eTOqsRoSDpAS1kj7c4QYjgJnrwt6a/iOBa5hQ6sZ8Agy4k/b c4swaYj8FA4IGjRl7eQQQ+cTpiOCuFpWLYgXsyEqXQjhKjXiGOMLOtFdKaPOq85pn7qr qp8VR/Ib8JQaKmMcpvjDIGCKVBUHImfy9hUCeZMkbls1zMApmudSA93CF176KqIUg9UO LVTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=wWQdCeaE; spf=pass (google.com: domain of 3b-uaxqokccwivlzmgsvdtowwotm.kwutqvcf-uusdiks.wzo@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3b-UAXQoKCCwIVLZMgSVdTOWWOTM.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 a4sor5807055otb.33.2019.06.12.04.43.43 for (Google Transport Security); Wed, 12 Jun 2019 04:43:43 -0700 (PDT) Received-SPF: pass (google.com: domain of 3b-uaxqokccwivlzmgsvdtowwotm.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=wWQdCeaE; spf=pass (google.com: domain of 3b-uaxqokccwivlzmgsvdtowwotm.kwutqvcf-uusdiks.wzo@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3b-UAXQoKCCwIVLZMgSVdTOWWOTM.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=UjHW3gvZNVNgT5aLmmsHnPxo+B7J7BC6tuQvc/RhPNk=; b=wWQdCeaEB2u6K2FokoVH57TiuY9+YM+iloWJZ9olfqp0zjmIdmC5f6DPCzUKmsxGdy S65EVOJIDT5V4zwCQfqNTJzphOcFWfUmY+gXBOeFncv77kXLYdKYGCkdMxc+OyweaWX0 0fKTo4iZRRAvEu0L5K9N5O0E1jscX+Pk92PzQ1PknQ2YOc6xMrIj1RN7n/IEUROoLRHK DSyTNlm/Sr+vicrs5WJhiUx/1nLhQ5Q4ACjS55YPvH7eOOqFTP/CfYXsftMzptdGowR3 ikQ6jhRMQBxQ3FPli1xBTZa23yNKdUvKN2sR5HTTLiPeqs1dY61XYlyLOGrjNBMaj6hd 3iow== X-Google-Smtp-Source: APXvYqwN3f56c3YdzV4vuBZtnTaXMq2rkbV7EZJhl+9vuDir+VdtrZMmSzDSSPuiOLJaxWwDb81r7VAwTgFT1eUN X-Received: by 2002:a9d:764d:: with SMTP id o13mr6499138otl.298.1560339823090; Wed, 12 Jun 2019 04:43:43 -0700 (PDT) Date: Wed, 12 Jun 2019 13:43:19 +0200 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.22.0.rc2.383.gf4fbbf30c2-goog Subject: [PATCH v17 02/15] lib, arm64: untag user pointers in strn*_user From: Andrey Konovalov To: linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-rdma@vger.kernel.org, linux-media@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: Catalin Marinas , Vincenzo Frascino , Will Deacon , Mark Rutland , Andrew Morton , Greg Kroah-Hartman , Kees Cook , Yishai Hadas , Felix Kuehling , Alexander Deucher , Christian Koenig , Mauro Carvalho Chehab , Jens Wiklander , Alex Williamson , Leon Romanovsky , 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 arm64 kernel ABI to allow to pass tagged user pointers (with the top byte set to something else other than 0x00) as syscall arguments. strncpy_from_user and strnlen_user accept user addresses as arguments, and do not go through the same path as copy_from_user and others, so here we need to handle the case of tagged user addresses separately. Untag user pointers passed to these functions. Note, that this patch only temporarily untags the pointers to perform validity checks, but then uses them as is to perform user memory accesses. Reviewed-by: Khalid Aziz Acked-by: Kees Cook Reviewed-by: Catalin Marinas Signed-off-by: Andrey Konovalov Reviewed-by: Vincenzo Frascino --- lib/strncpy_from_user.c | 3 ++- lib/strnlen_user.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c index 023ba9f3b99f..dccb95af6003 100644 --- a/lib/strncpy_from_user.c +++ b/lib/strncpy_from_user.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -108,7 +109,7 @@ long strncpy_from_user(char *dst, const char __user *src, long count) return 0; max_addr = user_addr_max(); - src_addr = (unsigned long)src; + src_addr = (unsigned long)untagged_addr(src); if (likely(src_addr < max_addr)) { unsigned long max = max_addr - src_addr; long retval; diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c index 7f2db3fe311f..28ff554a1be8 100644 --- a/lib/strnlen_user.c +++ b/lib/strnlen_user.c @@ -2,6 +2,7 @@ #include #include #include +#include #include @@ -109,7 +110,7 @@ long strnlen_user(const char __user *str, long count) return 0; max_addr = user_addr_max(); - src_addr = (unsigned long)str; + src_addr = (unsigned long)untagged_addr(str); if (likely(src_addr < max_addr)) { unsigned long max = max_addr - src_addr; long retval; From patchwork Wed Jun 12 11:43:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10989529 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 9EFD076 for ; Wed, 12 Jun 2019 11:43:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C259286C6 for ; Wed, 12 Jun 2019 11:43:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7FF7E28A24; Wed, 12 Jun 2019 11:43:51 +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 5FF6B2894D for ; Wed, 12 Jun 2019 11:43:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0CE616B0007; Wed, 12 Jun 2019 07:43:48 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 07EA76B0008; Wed, 12 Jun 2019 07:43:48 -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 EAEE66B000A; Wed, 12 Jun 2019 07:43:47 -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 C82736B0007 for ; Wed, 12 Jun 2019 07:43:47 -0400 (EDT) Received: by mail-yw1-f70.google.com with SMTP id t203so6530366ywe.7 for ; Wed, 12 Jun 2019 04:43:47 -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=6M/Xbdq/GEdg1U6KS1Q2G6Oz7M7u1wX9lFNSbOIs0eE=; b=gbnQOdNv428VeglZh1dY1Vu14lcVhom/TNCT6ynmk4sKwT41hTPfZeOZhyHUKeicVM GFMbhfuQD2wbEHCqI64eJE36IMYW9OZOqXxBDEdDLC0KbRgCon+zjlh2+DQJe1bcsG3N qQ7S5fs5dBg6DTzJLx/yK8nMiZ0zEWWObLMWikw1jaYS0Ya0m6OJpMAKVZPudZ4z1+Qd KOwhXaGUkdz91OYlJ9FN+hASZ+IGxdXg8jPIirqvKJfEkh2bV2Uz3p6KPVlpqgo1tIN4 twY+WH3hr0wVqtRNXpSatwaG0vDrHooCsJVqB25itYCh1kr+ZXnlnT/lG+QDaa/cYTB7 9Ysw== X-Gm-Message-State: APjAAAXuFmqqSphUYsbHyj7Ltp38nLS2DMc5RlMPAptSNCo3embNDjdn 01cCSipQkEqxGZvflnZ5se6/1jRTWZdmsv5OU2z+jtH2Y45Wqd3vvA4gSJYNkNHPAshko+Ug5wv EDotuLE3lmZ7odj7rTDmwN63cMGRXlRSV9R6XoBr04CPeRStEeKATfB0dnxSyI4PCZQ== X-Received: by 2002:a0d:df41:: with SMTP id i62mr30171407ywe.52.1560339827471; Wed, 12 Jun 2019 04:43:47 -0700 (PDT) X-Received: by 2002:a0d:df41:: with SMTP id i62mr30171380ywe.52.1560339826725; Wed, 12 Jun 2019 04:43:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560339826; cv=none; d=google.com; s=arc-20160816; b=CNJNM1/elERCA9celGeff+2ktFiYxpKnMrOENTbbRKzQqBgV8QL7WZefp2N4lE4xt+ HnIQRkb8DzSlrfGfO43fw1TmGuS37zHkbKYe8TfpBKzkboU+Wv5YE62QRurGP07L6PKE 6v43ic2FRq3d2CudQizpWRD+zFRVi9EFodkKxN5xekANLI6P1GpP4zE0KEUjjoRQnCPd ZwzHUM3fQH5Bga7eTmMwIuAPYjN04WDpxwW8jfM1nElsVD2GR5wGX4rBl58hpnUnq3WA PmO6f0m3viHjigPZ0k/0yb6oaBsQa64pNDLfOoLpDGYnF6NAV36wj7+EuQ9yumVQ7X8P GsaA== 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=6M/Xbdq/GEdg1U6KS1Q2G6Oz7M7u1wX9lFNSbOIs0eE=; b=NCb2HgUDk4yhPz1W9InrkV6VstEc41+Z6/rzMVHCbO/BCLwIjRjZVAIzq7kWfeq4xp ZBug7p7oDFhtn4l+zkzU/VXda+9A8chBZ4gah0EBvEOQuA69OR2YY2wjgq6hiwTlVz84 JbiolgYTgXFL7YPNc8P5lvwKOzTrmtylrFPhIx6xxftwOqTOGeMMqg9PSXudTcFk/yrd NSNppLGyWbhfNgtU9Mmx1p627LL55tIw7/YSriOPcVLDh61NC+xZYjZIEJ/qi5qDGPmC QLyg7dnABSE2opSoBo2BMv13fzdDAK2GO4hvxz0Le0qBR94czwKqblbkDFwUxVCMcEAB Ocfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ACVZLE8q; spf=pass (google.com: domain of 3cuuaxqokcc8lyocpjvygwrzzrwp.nzxwtyfi-xxvglnv.zcr@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3cuUAXQoKCC8LYOcPjVYgWRZZRWP.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 j18sor8105027ywj.23.2019.06.12.04.43.46 for (Google Transport Security); Wed, 12 Jun 2019 04:43:46 -0700 (PDT) Received-SPF: pass (google.com: domain of 3cuuaxqokcc8lyocpjvygwrzzrwp.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=ACVZLE8q; spf=pass (google.com: domain of 3cuuaxqokcc8lyocpjvygwrzzrwp.nzxwtyfi-xxvglnv.zcr@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3cuUAXQoKCC8LYOcPjVYgWRZZRWP.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=6M/Xbdq/GEdg1U6KS1Q2G6Oz7M7u1wX9lFNSbOIs0eE=; b=ACVZLE8qVD2m+0cgtxpWQhGhPGG/Ln68kdWb/oTLWTvjnKjV3OEd+czJBWQA90rzG9 k8pT1WDCWs7sRvQ+L+JDsoJ9EPlF9djBkn8ZvPuT3pIBz18V1FwWApJ56GicLlKJCvSZ l8TgnBTFOKgBUdKjzXAR3WAhJXBBkdOHq+Mn4a5V+670dcUoWBJEFoKWGr/qKzn4y4ZD gjnslGXnEt1rG5J59WQkLbftJMrXLwUl2590vidXXmp5/WyRAn6J6aq6ly4KEqdvnx0u 6w6xsTCBCkTePQK1NsH0i++YzOU+WcrP9IejUTPvS9ZoW0C5f84IOWgLFPwWGXrzJgOj gFOA== X-Google-Smtp-Source: APXvYqytOU+n01l3ivjYwD2cpTD0/nhGfCxB5SZGN1Rdh+wHFGv3wu5KqIwv58r4//qfgSYCsX+M2/Nb4vcejc3q X-Received: by 2002:a81:a491:: with SMTP id b139mr20168814ywh.148.1560339826354; Wed, 12 Jun 2019 04:43:46 -0700 (PDT) Date: Wed, 12 Jun 2019 13:43:20 +0200 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.22.0.rc2.383.gf4fbbf30c2-goog Subject: [PATCH v17 03/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 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(). The PR_SET_TAGGED_ADDR_CTRL will be expanded in the future to handle MTE-specific settings like imprecise vs precise exceptions. Signed-off-by: Catalin Marinas Reviewed-by: Vincenzo Frascino --- arch/arm64/include/asm/processor.h | 6 +++ arch/arm64/include/asm/thread_info.h | 1 + arch/arm64/include/asm/uaccess.h | 3 +- arch/arm64/kernel/process.c | 67 ++++++++++++++++++++++++++++ include/uapi/linux/prctl.h | 5 +++ kernel/sys.c | 16 +++++++ 6 files changed, 97 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/processor.h b/arch/arm64/include/asm/processor.h index fcd0e691b1ea..fee457456aa8 100644 --- a/arch/arm64/include/asm/processor.h +++ b/arch/arm64/include/asm/processor.h @@ -307,6 +307,12 @@ extern void __init minsigstksz_setup(void); /* PR_PAC_RESET_KEYS prctl */ #define PAC_RESET_KEYS(tsk, arg) ptrauth_prctl_reset_keys(tsk, arg) +/* PR_TAGGED_ADDR 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() + /* * For CONFIG_GCC_PLUGIN_STACKLEAK * diff --git a/arch/arm64/include/asm/thread_info.h b/arch/arm64/include/asm/thread_info.h index f1d032be628a..354a31d2b737 100644 --- a/arch/arm64/include/asm/thread_info.h +++ b/arch/arm64/include/asm/thread_info.h @@ -99,6 +99,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 df729afca0ba..995b9ea11a89 100644 --- a/arch/arm64/include/asm/uaccess.h +++ b/arch/arm64/include/asm/uaccess.h @@ -73,7 +73,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); + if (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 3767fb21a5b8..69d0be1fc708 100644 --- a/arch/arm64/kernel/process.c +++ b/arch/arm64/kernel/process.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -323,6 +324,7 @@ void flush_thread(void) fpsimd_flush_thread(); tls_thread_flush(); flush_ptrace_hw_breakpoint(current); + clear_thread_flag(TIF_TAGGED_ADDR); } void release_thread(struct task_struct *dead_task) @@ -552,3 +554,68 @@ void arch_setup_new_exec(void) ptrauth_thread_init_user(current); } + +/* + * 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; + + if (arg & PR_TAGGED_ADDR_ENABLE) + set_thread_flag(TIF_TAGGED_ADDR); + else + clear_thread_flag(TIF_TAGGED_ADDR); + + 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); 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..ec48396b4943 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,16 @@ 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: + if (arg3 || arg4 || arg5) + return -EINVAL; + error = SET_TAGGED_ADDR_CTRL(arg2); + break; + case PR_GET_TAGGED_ADDR_CTRL: + if (arg2 || arg3 || arg4 || arg5) + return -EINVAL; + error = GET_TAGGED_ADDR_CTRL(); + break; default: error = -EINVAL; break; From patchwork Wed Jun 12 11:43:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10989531 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 6584F76 for ; Wed, 12 Jun 2019 11:43:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 515862894D for ; Wed, 12 Jun 2019 11:43:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 451BC28A24; Wed, 12 Jun 2019 11:43:53 +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 911F028A2E for ; Wed, 12 Jun 2019 11:43:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 561F96B0008; Wed, 12 Jun 2019 07:43:51 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 53AAA6B000A; Wed, 12 Jun 2019 07:43:51 -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 450556B000D; Wed, 12 Jun 2019 07:43:51 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yb1-f200.google.com (mail-yb1-f200.google.com [209.85.219.200]) by kanga.kvack.org (Postfix) with ESMTP id 263DC6B0008 for ; Wed, 12 Jun 2019 07:43:51 -0400 (EDT) Received: by mail-yb1-f200.google.com with SMTP id l184so15212312ybl.3 for ; Wed, 12 Jun 2019 04:43:51 -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=9yc1Yq7FenUh0AO3dUlc6AUSMFMskh2/7LbKPot9xGI=; b=I0AGt2mVF2gO7482NpK6ziFp3oKCj27zWKWd07F0wF24v+Rl4Fv1mjqGu7ZkDaz8qJ V7VR/kq3Bk6L160iLZ/nWMcAUGJ2KTsfEdF7c1tsRRepuZ5h3p+1SDV3JXm3a481wYvY cfG9e3l1fgraa2lL66vbI1ccAvj4KueBDncQY+zjleNGUQcHuBuqvzeJgpkxl8IoNDjp gxT9AeW7X4vrDqXexDjgi6YgrDj0awScNET6hnz0znQxW1KJ/Aq54CJWkuDgvK3mpr27 iimrrMEqmvzBCTHS/i2NJLCIaMc5KEZ8IY+8jIRKXryqD/zsfRnztIouwtokzItwQB5k fzXA== X-Gm-Message-State: APjAAAXNoTUFm2cjvqC9zWxtb0vmbLSca07ChYc4IgIP9Ie/wz+yYoBe WPIrP0pndZAO35gBqqKPLbtrHojta+rV8XJsa0dtmR3sPP4wGKIuUMdey/BmNouPsOwpK/Lf/g9 /H96xfUiklTfMScTkJCvVlqfy2VlO4oErRt7ALtzrnJTmZ/FhbZ/+Rn3JE2LsNsPX4Q== X-Received: by 2002:a5b:a8d:: with SMTP id h13mr979836ybq.3.1560339830804; Wed, 12 Jun 2019 04:43:50 -0700 (PDT) X-Received: by 2002:a5b:a8d:: with SMTP id h13mr979815ybq.3.1560339830003; Wed, 12 Jun 2019 04:43:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560339829; cv=none; d=google.com; s=arc-20160816; b=D/KVDomL5fXjz5FRzXQEkfdY1stLz64giOYPo1I6knBhXnREmcaBwtCcPYCM0kh59A ClO3AXl/aDv4ITfPMDmF+KWvuPIKCb3z7dZojTo/YpsXJ1xHBNMevYx2csFzIeghFq61 TDBmbR+TKHijJU0SedTpBME/JGFtyrppZv3AAyQXOEwzEFodgruFtiCna7aQpn2TkqbQ kCX5/zHMQ+84nzFGU3BiE1au/cbdaoOa90KQOgDxHhVmqXowpPwpC6iLqsaUT6fUL5JW FhPTg50yeXVfQl0g8TFCKZb64ad4oVy6NJHOrs8BjTCXenBsWcSOHyR5d0ZD96pkwpbR 4YQQ== 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=9yc1Yq7FenUh0AO3dUlc6AUSMFMskh2/7LbKPot9xGI=; b=KCxPCZ/RNi49dXeAMkXDbjjuIJN9/1FrVxiEAPlZ3Krfj1HvSHHHHX83iJdPfuxazE WPxK6KgKwj8Zpgo/yKUeSi8p30G69RYO5we2qTUQCPaV2wqeQXhEyp5XUwW/bDc7HmiV USQqwuuZyAwcRSPY6gYkT7kgDA86xz+irTc+C3rBOvicw22J+eL7dR9TwgfaAYFrNU12 tAcd7Su1Dyv1+Djwx/wPLMg2fhT4Qg0oTwudAiFWo3ezJ9MwOhS2S1VzOTibwjrYT+S3 rW7Gby4N2Tgmm7LIPZPM0b/X/bFu25HD6uAtTEViD/9rif68pWAv6vMSOUg95xlOc34q 9iYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=jG6r3qKX; spf=pass (google.com: domain of 3deuaxqokcdiobrfsmybjzuccuzs.qcazwbil-aayjoqy.cfu@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3deUAXQoKCDIObRfSmYbjZUccUZS.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 u6sor8023844ywc.162.2019.06.12.04.43.49 for (Google Transport Security); Wed, 12 Jun 2019 04:43:49 -0700 (PDT) Received-SPF: pass (google.com: domain of 3deuaxqokcdiobrfsmybjzuccuzs.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=jG6r3qKX; spf=pass (google.com: domain of 3deuaxqokcdiobrfsmybjzuccuzs.qcazwbil-aayjoqy.cfu@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3deUAXQoKCDIObRfSmYbjZUccUZS.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=9yc1Yq7FenUh0AO3dUlc6AUSMFMskh2/7LbKPot9xGI=; b=jG6r3qKXi5/zKGkjzMFvbQ4XcPl+/QmcSKvFp3utSJtxAUleazRXkJRGwBNNuJ7i7E W7vyyFyjCHej12ys6727AQE+zBEoRn7fuGQ0zPXkT7W8rJNSD33sWm4M+L2uLQ9Yr38G Tk/yJfeEOxvIPA7bqvovIzoag6j0IkNGtc29ARK/7GdZnbkyHKT1QM3wgM9+VOErwGhl DOZEsTVUoN8+b79rOajf7KnGDkH2u/eCR/G6bd5zo2eRqtSAit8bn6BlCrH2lRN5NzMd //lJnKytaH0FthsUWMOhqc1e/AQcdKwVvubR2bol5kkiAS3ABJ/10iV11C/N1mocmKiy lcUQ== X-Google-Smtp-Source: APXvYqzWkT0P+p3RG6pP2xT18iDm8BLgmUWrizOHYeFPCBqdgbB+Dc65X4gpAkgZlAg9PVOXah90gk97CBM2CYKI X-Received: by 2002:a81:2545:: with SMTP id l66mr16760176ywl.489.1560339829646; Wed, 12 Jun 2019 04:43:49 -0700 (PDT) Date: Wed, 12 Jun 2019 13:43:21 +0200 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.22.0.rc2.383.gf4fbbf30c2-goog Subject: [PATCH v17 04/15] mm, arm64: 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 arm64 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: Catalin Marinas Reviewed-by: Kees Cook Signed-off-by: Andrey Konovalov Reviewed-by: Vincenzo Frascino Reviewed-by: Khalid Aziz --- 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 628022e674a7..39b82f8a698f 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 01600d80ae01..78e0a88b2680 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 f2ecc2855a12..d22c45cf36b2 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1616,7 +1616,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 c3f058bd0faf..64c322ed845c 100644 --- a/mm/mincore.c +++ b/mm/mincore.c @@ -249,6 +249,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 080f3b36415b..e82609eaa428 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 Wed Jun 12 11:43:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10989537 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 22BD276 for ; Wed, 12 Jun 2019 11:43:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 105F0286C6 for ; Wed, 12 Jun 2019 11:43:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 03B3528A24; Wed, 12 Jun 2019 11:43:56 +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 7F680286C6 for ; Wed, 12 Jun 2019 11:43:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EB1FE6B000A; Wed, 12 Jun 2019 07:43:53 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E396F6B000D; Wed, 12 Jun 2019 07:43: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 D03C56B000E; Wed, 12 Jun 2019 07:43:53 -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 AEE6D6B000A for ; Wed, 12 Jun 2019 07:43:53 -0400 (EDT) Received: by mail-qk1-f198.google.com with SMTP id w184so13510372qka.15 for ; Wed, 12 Jun 2019 04:43: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=lneYlz8LHaEiU1JdbWuWSlmR06MpCpkboyQbci6TbSY=; b=KKxpMhn3YuukOlp93Iz5UzTlyxDxXYu782Yjy5g7hfburfWy16aNOQshaugXyY3Wki jCoGF9dAAA7aCGufe3AxcVzcBHTJKKqZJ3VPZwOQoEl+cgWV/Lr0Cs6lElJfFbuk2xb3 dt0dAjT9iBfGhVqhJl1tcrXFgtZR2z4tWh7ZV4QAu510SqNIsJX6W/F+Ln+rMNCyQ14V Pc8yImrcVCppW21/WAmYA843zZYFZHqUhx0xFccFF0HSCWllIODXgxaOr19UvubrWxHE cLgE+lIGrGnRog2vUOZpFF2uQDka+U6RMQWmge55/BSzD3jPbOwkLn0EQBfZOo7ryciB ULZw== X-Gm-Message-State: APjAAAXdxVmL4aVU2VqEqmfcn7Gh7VALIJ57DYqA0oimqGXmD1tyKVA4 xVToMbHP+DHSL+gaVPToyg2wCHqjiN7uxzEwMbI+CLzMnSpIndINCfBm4yzwP7oVJNMuPhkGJPB 3j7kbKWSFK2Z1/vx66rycmVWppUDsopuYAlwu0F7k5XXk2oLtn0SsVZYHBsd1ojhrxg== X-Received: by 2002:a37:5d44:: with SMTP id r65mr47491713qkb.221.1560339833497; Wed, 12 Jun 2019 04:43:53 -0700 (PDT) X-Received: by 2002:a37:5d44:: with SMTP id r65mr47491684qkb.221.1560339833002; Wed, 12 Jun 2019 04:43:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560339832; cv=none; d=google.com; s=arc-20160816; b=mLMuAkHReGt0MOC+kJ3mUUBcZWMVJrEJB7TZkT+Da1HpA0qIx43s4Kiazyzocut5kU 2cgEkM2Nx/MkENOWF0gKfmFChAfjrn4TTCgdYCaIjOpf+n1qxDZ+ycSgsROm9lWlmT/1 mvMT9M2J5JguLVJt8Q18S7hdJ8tkcaanQfOY/yhPO2Na5Kr10dCROMGysQ/TwEnC3Rnz yBUZcNZnY6SJ2PwTad6TGtsj/R5Ihm/xEnsOIJBuflHcdLf7cwbJoOU75Wd6uMAQk41x PvNq0u06E7LJlOgq1jje+UKMInEgcKESTZ+S3diWn9osB2mRDmAuGzPfhf+umwtzFoXm YjbQ== 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=lneYlz8LHaEiU1JdbWuWSlmR06MpCpkboyQbci6TbSY=; b=URC/oc1ad6eIy8UOVmiGemOUqNeaZYsrYLGbvW2As9ZtBFbJaLnx2qQLwL3auK0EDQ uAm+KNnKM9BEFv2Uh5F4m7g6RpK9WLhzP5kw2ueKJfhyso2zJZZ3Z0Wk1uJJj3uGApAb bpx+p0ZCzyOMwiZNYmA9W5j4LpetzRnyvLzHadKlsfHPAhztjcGpzlShpVFM6nuKK+Ul sgqpI6KaWHpnhk9CKb+NI4gbgT72MP/WHB6e53rowTJWX12hoZdfzjKjjgOvHdLKob4L r9wNFdnuzCwRX2mQfBekTVNLeFUiSeIj1I3tJT87xM7ajfQldFA8DfZNAMitQSqzEw3r kUdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ZYQEd649; spf=pass (google.com: domain of 3eouaxqokcdureuivpbemcxffxcv.tfdczelo-ddbmrtb.fix@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3eOUAXQoKCDUReUiVpbemcXffXcV.TfdcZelo-ddbmRTb.fiX@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 v203sor6904144qka.50.2019.06.12.04.43.52 for (Google Transport Security); Wed, 12 Jun 2019 04:43:52 -0700 (PDT) Received-SPF: pass (google.com: domain of 3eouaxqokcdureuivpbemcxffxcv.tfdczelo-ddbmrtb.fix@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=ZYQEd649; spf=pass (google.com: domain of 3eouaxqokcdureuivpbemcxffxcv.tfdczelo-ddbmrtb.fix@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3eOUAXQoKCDUReUiVpbemcXffXcV.TfdcZelo-ddbmRTb.fiX@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=lneYlz8LHaEiU1JdbWuWSlmR06MpCpkboyQbci6TbSY=; b=ZYQEd649LLsr0eo67tg5mBkc6yqoxRRkUvXmz72kCnd/9DceAYIH632RHTy/L9FYgN XB0cqiUT3202g16B44AOr6KGjUuUQCuOjjfhX/1rdyfTYvOLIoAOYVJQEyUECaYKw2EI wRT/I+bn5+fj2NWK1Uq2bsCtdk4XPg+CFAKbAVJ1PN2JQI+rUil/RmfEGI1P+fH7HVvB bi61I1IZdPLHbF9O0x6GFnVgN1H+PpiOuX7A6ltMyEW2b4fJxpc44OPAWrBW3bGwUHZL UOaZyEvgJIbhkL4J+WjiYsF7XS5CEf84amjDEh8dkaorHVY5qClgPk6YQHyQ5aqjEpT+ PVjA== X-Google-Smtp-Source: APXvYqycBZ/jgN95w1hvszVcRcdW7P9Dg7ub2DyBfBHGpLBHXa9MwJ+9kmDh7H9YZkcwArOGpwiZYJEXckCXcJ6D X-Received: by 2002:a37:a5d5:: with SMTP id o204mr25506301qke.155.1560339832693; Wed, 12 Jun 2019 04:43:52 -0700 (PDT) Date: Wed, 12 Jun 2019 13:43:22 +0200 In-Reply-To: Message-Id: <8f65548bef8544d49980a92d221b74440d544c1e.1560339705.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.22.0.rc2.383.gf4fbbf30c2-goog Subject: [PATCH v17 05/15] mm, arm64: 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 arm64 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: Kees Cook Reviewed-by: Catalin Marinas Signed-off-by: Andrey Konovalov Reviewed-by: Vincenzo Frascino Reviewed-by: Khalid Aziz --- mm/gup.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mm/gup.c b/mm/gup.c index ddde097cf9e4..c37df3d455a2 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -802,6 +802,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)); /* @@ -964,6 +966,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 Wed Jun 12 11:43:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10989541 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 CE2A31708 for ; Wed, 12 Jun 2019 11:43:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BD79A286C6 for ; Wed, 12 Jun 2019 11:43:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B11DF28A2E; Wed, 12 Jun 2019 11:43: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 7CC0A286C6 for ; Wed, 12 Jun 2019 11:43:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 317CF6B000D; Wed, 12 Jun 2019 07:43:57 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2F0496B000E; Wed, 12 Jun 2019 07:43: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 2069E6B0010; Wed, 12 Jun 2019 07:43:57 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yb1-f197.google.com (mail-yb1-f197.google.com [209.85.219.197]) by kanga.kvack.org (Postfix) with ESMTP id F35596B000D for ; Wed, 12 Jun 2019 07:43:56 -0400 (EDT) Received: by mail-yb1-f197.google.com with SMTP id l3so15212563ybm.18 for ; Wed, 12 Jun 2019 04:43:56 -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=YVD/WVehggR5Wc73HNU/6Lbl/J+rO7t+BXcE3PMRRDE=; b=U7zrI/yy8Zpjm26GR/yDdccmGRYkzIZ9u/us0GGSaGHK5tgIdzWBaj4tsEip1OMvIe hciCkkCuDfSuw9Yar0ETWJfF0fFgCHATlxgrkgYIGJmE8qGmxYwYn2QNa/QndaYV1ID9 4dFMaWgnH5vttL27pePihnK2PM4ld9COVH3B6UnXSbZf0AwzFJOKK8kjQgI/N/DncNOn LCNhlN2KgxgBxOvia3uqvrqvG5s9mj1fwIUyVNPwjUABuJP3SpB/+60w0Go9WZKAcypI eOf+Bbt7+fuHPBNA6a+g5N5zANtns2QnXc1OWvkNAwSfo5jwY4ieoKFaaAN3U735BbY9 xP4Q== X-Gm-Message-State: APjAAAVbDFmaIlLx+B7XCDVDblHTXio4+9hHlGm2tJDQEiingGbGvLDL YfIOzMyGg9OLHd7mzJvnruXh/qKTMlqq3X2LfmM+rrUD5pTE8sSV/rUOSZvB4iNxvrHzy2Ebicv +RDjdTdRqLOoNrBl2XuTbb4Nk8YaMIeN+ZCyIh3hk5N9XbONVdTF3lLWGvzUl2HUAjQ== X-Received: by 2002:a25:3484:: with SMTP id b126mr9802038yba.452.1560339836747; Wed, 12 Jun 2019 04:43:56 -0700 (PDT) X-Received: by 2002:a25:3484:: with SMTP id b126mr9802022yba.452.1560339836240; Wed, 12 Jun 2019 04:43:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560339836; cv=none; d=google.com; s=arc-20160816; b=wd+XSqHA2cbf/v1zYdTwCa7TUQeLUgw72YA1LBSM3ZesXGPaP9PB6M+egRm61NvNUN QHxJYV1jMUDVy/3fbiLbemTfP+vkBH4Ef6gxRFu7Gz5YZA/j0OPZO+fa1yeUSzb/2THL UkGQ0gnUWDKPW2ve0Soxk6W59Ie/dr/JjXehrDQKnLiuh7LrKANZg9iEmBNhmrkhuvLf oy7ivs58cTr3H11NL101vk5812ZbTyNSpq0AUAqtuZhLayI6EraRatO3nthRrypBlwJe a6wTVB+WDgWQtrgaPexcEUeSALSrE/4l3xKZKRmmsqlw4BxGpPP2nQyI/BGTe3q9ICzu Klaw== 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=YVD/WVehggR5Wc73HNU/6Lbl/J+rO7t+BXcE3PMRRDE=; b=EKHJPhheIDK8HiB9lv6Jb5hWApGvOC69AhIBlDF+dFi27Dqw3gggOiYqxNNuVrROkC KoFX8N/MYSh9YUlY6B1csOw6Xm6nZHSmhtaHMbohrm/5NUezAOQRHeLKAugyGzMpmw0x VfKXOel5jOqUnNxD594S1TUl7+q6vjdVGNFjUoDCh+nbXrKKJ6fJDx4PRmpVAYCD+lAn IPJzsVOY+W/RDfilOZSDdzqbDa2D6tI0XAKVS2wI+4C6G43CzzHZDzEc8nVj5glNsEKF psmeSifuCaSOV0x5ZtcQLEDFICeaZCMSCZ9w5v11gWdEcLkRRXIY1g+Sk/zlS8MjxYzK 4+VQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=hBGTTVG6; spf=pass (google.com: domain of 3e-uaxqokcdguhxlysehpfaiiafy.wigfchor-ggepuwe.ila@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3e-UAXQoKCDgUhXlYsehpfaiiafY.Wigfchor-ggepUWe.ila@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 l186sor4871234ywl.166.2019.06.12.04.43.56 for (Google Transport Security); Wed, 12 Jun 2019 04:43:56 -0700 (PDT) Received-SPF: pass (google.com: domain of 3e-uaxqokcdguhxlysehpfaiiafy.wigfchor-ggepuwe.ila@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=hBGTTVG6; spf=pass (google.com: domain of 3e-uaxqokcdguhxlysehpfaiiafy.wigfchor-ggepuwe.ila@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3e-UAXQoKCDgUhXlYsehpfaiiafY.Wigfchor-ggepUWe.ila@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=YVD/WVehggR5Wc73HNU/6Lbl/J+rO7t+BXcE3PMRRDE=; b=hBGTTVG6ghhZ3+0guLELKJ8wGbky2Qh0tZY2BONpI+zCvbTSjhlIF7W0/JokOx5TzR VO5Rbf4FBD1McYuvKbubXsd/VFsD/O7BipMIP18RAMdpnsTMlCRbLlZbiP7oKXwSNsh/ 7N4rlsaJS9M2NXxtFUlEJJPsr6p+or/nlT4Zv12ZmDZup6gUVLdgoPgHeFDcpmGNRrjd 3ALIrSuYojaH/pslqsc0jXMozZhljZkCeYnT4XFg9eFUPMSJzEQdr0RcX9d6uIudOkk2 t4M2C4U//NS1sNKKoHlt+ReZpRZW4iLnE+17ISBaStJwmRniOrfV+Za5ClmC/tGhrMxn H1LA== X-Google-Smtp-Source: APXvYqzC8DIDqxpBDUE3Cs2MqoYPwBYxauFh78Yi9sE2QOVumKFBSV5WM5ycdrw0GZ9JIDvcxx34zgkY7MRSX6GJ X-Received: by 2002:a81:9947:: with SMTP id q68mr46506819ywg.197.1560339835908; Wed, 12 Jun 2019 04:43:55 -0700 (PDT) Date: Wed, 12 Jun 2019 13:43:23 +0200 In-Reply-To: Message-Id: <4c0b9a258e794437a1c6cec97585b4b5bd2d3bba.1560339705.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.22.0.rc2.383.gf4fbbf30c2-goog Subject: [PATCH v17 06/15] mm, arm64: 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 arm64 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. Acked-by: Catalin Marinas Reviewed-by: Kees Cook Signed-off-by: Andrey Konovalov Reviewed-by: Vincenzo Frascino Reviewed-by: Khalid Aziz --- 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 Wed Jun 12 11:43:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10989549 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 712E476 for ; Wed, 12 Jun 2019 11:44:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5E489286C6 for ; Wed, 12 Jun 2019 11:44:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5034228A24; Wed, 12 Jun 2019 11:44:02 +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 C76C2286C6 for ; Wed, 12 Jun 2019 11:44:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 821016B000E; Wed, 12 Jun 2019 07:44:00 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 7F7D26B0010; Wed, 12 Jun 2019 07:44:00 -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 70E7F6B0266; Wed, 12 Jun 2019 07:44:00 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-oi1-f199.google.com (mail-oi1-f199.google.com [209.85.167.199]) by kanga.kvack.org (Postfix) with ESMTP id 4A3276B000E for ; Wed, 12 Jun 2019 07:44:00 -0400 (EDT) Received: by mail-oi1-f199.google.com with SMTP id t198so5310819oih.20 for ; Wed, 12 Jun 2019 04:44:00 -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=Q196Me2jAIDAnTBGiPK/Cxn0vMZ4fncAn8y7f8WRTyA=; b=hkoYYzgJwt6AqBO5wWrHPjszgKOZEmmAqm8H4oQeI1/xaRR5rJyO83s/N0xCC1y1ri JtaLE8rGw87I4w3Kz1P69WcxFDkfxXuIpIHz0VRfQL/zpir6hb0HN1eGPCtcO29fsS0U qYTSFMWvxW/S24Z03AwzWImGQ4G+tIGZeuWjaKAhrf7c7jxCXjOgcAvVAx2PZRTbnlvk qLJf+XD6S5noWrWBe5jh6i5bI3ZFR2Ta0Qw126sp4e2DBSchx90ZfTZMtW6DrK3fkp24 mSYRKVwSGf59G2LCq/CsxoAKZn3gQt6MW4TusjM3E+EPlvsGF4Oke78uKtNWIvqMgGxc /2/A== X-Gm-Message-State: APjAAAXDGAzW0KRX6X0GCyJ/Vjjj9M55ocxBsFLaOaNDVlsG52Dr2Z2G PXgFLBHiT9BNmh1vULmpUg/LK6IxPkbS6vXtY/oWd4VrEttbbXCA94S8ODUzQTL/hU8gpsrjX7Z nlp7z7IEvBKs9JFvTFIliGwNO66ylabipFJc63gJjN8ZngXhRMKVtJNaLEQLVjhClmw== X-Received: by 2002:a05:6830:119:: with SMTP id i25mr175052otp.288.1560339839996; Wed, 12 Jun 2019 04:43:59 -0700 (PDT) X-Received: by 2002:a05:6830:119:: with SMTP id i25mr175025otp.288.1560339839392; Wed, 12 Jun 2019 04:43:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560339839; cv=none; d=google.com; s=arc-20160816; b=w0+SaWLQjOjD39ULcwrxYbNvuz1Wuy0Zri6K3lWQoA4LwLhRzrpMBPSdKalMrvO8cG gpvyjhrn6Xp5uqi2/VLvRZN0mdfofPYdybBpsJNqwdqIa3dxKzsCRdfSiB2cYa9i4zWg G6jvtNmkU0a/RSiQOX17qvawFO08myqk1ge+Sya7LztXY7stYHOp+TJneq/l/tWjf/nq Ha0jq/rluv+Y9y23W6rORXNK+w9BNoRqBiKQNCE7m/GEQecTn1n1aey1gdoqkfUHhLcS k3Zb8bL55WlZWhXsWCcVpQRYlKZSaeEXxmwj3PhU/sQn0uY2bjbhBIudAxD6K8BKx/OT L60A== 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=Q196Me2jAIDAnTBGiPK/Cxn0vMZ4fncAn8y7f8WRTyA=; b=pl3Pr9EWd9Rwp69HByt+ihfEfXIrsR0F/EIb6MLDBiNYK+pDoNUksaRdCy7kdqQtdR 4wqKXKe0m9cy7RZTRf2bjhdAKWG+RdzoK1VnMFNACGYM84Vcp0nSvVJJ2zpnYuA8p508 0b7pa6zCfavS1KZhADS3xN+ld1qmrnT5eZygqi3Bce9j2djm7SfdMufaML1bpqJ1Tv8y zefqwq1IlkTRxxGRuGEqRsa3Sx93zSGf/hkOmlT7KWgTOoe2nFxDmu1MokNemCPnnrvk dUawVcf523dK26/QH/hujsL3kGrZYFhb9qyWlm2xoS1okQ0OsCnBSrQrsCnWvfXUCg+C yC3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=crJJXXAC; spf=pass (google.com: domain of 3fuuaxqokcdsxkaobvhksidlldib.zljifkru-jjhsxzh.lod@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3fuUAXQoKCDsXkaobvhksidlldib.Zljifkru-jjhsXZh.lod@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 o64sor6180408oia.58.2019.06.12.04.43.59 for (Google Transport Security); Wed, 12 Jun 2019 04:43:59 -0700 (PDT) Received-SPF: pass (google.com: domain of 3fuuaxqokcdsxkaobvhksidlldib.zljifkru-jjhsxzh.lod@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=crJJXXAC; spf=pass (google.com: domain of 3fuuaxqokcdsxkaobvhksidlldib.zljifkru-jjhsxzh.lod@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3fuUAXQoKCDsXkaobvhksidlldib.Zljifkru-jjhsXZh.lod@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=Q196Me2jAIDAnTBGiPK/Cxn0vMZ4fncAn8y7f8WRTyA=; b=crJJXXAC2Ku7R2O4W/i46T8MVMbfUT08MJ41XL5/hHP5V9FjHyo0Uen9LNxuGDN5Vy 63AWsHkedb9O9JWDh7PX7+icF3+aQrjNm9LMqOxXKSXvWvA1aCADx8vQJIjHIcqFjNdS lYpx+uRnlnGYhTQ2lQa8QHdE77x+n4mpr2sUjGrEPZ8RUtGTjRZ6moY6dJvWWn+KRbsY dQnCJW3fkugzHDg7Z7YzCoAOi+mpWJRQPWYBzTyBpPkH9NOLOyHd9BCpw34BLqWhA4XL 4AfxwDFDvKPDrbAnUzBzbdpr67Rfah4zZpcEFIF5+I68PhpwUQ4ynpp9B2e02i2b/LFy ttKg== X-Google-Smtp-Source: APXvYqzBV++HnsJqGVA3TkWLFAlh+OLmBH/rJ20EXP8gbe+qklBNVVp+IuIonV1uuXEIF8K1ppBAgAEKJRpWB8lr X-Received: by 2002:aca:6c6:: with SMTP id 189mr17818209oig.167.1560339838959; Wed, 12 Jun 2019 04:43:58 -0700 (PDT) Date: Wed, 12 Jun 2019 13:43:24 +0200 In-Reply-To: Message-Id: <4ed871e14cc265a519c6ba8660a1827844371791.1560339705.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.22.0.rc2.383.gf4fbbf30c2-goog Subject: [PATCH v17 07/15] fs, arm64: 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 arm64 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: Kees Cook Reviewed-by: Catalin Marinas Signed-off-by: Andrey Konovalov Reviewed-by: Vincenzo Frascino Reviewed-by: Khalid Aziz --- fs/namespace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/namespace.c b/fs/namespace.c index b26778bdc236..2e85712a19ed 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -2993,7 +2993,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 Wed Jun 12 11:43:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10989551 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 C1B7B76 for ; Wed, 12 Jun 2019 11:44:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AE9AC286C6 for ; Wed, 12 Jun 2019 11:44:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A135F28A24; Wed, 12 Jun 2019 11:44:05 +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 13C5B286C6 for ; Wed, 12 Jun 2019 11:44:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9A7EC6B0010; Wed, 12 Jun 2019 07:44:03 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 97F0A6B0266; Wed, 12 Jun 2019 07:44:03 -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 86CA56B0269; Wed, 12 Jun 2019 07:44:03 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-vs1-f71.google.com (mail-vs1-f71.google.com [209.85.217.71]) by kanga.kvack.org (Postfix) with ESMTP id 646BA6B0010 for ; Wed, 12 Jun 2019 07:44:03 -0400 (EDT) Received: by mail-vs1-f71.google.com with SMTP id r17so1924524vsl.12 for ; Wed, 12 Jun 2019 04:44:03 -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=0pRrtQh1WGSItgbOKTKHJXYw3ig9cf9ovTOOwQBNCxo=; b=lEWWsJLu5wV12rUH0ZmzrvJCxf897y4VLbn4X/Mn2ybY4kgOxxFO7JdXQwbrPuPEMc VfmW8/gqcMwS7RcBWy6/r1Z4qY32LbmsOktjxbrSpc8I5DufXTmwyi4JK6iEnESBsYid zoLSf2ahSkQ11SFPnA9QuTvUsNv5RJVNQAaYFLA/fo9I6emc4ki/OnM/w2cWVSwJ7ZDU +SbAr7mQjgVZnAbc7LtwFXHGj57trNHz7lmoaOBodtN4MjLHhsGKQoFKuIdf1Ah2YCIR AG4GdwQlf2poNV5C4qN3shVVHEJYaAMUriyGPhzWhckqseryNik7/vZNaJ72AaDJrvwH Ri1g== X-Gm-Message-State: APjAAAWqc8ANKXU0XwyYKNlcekrr4qCIACAed68GsT0cDWYHYRzVaGL1 E9BqKhZDaJfxpQkl96HjW2c6Neg7HFNHFB/8lFY+7iR5ZevJ2rCvre+ZzNIYslCJYLbadnS8KMv lhGW4CFKIKzhkWAPoyMUvjNEMjIJkl0nN8uv92XfgRuCDReMn8+s0p/gEBand/g3k6w== X-Received: by 2002:a67:63c2:: with SMTP id x185mr45006053vsb.166.1560339842986; Wed, 12 Jun 2019 04:44:02 -0700 (PDT) X-Received: by 2002:a67:63c2:: with SMTP id x185mr45006029vsb.166.1560339842439; Wed, 12 Jun 2019 04:44:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560339842; cv=none; d=google.com; s=arc-20160816; b=y9ll2+ySEnxgGTAgtYGohgz2G3xVRaxUan4KTk2uodtDpKYPTTX8Rg8PwaYp2wHY1z 2pi+3+mL2TkpfNoNDhPVg+dVEgnqycB8o4AI63aUZEKSAVF2gySa//cf7mp7i0VIn/m0 djkIOpSlNKUiH1mzLV78RpnMU6D4hH6lVi93NyfbMcm5VKk0Aq2ugbzDMWob4xhcC2QC H8lyQJsbsE5izi7C6+UZDGKgHvpE9180v1FPNu01v4gysuYiZP8/v5CVfMvd/yL8FpmO pDnJ/dOZXAKdMaEZaaP8Zcx99g6xOhJ5ozQ/3arBn2hjpmyQMnXyxlUGnX/kkUtI2R1B yNPg== 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=0pRrtQh1WGSItgbOKTKHJXYw3ig9cf9ovTOOwQBNCxo=; b=qqFziYhmFv1EXKYWy+Ov4hGOW/ZgOWu264gBoEifpXxWzmiS287sYmShSlHDj38yiR HNffYerkALehn3nfgLUlWu9udhkI/TPm0UMAK2u/M06v2wR6kTrnjHTDKyKq8LbcmW3M lFrgRV4psTTxZvww8ANKRlXWIwBXHDeXC0m4qLNRxVo2OyZ+MfZbVaLImT9wKy5Re2sU SIyPirR9yKC4eRLacFdsW5qQhxBL9IUmf4E4FrQh7CpYMEUnun29jxh1Bk2K+dHkMZ3G PgVsFqAsMPqB4B3SdAUcpX3t2ojRT4uO9648jo2txp9lMLq7GkAHTgvUYr4UwiPzFMfM gJtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=IoAMjSO8; spf=pass (google.com: domain of 3guuaxqokcd8boesfzlowmhpphmf.dpnmjovy-nnlwbdl.psh@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3guUAXQoKCD8boesfzlowmhpphmf.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 h15sor7072807uac.44.2019.06.12.04.44.02 for (Google Transport Security); Wed, 12 Jun 2019 04:44:02 -0700 (PDT) Received-SPF: pass (google.com: domain of 3guuaxqokcd8boesfzlowmhpphmf.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=IoAMjSO8; spf=pass (google.com: domain of 3guuaxqokcd8boesfzlowmhpphmf.dpnmjovy-nnlwbdl.psh@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3guUAXQoKCD8boesfzlowmhpphmf.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=0pRrtQh1WGSItgbOKTKHJXYw3ig9cf9ovTOOwQBNCxo=; b=IoAMjSO8LpV9sQ4rhyGuwSi9qAWnWdJKm92qjIFlDfIzZK27lRdtbBpUTTqSsHKQqq mk4pY6s02uPltexkWHMnxfPS6E14WpHQTBtMuXD5ciPLmKwQYfFZ7D/irHKINjpULcIC qesPb2LJHGU1U+hg3Lnr8sbHR2PLa6XJRSA+MwutfJ1QD1fm8gchvdk4JFKcehQpLj7U rwlJqHzorntg7c/BDSuoHH78gq9KnzX7dlAs2pxjWc6C1dDkPCqTKTM+gMG73nj/ByrG HBTS6w/3UTjUct6MrDb5Sf2LP5/PYv9l52cM1MNahSes/06CDdeCzTIAFl18VFOFWLlP HuBg== X-Google-Smtp-Source: APXvYqyhjQEo4g9YND5Fe8F9dcUypnQYf8jfozQHANwshchy+6+kG6ludLuigCmoO08U0FojfDlhn98Rsb9Khi5b X-Received: by 2002:a9f:25e9:: with SMTP id 96mr28666032uaf.95.1560339842024; Wed, 12 Jun 2019 04:44:02 -0700 (PDT) Date: Wed, 12 Jun 2019 13:43:25 +0200 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.22.0.rc2.383.gf4fbbf30c2-goog Subject: [PATCH v17 08/15] userfaultfd, arm64: 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 arm64 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: Catalin Marinas Reviewed-by: Kees Cook Signed-off-by: Andrey Konovalov Reviewed-by: Vincenzo Frascino --- fs/userfaultfd.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index 3b30301c90ec..24d68c3b5ee2 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -1263,21 +1263,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; } @@ -1327,7 +1329,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; @@ -1516,7 +1518,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; @@ -1667,7 +1669,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; @@ -1707,7 +1709,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; /* @@ -1763,7 +1765,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 Wed Jun 12 11:43:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10989555 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 080B614C0 for ; Wed, 12 Jun 2019 11:44:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E92B9286C6 for ; Wed, 12 Jun 2019 11:44:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DD0DF28A24; Wed, 12 Jun 2019 11:44:08 +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 3ECE3286C6 for ; Wed, 12 Jun 2019 11:44:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 934816B0266; Wed, 12 Jun 2019 07:44:06 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 8E2906B0269; Wed, 12 Jun 2019 07:44:06 -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 7D2766B026A; Wed, 12 Jun 2019 07:44:06 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yw1-f72.google.com (mail-yw1-f72.google.com [209.85.161.72]) by kanga.kvack.org (Postfix) with ESMTP id 58EAC6B0266 for ; Wed, 12 Jun 2019 07:44:06 -0400 (EDT) Received: by mail-yw1-f72.google.com with SMTP id b75so17010219ywh.8 for ; Wed, 12 Jun 2019 04:44:06 -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=49lyybNUomf5TPPaYx2MdHbLNYXxhntLqw2Vq4fwp4Q=; b=Yt+PzfYo8qSZud0DwxwmvkR5vwfm2ZRrfl7r/j5VGEdTBLt70NohEN4FRrY9U/hQIe Wlom9oISWHJ98qsznl0bZSR1X/eDvaYx5CeU8PuxsDls+TNvknsFu3v/wQk+CsXc64+M lPfJ4/nQSxtRTfoxwKlJzZZv6ud0LV7812uTJwnPY+2B6bYC0V7yu7M9nKDi2UsRQmhK FTQwvBDJBD9pseGeF7mAgRjgwsItGR96vNoUggHNLFB8nmiZYBBcGOCbewuDpFzbMoIw qd8KATzDaRNLJC6akQAZFHEWRnASTEkmZPH03gCMxRsYmhEgv9URiOwYvbMvXf+noJSs 30Fg== X-Gm-Message-State: APjAAAVzp74JMAKKMuBuhrWLPwm/Bv1hwMHiHqNX23SObS94sh/4Yk78 0fXdMhY413vW/M6Yn2lxZ+jqYUoX08So/054Su6Zid6zQinNhzcfvZWNMno0Pb8sGh6V8rkp4TR AOYWpzQ3q3mqS7mV0ZWkkfcHjhaCIv8Y7XLbdTc7rGkz7Ts70DEsGAn2crGkDTQS6Ug== X-Received: by 2002:a81:aa50:: with SMTP id z16mr22626597ywk.278.1560339846010; Wed, 12 Jun 2019 04:44:06 -0700 (PDT) X-Received: by 2002:a81:aa50:: with SMTP id z16mr22626580ywk.278.1560339845448; Wed, 12 Jun 2019 04:44:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560339845; cv=none; d=google.com; s=arc-20160816; b=dLrDv1GJTRB4JpNNFWMEBVn+WRgeXDj/qbfBtlcT60jAY2v7VkSTgqj4ZwXPrq8pHT 1QDJNHp9PeYV5O/JziGgH7dm4sXfLAiZDbjXGr5m8efUXSPeWcX6IrLJNUG4WH0lOT0s ySOZQznZZ9Z2g16BBl+YccdBIYiLZVXEjGfO7XQR7sB3d+SIFPJS9MLopq4FYEe9/fod Qz2WnG6JtUZaiR9oUVyb95YdELANEMN/9dGmW9iObygLDnaViVl1uxgN3AHpzuulqVTF p+4dlmmsgd4SixtFP+Q+9gAgEPk9fqUAGdvGwFTLADK1dTTdzSUnUUebSgs0/xRxTMeH yiDw== 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=49lyybNUomf5TPPaYx2MdHbLNYXxhntLqw2Vq4fwp4Q=; b=LF4fHXRp/vxQ0CT5r6Yc072OLuYtYqd4swmteEXcaUpuWvAD6cFUO2sJkIgIArgQSi 6Ru4IFvLxNMg0Hpm5QATjHIhBQlKt9vI4uFiunCy/h9tXf6UKhGXzHBFQ1PtskYvvCMV bpqCttOvFNBkAom/XwRb4JQZHoDrHE0R/XSLFSSKxWfY4d7FZ8d1ECPKYeau5WUfBdRf 1aOLhcnLoyTvASwoeZX8xE3tBPU2n7ILw0wArmkIb7waVfHpp1xNEid/rkGdgzzMyYna 5Z0NatKVWkyX5Zu4GnRNuEL2mRbMLEpOFVotZtPHY9yDzJMJcdPrqP5hPVWAuO+SB2xd zw1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ihFwqktA; spf=pass (google.com: domain of 3heuaxqokceierhvi2orzpksskpi.gsqpmry1-qqozego.svk@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3heUAXQoKCEIerhvi2orzpksskpi.gsqpmry1-qqozego.svk@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 r124sor8203830ywg.55.2019.06.12.04.44.05 for (Google Transport Security); Wed, 12 Jun 2019 04:44:05 -0700 (PDT) Received-SPF: pass (google.com: domain of 3heuaxqokceierhvi2orzpksskpi.gsqpmry1-qqozego.svk@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=ihFwqktA; spf=pass (google.com: domain of 3heuaxqokceierhvi2orzpksskpi.gsqpmry1-qqozego.svk@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3heUAXQoKCEIerhvi2orzpksskpi.gsqpmry1-qqozego.svk@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=49lyybNUomf5TPPaYx2MdHbLNYXxhntLqw2Vq4fwp4Q=; b=ihFwqktAIqrJiTQwTjUhK+MAdfOsiouWKHqO7ZjSSZRmzOCHa96d8VJOaNVIZNxAcO AN6aXPp/RE1MrQ6zM8JJXD7nVRwFFfp5nOw9hthmPYYo49089cBtVFaOKAL5CUs7PfyJ QVJHzuksJxoSuikR4fgviWI+uxOP0qQaG3AiODD2sa8fpyWPMeWsTelFk8q9IMn10OKD +UNh5Ci6TXkOO1z7q/a2BisVOKAv5AoSV7//DSqtdeKoVvYLLBYkbZ3uB0cH3pp+Kewb rQGpoPMvtpdogBshUOOc5uWdI95iNZkAb+XnamPk3rh+8KJ/cKljnQO2b6iriftiFlMR wRJQ== X-Google-Smtp-Source: APXvYqxF+/T3yPkem3l6CI+bv3/rmqxcJMbV/vABJbuoyeQcWj2Unps+PKPx2+cODkSgswAOZakXvU9OwOpzOWtl X-Received: by 2002:a81:2717:: with SMTP id n23mr31165867ywn.423.1560339845094; Wed, 12 Jun 2019 04:44:05 -0700 (PDT) Date: Wed, 12 Jun 2019 13:43:26 +0200 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.22.0.rc2.383.gf4fbbf30c2-goog Subject: [PATCH v17 09/15] drm/amdgpu, arm64: 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 arm64 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. 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 a6e5184d436c..5d476e9bbc43 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c @@ -1108,7 +1108,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) { domain = AMDGPU_GEM_DOMAIN_GTT; alloc_domain = AMDGPU_GEM_DOMAIN_CPU; diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c index d4fcf5475464..e91df1407618 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c @@ -287,6 +287,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 Wed Jun 12 11:43:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10989557 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 0A63476 for ; Wed, 12 Jun 2019 11:44:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EB5F8286C6 for ; Wed, 12 Jun 2019 11:44:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DD29428A24; Wed, 12 Jun 2019 11:44: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 9D76B286C6 for ; Wed, 12 Jun 2019 11:44:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 143976B0269; Wed, 12 Jun 2019 07:44:10 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 11C796B026A; Wed, 12 Jun 2019 07:44: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 009226B026B; Wed, 12 Jun 2019 07:44:09 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ot1-f69.google.com (mail-ot1-f69.google.com [209.85.210.69]) by kanga.kvack.org (Postfix) with ESMTP id CD6146B0269 for ; Wed, 12 Jun 2019 07:44:09 -0400 (EDT) Received: by mail-ot1-f69.google.com with SMTP id a17so7599335otd.19 for ; Wed, 12 Jun 2019 04:44:09 -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=9qcG2BgTwk3XlX0RcWVeDPHI8lhK5DjmwRDy1FE/sPA=; b=Rqftxi4i96rlDJEDje1cx6btg7fg9/A2wxYcLSa7QH3WzDELLUGd1vlJGhLer+fz+L 8q3dz49PaoYS48Kv3/UdEMY9IjeR4dl6GXKEKxMlMHXtWH4ng0OkN/PzOm3v+zk6AaX8 5Ekgw8Qv6lT6PJew9Et0/En431VuSkhQ7gC/msI/BIrzkD4BrsrkOko0mawRrQC+cNjx MEU46fLCHXsoBr0EDac+qS5lMCb6swe1Ht4uFlXf66yaS/ww/TBFbluR5uSsRYTWp+mi qhD1un4RPPHPFzKqL8j7GkunwvKDSnFj8QZwyD1fewCXhFRbdudsWeBvEhWE8Cour0gm 5Elg== X-Gm-Message-State: APjAAAXa8PcZ22pOZsVoUs1Yz7mkFdntAIAlPdv6xvfA7LG9vF49fxO6 Yndd1KSpYZ2tauc7K39nOU/bbqm7SPPy9U1v+b0C1sOUHxxDJCZzydc1KqUNNAQKBi7IEHsHQRE iKznU9ggGqfzKYRbFqIhX2OwbHdfGYCacuJiPmUDu4pCD4Iry7vOodQjWGRY+6Zl4IA== X-Received: by 2002:a9d:d22:: with SMTP id 31mr21918802oti.304.1560339849468; Wed, 12 Jun 2019 04:44:09 -0700 (PDT) X-Received: by 2002:a9d:d22:: with SMTP id 31mr21918764oti.304.1560339848661; Wed, 12 Jun 2019 04:44:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560339848; cv=none; d=google.com; s=arc-20160816; b=TvVmdRh9+CjxMrDc0QrXFmuI+QhERILBeKNm1ZI9QrOKY9Hq1OyOBjVRecJnQUhhlz g9MmjX5ePAjEWX6cSE0lvBmbfQ8T4lxk4qG9QM/Ku5QveumQz7xpGYahrB0YiP2ZA63L J1wpppIGL7h1QGOjCNFoob21T1VknTUh2IASfkFDvOfyR3jwfKPUufbrTJY9dn8jiXam Zv+FwOTCN5rzJDCeWUZqgln9BJ+xYpmwCExd9jZmBJlkhJMqqbsd4DvzN1ugZv9ONAog Vzv0LiDQnX8tiG+FgwdzglsozFXuJImrf3E7Mhljyd2jMcTGFW1yF3qMzO/+TQHxMjRJ Un3A== 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=9qcG2BgTwk3XlX0RcWVeDPHI8lhK5DjmwRDy1FE/sPA=; b=pxQYq6AAbPuMMNYJLMo12gwwuLfQWc59LZRKuliUHLpMh00ImLTbEXTVHrzhEQ0uJr egq6azWL1WVKQlvkCVYvSffhRe/iN7fz7cBugFpGtDPwmOBug1LhKMz+Y22VtE/lfc1F 3UR5iDfoDA6Jys7fb/4its19wvXMKsZ18MqohsVo7sV8Nup+hJ/hc34EwPLZof3rE+fR mWnpJfJBswT7UjzSVa3JGqaBe7nC5Aw/Qz/wrOycU6vb/vG/oKQiTCuaj9wXW5Gex7qx bG/Rcn9axxBV0h7Ae49gx5oVzBfoyYvF6vZuSY+sS+bp78xZHPEvCaatNoQCEztZ708k eAOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=NtLJcSSF; spf=pass (google.com: domain of 3iouaxqokceuhukyl5ru2snvvnsl.jvtspu14-ttr2hjr.vyn@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3iOUAXQoKCEUhukyl5ru2snvvnsl.jvtspu14-ttr2hjr.vyn@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 f25sor7462940oti.138.2019.06.12.04.44.08 for (Google Transport Security); Wed, 12 Jun 2019 04:44:08 -0700 (PDT) Received-SPF: pass (google.com: domain of 3iouaxqokceuhukyl5ru2snvvnsl.jvtspu14-ttr2hjr.vyn@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=NtLJcSSF; spf=pass (google.com: domain of 3iouaxqokceuhukyl5ru2snvvnsl.jvtspu14-ttr2hjr.vyn@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3iOUAXQoKCEUhukyl5ru2snvvnsl.jvtspu14-ttr2hjr.vyn@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=9qcG2BgTwk3XlX0RcWVeDPHI8lhK5DjmwRDy1FE/sPA=; b=NtLJcSSFMHHu317AevzAQ/30ZKEUOStp0YqobtwksbYseFWqgtaBTFdiHMGyyyf7At YDJhLaCkyHoSzl2vKPQ0kqczt1dgoIP6M4Ipn73b/OGJITm9/nwiI3El0EdSAptKyxy3 b89x7f/UmAMLYhahbGWtvHAEQvqe/KEbHnD9FTBIwA/5CD9mYyTGMXM5MGTE55QAL6sy I3ZLX4P7OcoVJPIKw9PZDhGTJmKOWHMHOrsjABMEwlErwDLgIe9+iGkSdgcah0pP/nqE b30uAgSnuW/RhTjVNWI3Kw8grpBZAvIwRQ2tzxM9A7fFKVadA2sdBJN3nJtOltKf1dPe uUMA== X-Google-Smtp-Source: APXvYqwmn5LtjaTY+f4hsmtZfAoqdCdKYyyJ3TA1JpFnaOV6Nu/BG+R38vnyWSwcum180MP3Ic/YmQmm8bwHU1r3 X-Received: by 2002:a05:6830:119:: with SMTP id i25mr175410otp.288.1560339848209; Wed, 12 Jun 2019 04:44:08 -0700 (PDT) Date: Wed, 12 Jun 2019 13:43:27 +0200 In-Reply-To: Message-Id: <9ba6199f01b8e941404b18bf8f7079ff384fb60b.1560339705.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.22.0.rc2.383.gf4fbbf30c2-goog Subject: [PATCH v17 10/15] drm/radeon, arm64: 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 arm64 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(). 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 44617dec8183..90eb78fb5eb2 100644 --- a/drivers/gpu/drm/radeon/radeon_gem.c +++ b/drivers/gpu/drm/radeon/radeon_gem.c @@ -291,6 +291,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 Wed Jun 12 11:43:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10989563 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 59D5776 for ; Wed, 12 Jun 2019 11:44:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4841A286C6 for ; Wed, 12 Jun 2019 11:44:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3BA0228A2E; Wed, 12 Jun 2019 11:44:15 +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 BAD5D286C6 for ; Wed, 12 Jun 2019 11:44:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D2D176B026A; Wed, 12 Jun 2019 07:44:12 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D00696B026B; Wed, 12 Jun 2019 07:44:12 -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 BC9D06B026C; Wed, 12 Jun 2019 07:44:12 -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 9E4B46B026A for ; Wed, 12 Jun 2019 07:44:12 -0400 (EDT) Received: by mail-qt1-f200.google.com with SMTP id q26so14485416qtr.3 for ; Wed, 12 Jun 2019 04:44:12 -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=eb4SnUCHaoFPTU0EqMrx7H6L5ANcvzM3zwsiyq0FV40=; b=aaokBjGaSM4PUx//olVbzhTkuNXgnhM/7YUSKia82wTNEUihdUzzNu152pKsRj2LCn MUhU4vk9A8RaitHzBHgNYAakOmv0DlpQdDzeSfy7TTqgdjbNSxuBNh0TpULHDHg7h0EB kWtCmmk7F1PxZH15OPRtqKxFO3c9Wk64VwFQtjn2PVmIzsmT27nx2FXvCI7Ni1QkEeNC DWRlqZdK8MWUc2dUsBgjjsqCoFodMyb/bDZOxeIxlCfqukxILkyuYtHOG15yR9JwiO83 4dAjqeHvc7uh3PZ9TEDoCKWEb16LuFKf8EJYVfAFyvWkEGRNNZPXwqYu7Mx1kHRBQ7TE lj4Q== X-Gm-Message-State: APjAAAXTdNqQtIJYXBisylszHVpOoPtHmQujbm+QarEIdyV+3mCCq3bf fshKGsqoTwqRjQJCZv3kadhNkbFv3SCIKchNvlxMQN6Gaa7n6os6bA+R0KlDwLan48mVIyqFgD6 Kbz1+TSK7tzGVKL7LC63TZGLugVz4m3xfOt33kp/XbOPj0gAvjRoTHyrMB9pwh3FkTg== X-Received: by 2002:a05:620a:12ef:: with SMTP id f15mr21611833qkl.340.1560339852429; Wed, 12 Jun 2019 04:44:12 -0700 (PDT) X-Received: by 2002:a05:620a:12ef:: with SMTP id f15mr21611798qkl.340.1560339851932; Wed, 12 Jun 2019 04:44:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560339851; cv=none; d=google.com; s=arc-20160816; b=lzhl6H8JjArd0sn7TBITtX2XFRSdV73Iuvrov/9kVs1wXKY9J8VyrzoBUufA+/Rl8K xsXcy+VrkyVnOLUAgiPaPAkqfryDYDX4V9eNG4EqGPmAdkuokyj6rgXsHvceeZJlV3h4 dJpbBd077FnEhi6050PD/AnX8Dsf66eJKIusNUbNzTnag4D0sR0K/+E7gtBDGSwYRtyy cbTGAhcW11u4mgAHn4iONseZHbgHHy2MFlmYVP2ow8EWM4g0gsUQ3SH7xPTZc9jWsQxS MR+xLj9TktJLcqGno1soG9gHp47Z9aiei9XJXNr9tZLUfbV1XuM63ETuif/jsgXaTGIk RsYw== 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=eb4SnUCHaoFPTU0EqMrx7H6L5ANcvzM3zwsiyq0FV40=; b=jUeoooE1T/FxdP75O95hmVqp6LQ6KckGD/+VSl6SMVnCDqucRAyexrPIsrk/UEla0z /DpvpRaXPWkUWWL7QuM5d948LVMiNo7YpMVOW3mXj0sASKDoHVFZBJEe3UYClDeJe8lK CGJi5n0Ss0s8XOPUmSagrWdsQ7tZC5v91pdaIqzPP6WjhidFXfURx23cKJDYysL1Fm5S lZtrOZPPbbmvc37W8+e193ZcvxF4QqK3qLJMaPyXr5HxsChPUtylzwLB4uyS/a6RBnvT GdJV2B3+OofPZsrsjk8csbmAKIMcgHQse7phAzFY/Q1KLQlDx6YKQalkzRuCbg3ECNFJ g39w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=UD79Ay48; spf=pass (google.com: domain of 3i-uaxqokcegkxn1o8ux5vqyyqvo.mywvsx47-wwu5kmu.y1q@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3i-UAXQoKCEgkxn1o8ux5vqyyqvo.mywvsx47-wwu5kmu.y1q@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 v83sor9203215qkb.100.2019.06.12.04.44.11 for (Google Transport Security); Wed, 12 Jun 2019 04:44:11 -0700 (PDT) Received-SPF: pass (google.com: domain of 3i-uaxqokcegkxn1o8ux5vqyyqvo.mywvsx47-wwu5kmu.y1q@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=UD79Ay48; spf=pass (google.com: domain of 3i-uaxqokcegkxn1o8ux5vqyyqvo.mywvsx47-wwu5kmu.y1q@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3i-UAXQoKCEgkxn1o8ux5vqyyqvo.mywvsx47-wwu5kmu.y1q@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=eb4SnUCHaoFPTU0EqMrx7H6L5ANcvzM3zwsiyq0FV40=; b=UD79Ay48r+Qt/fUB4eQQS+u7jB3BFWRYtdLCt6Qa95VfLfmvvw7Hya/RkyTUwkhx0D +1vmB8M4RBQZbJNIhwkYxv5AEL21ErrNvQCQ8+lOs4BCA4LMOTjJTuV8BlTNIfNEsvvi S8RTYx74gNWKftQMTjEJ+kHo6ZnD8masl8ZG8ezS9xy8uaiMn8te593VaiscKSGKojp2 e5Cc4FqtUoN3q8YTe+OydLtjYtDNOm5Wm5t/bbuGQhbg9sf44AZgifS6zPiIE4WlbsCF 2CX+HbBHE4vO/HCGylKIpSsIsXiK8frsZe8Lb15lkTfFpYP5OsKznhL91S0FrbJQy23X yoqw== X-Google-Smtp-Source: APXvYqziQbsGJB+s1a1ziaRcl+e8Gmo6MzSM6gFLtwRxsTnl2K0xyr2RS7DkrrH2w0nPz/f56zeYNt9ix1U3jsHZ X-Received: by 2002:ae9:f107:: with SMTP id k7mr2472892qkg.215.1560339851579; Wed, 12 Jun 2019 04:44:11 -0700 (PDT) Date: Wed, 12 Jun 2019 13:43:28 +0200 In-Reply-To: Message-Id: <50293fea168d5252f79ee0bf160c64c72edbf270.1560339705.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.22.0.rc2.383.gf4fbbf30c2-goog Subject: [PATCH v17 11/15] IB/mlx4, arm64: 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 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 arm64 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. 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 355205a28544..13d9f917f249 100644 --- a/drivers/infiniband/hw/mlx4/mr.c +++ b/drivers/infiniband/hw/mlx4/mr.c @@ -378,6 +378,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); @@ -386,9 +387,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 Wed Jun 12 11:43:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10989569 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 BADD014C0 for ; Wed, 12 Jun 2019 11:44:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A2BD82894D for ; Wed, 12 Jun 2019 11:44:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9190728A24; Wed, 12 Jun 2019 11:44:18 +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 1AD55286C6 for ; Wed, 12 Jun 2019 11:44:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3B4356B026B; Wed, 12 Jun 2019 07:44:16 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 363C76B026C; Wed, 12 Jun 2019 07:44:16 -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 27BB16B026D; Wed, 12 Jun 2019 07:44:16 -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 045F66B026B for ; Wed, 12 Jun 2019 07:44:16 -0400 (EDT) Received: by mail-yw1-f70.google.com with SMTP id y205so16943726ywy.19 for ; Wed, 12 Jun 2019 04:44:16 -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=OMWTVS19S/O2L7wjAg8YO34JfVmTuzDlFYDWpvnlfdc=; b=T9Wy11RcJ5MaYUY6udvxX/37pdKEW+fna/Am6BV1l46uu2VCXy171+5dZmK/jA0yez OLMr0loUiYxXvfflGYTmJiv2lzA+5qwj51HOAKkQqhqcnGaYfpqV8Fps68kQqpSMUBIt vhT6+ACslzdqc4X7ZtUmjYvQR6v4gaXrPY7yx4H1jLVWYQXPRs9tM0D3p3KWxQDPE1hx xSX7G7XLH1bN/wKczeD2p1OBZJfjQ7SjNL340xUzv7rFx9sp04vZetAAuQBmrPqmkQS0 7n349sAB/WTfw7oFoRC64s/7VcJcTudwU4f0zbC5gmAQVAmrI0A+up+XJvVMUnQ1mxJ+ keOg== X-Gm-Message-State: APjAAAXAzs7b8bGNXUOaiG+PnwRCL7n7khUy14IfUZWWTD1isYzft7tL QJy+1dNQBpVHfN/xD098aHxgNqEbVfz0nDr1/5mwVWUt5tnc5ggFbeXyKLGpD/oBOcwOWvWd58h 33K2EVOxmNVVOm/d5d1V87/0osFuWu517x1XGdnH7xuUvKqUT2y+NgYCyOddq/5cRBQ== X-Received: by 2002:a25:d4c5:: with SMTP id m188mr39154078ybf.60.1560339855763; Wed, 12 Jun 2019 04:44:15 -0700 (PDT) X-Received: by 2002:a25:d4c5:: with SMTP id m188mr39154048ybf.60.1560339855090; Wed, 12 Jun 2019 04:44:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560339855; cv=none; d=google.com; s=arc-20160816; b=N7XC8aoRVTuFo+vb5LDxNAiuly+QNnTRw6zPCeWlMN5MNKL25Z+eGB54aelXgd85Vk 14Gr+L7mq2XHaPblmFxQ4sWhnl9qra7ybnomcW4iRpqXp3zEP2WANYv15nWs9U7J8XoK NSCmwYStwEbLhZU9IDgaJo5NLn3zwYVFcbGZ20as/YsCVhzIYPXBxwnigtjOEVFPsDc2 acCwRX3fIYD4AHf27MDqtBVap82SGDwUJ3vdL/jPjDahHp1CF3HtzxUAD/hbIRaCwUuP COwzMjU2Se+QzBs0oqnaYySow3sevfjhnjbCV1RIsZ74YBAEgdZY8l+Z+GuS5cG4Dbfr kXKg== 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=OMWTVS19S/O2L7wjAg8YO34JfVmTuzDlFYDWpvnlfdc=; b=dSVPdLDsH0f5P3V1Y3KmiKLA8EHeAYJyXXwh4r8/7VSrH9Kq+ssEWXJ+U6T0yEwOSm vQmRLnQRgOcRlkGdRNk0JEsetwAq/P0w42vweAfazTTSIUpi8RUKqUKfqUDFA7pH94oI sem/lO/67s/5rDXmOse4PoWTJ9JwO2z/XOB8f4LqxOh+CZUJca1r7xATqn0NphgTxywq jD6S+vEj1TRqSbnXEWrZA/u1JCpYVE5UuI7Hz730E9MamAAkyhdGq+TxvMZ4BoefroM+ d4lB+GB/NO0pxUdSX+ueW46mk/Jb/AXiNuPoSouYltWDEOxAXPB/OBRL+UlkkoVclZWl YJ7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="l/pAL0pY"; spf=pass (google.com: domain of 3juuaxqokcesn0q4rbx08yt11tyr.p1zyv07a-zzx8npx.14t@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3juUAXQoKCEsn0q4rBx08yt11tyr.p1zyv07A-zzx8npx.14t@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 k63sor8086281ybb.163.2019.06.12.04.44.15 for (Google Transport Security); Wed, 12 Jun 2019 04:44:15 -0700 (PDT) Received-SPF: pass (google.com: domain of 3juuaxqokcesn0q4rbx08yt11tyr.p1zyv07a-zzx8npx.14t@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="l/pAL0pY"; spf=pass (google.com: domain of 3juuaxqokcesn0q4rbx08yt11tyr.p1zyv07a-zzx8npx.14t@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3juUAXQoKCEsn0q4rBx08yt11tyr.p1zyv07A-zzx8npx.14t@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=OMWTVS19S/O2L7wjAg8YO34JfVmTuzDlFYDWpvnlfdc=; b=l/pAL0pYNwxIjhI4A5Di3+u8zRy7KDPlydIoJClA3OuILFZkNAGW7KJJpakHJKu6oE BOdwx+v3Y6mB0EaDg1WhpBGkC44sbC2cWM9OPunZvHIIMbKjR7+B/dGr9AjLsLmz2Olt nLMYnF0Wzf15zXWsTdJBm9qmaTa4PXWly/FRd7uizPU6BFseaNjpN6LtFlJq58pOQv7T WsZKhldlre+UFCD7WiBxmS6BBO31lObcc7zusnLdA80L2jwrzKGvI3ypNGCThs2lIqG6 VybQ3v2ZWx5KHhiRN49MNNAagP8G3S94nC+koOMwbLACD7/N8Wf3tprbj1wNC/YGyAaz DFPw== X-Google-Smtp-Source: APXvYqwTs0S91VLJ1vEb2xUG3SN6RjfUTygp4K8Hjte1QQ8AktyAJh0LJ+M6BJ5qwoi87JfKLCpvnOyNNEEmSEtd X-Received: by 2002:a25:aab0:: with SMTP id t45mr38754945ybi.201.1560339854764; Wed, 12 Jun 2019 04:44:14 -0700 (PDT) Date: Wed, 12 Jun 2019 13:43:29 +0200 In-Reply-To: Message-Id: <7fbcdbe16a2bd99e92eb4541248469738d89a122.1560339705.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.22.0.rc2.383.gf4fbbf30c2-goog Subject: [PATCH v17 12/15] media/v4l2-core, arm64: 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 arm64 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: Kees Cook Acked-by: Mauro Carvalho Chehab Signed-off-by: Andrey Konovalov Reviewed-by: Khalid Aziz --- 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 e1bf50df4c70..8a1ddd146b17 100644 --- a/drivers/media/v4l2-core/videobuf-dma-contig.c +++ b/drivers/media/v4l2-core/videobuf-dma-contig.c @@ -160,6 +160,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; @@ -167,22 +168,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 Wed Jun 12 11:43:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10989581 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 9754976 for ; Wed, 12 Jun 2019 11:44:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 841F7286C6 for ; Wed, 12 Jun 2019 11:44:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7712E28A24; Wed, 12 Jun 2019 11:44:23 +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 9A5EB286C6 for ; Wed, 12 Jun 2019 11:44:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0F4796B026C; Wed, 12 Jun 2019 07:44:19 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 0CC816B026D; Wed, 12 Jun 2019 07:44:19 -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 F247F6B026E; Wed, 12 Jun 2019 07:44:18 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by kanga.kvack.org (Postfix) with ESMTP id D19E86B026C for ; Wed, 12 Jun 2019 07:44:18 -0400 (EDT) Received: by mail-qk1-f199.google.com with SMTP id j128so5490332qkd.23 for ; Wed, 12 Jun 2019 04:44:18 -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=Tg03Gniv02ZbxFz4TR6ORKJ5z+YRDkk6YMGCeNMzVJA=; b=PRPHs7IZBOcUahFv2xcpHoR1YX4NPGK+BaaejAEgU06pzRaAaoqX+WDb5dbG1mBejR fgnZy3hwokDflaK60hpvEeXg+D+1iFiGeWnZN3pnhB8WauOB5km/bVMpMUef/ags/RQm G4ts5l3ty1fFXXNwEtgFoqRcPxeD73oQm3BAo5ehdQeI2mC2Hh3G50W2CiT+TLsJK9k8 hijz0CIBTEWLXge4wnpnFid8M/lPtlvGd1/LXlxHijOWY8hYyhxm8OX410gRB8OFWN6q EtPkDsnUBKj0ueZppQx9TsrrQtpzZwEvcx8qluOmVPh3jyTsUAdkv5rkFA9UGh2QC9LU zBRQ== X-Gm-Message-State: APjAAAVm6lgsCls78uUd8jVO7s15ZhYhF7d+uJs+Hi4pqgn13n1swSsr nHuhceidDqMxNC2sTgJmv0N+1j6UT1TmAtJ/t8qRx9afkJ1IEkDQcGD/ukjhNXbJNythN2CwFv3 8V4cptWWlueztO/4sIYxVKLrmTqxbR9K0FLBgMN5un1dUEAAucv2C7807cNRp4YAryw== X-Received: by 2002:a37:e40a:: with SMTP id y10mr8480297qkf.303.1560339858638; Wed, 12 Jun 2019 04:44:18 -0700 (PDT) X-Received: by 2002:a37:e40a:: with SMTP id y10mr8480244qkf.303.1560339858046; Wed, 12 Jun 2019 04:44:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560339858; cv=none; d=google.com; s=arc-20160816; b=q0AhIo0kjptyxzNh9j0azvqm5sfFJW2hdQlny1DzpgHvqSvx/ZOlnVQ6qE9w/WxRgf 0JBbw6994mwMrasYJtnrgXg2bA3ayODJJVcCbiGu8mJHIGU89K3N1wv6FZ2jtuxxdj// 7iVam91U6OP85O6czVLjGCtA/KpoR6eY+ursOIQJYmH+b97eKbUgNcGDi2znu4SnugB0 cZXYZ7lVT8vFZmt3DSO5QB9EBT/r4qh/6VWjrI7do1ZgHD0Ilnip2ziqt0QZVesTrbpY XirCoKfWf3DuMycnmT4R9F4slm/e/C7mP51U00R5pSVmkne/Cde2rVbBlh1/pkkHmCKD ltAw== 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=Tg03Gniv02ZbxFz4TR6ORKJ5z+YRDkk6YMGCeNMzVJA=; b=xSmVnNtMRwf1B0MscC5Ofhrm0biMLwnvohsfje+4fjIN2Sc3GOn3hu2wVbJRxH4R8x X50SF0xYfbqut0qXSUa9QEO39dr4CbVbHG+IP05aHR3A9IN0Ak49+orUHl7aAHz7xik5 QnY2ADbS0kO5YCYgzGUdGobJp9RM/rGCYQDsno6uEV4ZqAqjAiEcwUFwd/KXqE93t2/O wmPZLeCkK8jM7JynYNAwz4MPCuSUh7NfIOM6YeU/173URqw4lpj6HBzKIguPbqTPbBLn x4WkEiv6/UNLore9yC6nFzHL5VsAqHsl6o2O+TsS07CKUEiuIEl6Bit5ZrTGKiHf+Wsl ndgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="SFF/l4UF"; spf=pass (google.com: domain of 3keuaxqokce4q3t7ue03b1w44w1u.s421y3ad-220bqs0.47w@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3keUAXQoKCE4q3t7uE03B1w44w1u.s421y3AD-220Bqs0.47w@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 g28sor21481810qtb.3.2019.06.12.04.44.18 for (Google Transport Security); Wed, 12 Jun 2019 04:44:18 -0700 (PDT) Received-SPF: pass (google.com: domain of 3keuaxqokce4q3t7ue03b1w44w1u.s421y3ad-220bqs0.47w@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="SFF/l4UF"; spf=pass (google.com: domain of 3keuaxqokce4q3t7ue03b1w44w1u.s421y3ad-220bqs0.47w@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3keUAXQoKCE4q3t7uE03B1w44w1u.s421y3AD-220Bqs0.47w@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=Tg03Gniv02ZbxFz4TR6ORKJ5z+YRDkk6YMGCeNMzVJA=; b=SFF/l4UFcejexpzLF8WLlQfmQ26wur6/Lp5UaETnaEcEawlk3l/6lGLaUMMooAgs8s H8BXtM8Po2kTy/ERZiKnsQjpEuZwCfivxhd6SyQ7RL+iB0sQfj/clPfIeMIPz6uKVDLv xUHwWlMKGfxD6gcgGhDGYlQ/8FvPYT93r6i2RnedCW6E6xVhUJOencUb8rKP9J6i4iHL r+rptZFaLXc6jhn3wSb4NX5Q2zQt78sd6zAnhaXM0vfZ1qtib0qyN9SWZBmopO4jCPUZ R6Ny3CDz7f0jULr5eWdVbsgq1nlATw+QzZpUThV+z5VYuwsEypjY/9FNseoLEmXCwIbk +Rew== X-Google-Smtp-Source: APXvYqyCeVb0C2VnUmKvZl/NXpmzEb8PXfZVfFDAeRPGCnyVezO7o0ITR/pw5X1cgaGDH/zdBw+sIaHhGO7/u0mq X-Received: by 2002:ac8:5485:: with SMTP id h5mr67932284qtq.253.1560339857730; Wed, 12 Jun 2019 04:44:17 -0700 (PDT) Date: Wed, 12 Jun 2019 13:43:30 +0200 In-Reply-To: Message-Id: <9d68d9e7f9f89900adb4cb58c34ffe532dfb964a.1560339705.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.22.0.rc2.383.gf4fbbf30c2-goog Subject: [PATCH v17 13/15] tee/shm, arm64: 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 arm64 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 Wed Jun 12 11:43:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10989587 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 0B7A114C0 for ; Wed, 12 Jun 2019 11:44:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ED505286C6 for ; Wed, 12 Jun 2019 11:44:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E000A28A24; Wed, 12 Jun 2019 11:44: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 B90C9286C6 for ; Wed, 12 Jun 2019 11:44:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2F0EB6B026D; Wed, 12 Jun 2019 07:44:22 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2C8B16B026E; Wed, 12 Jun 2019 07:44:22 -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 1E0EA6B026F; Wed, 12 Jun 2019 07:44:22 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by kanga.kvack.org (Postfix) with ESMTP id E728E6B026D for ; Wed, 12 Jun 2019 07:44:21 -0400 (EDT) Received: by mail-qk1-f199.google.com with SMTP id v80so13531069qkb.19 for ; Wed, 12 Jun 2019 04:44:21 -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=dC40GuuRrFkQnjrApJXQmFxRiKKrkesKJBcqRTZL8Hw=; b=BESYZ+BpxULbs7EXGtRZkNu/ntqeedNLHIxVAzT5Xj2DbEc+tbmr93mn6nkv61Dvwc FKaGehpwERzinmAgoYid8nudb9C95Y9MZHSXYXkrUBac0r5lo+dRHOiin7c0zKWDg9FZ H8gtw2M9Zg+IwWldlOI7StSoHyEjPx8J0YgBqotJ0NRc9LyPS/gFr2K6u6h+C7/G1CuR Yp7XF0OA1k2J0zKMFmhTW5hWgqZrVDxsy6fIibIn3v3qtVIYc7mN2aNI6yYjsgHjlJik 15J733troBX2f6Yom3xJ9EKcxKOgc6+0Z8ZACKPtQyDVap6IIFhSeRCJax4w16ZOiMPc LWfw== X-Gm-Message-State: APjAAAVa9nJzVgCINz62yJ8GSA+DuHZIKTTOm+1Jly1/pAMCbXBbq6vp itreLnWsmQxhxcDOZwrAokZ3EmzDHqSwt8ML1ZrzL+oRaN0WpDKsrgQZCZ5UKPYeFaM+oqGgRtD QVV7vCfWB13a9NvCQLueBriOZ4L28mBOKyVtJcynNjYcGgJJcThvuqXdBhp+XGQhFwQ== X-Received: by 2002:ac8:2e14:: with SMTP id r20mr11753826qta.241.1560339861734; Wed, 12 Jun 2019 04:44:21 -0700 (PDT) X-Received: by 2002:ac8:2e14:: with SMTP id r20mr11753790qta.241.1560339861172; Wed, 12 Jun 2019 04:44:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560339861; cv=none; d=google.com; s=arc-20160816; b=X/CFLaOx20s+XK1XRB9kKq1e7x9L3thBbpPafVbtCXzbmruMfT7PXBcO2slsAVcjwV OFS4ULmSRxpAeYU7dQQIPBd4yZakn9A5AgZPGcMlsF4H8giPYDufJdC9SSUhXFp+ZVKQ 1OqlB9cNl9idIcdv1T7JAZvcUdzt7jHDgimPrZKxC4V/ZzuWdem98X7hc/ELSOi5N+IB TO1UDfjbbPjbMKrHBByQ7hzSdFSQcIwWZMTZq4RWdPOb7Z1a9L07cTRAWf7VNrj+B2SN 4848urjGbw0QY5WII9XSDkWn9cYumaAoaUjHPk8vWrfmbCikprKv/M84pblVGLRIYQV1 J3xA== 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=dC40GuuRrFkQnjrApJXQmFxRiKKrkesKJBcqRTZL8Hw=; b=s8wxemWA+JKfCmExZrkxxTXAeJbgGmBvPZp3NGAubX/MamobhsPprenJ9xSjSh3JCj GhpoOSUPTw9M6OcB4g+Yf8SFywrDZvEhLk2PlF9FyhYV9RmMnhkv24UxlTrJ98SeSusd abCMdgnS3cWqme35aFf2VqaQXr5+lMsgqzL+m7uGxNT7V7onD7W8YO29y5c9pVt4Sc/W 1d7YK/ceB8koS1//iFdWP+xjz2KjrcpwsXJbqfE/i4yEkP1GxtSNEJIynFsFq/4dEy3N EUVUrARiXmk8AhnO2obUKZfUg5JhB4D5Uh1OIWIP0g6RIhRuuJpDdaOm1tJ2RTTJTHu1 EKAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=l++ZaaCo; spf=pass (google.com: domain of 3louaxqokcfet6waxh36e4z77z4x.v75416dg-553etv3.7az@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3lOUAXQoKCFEt6wAxH36E4z77z4x.v75416DG-553Etv3.7Az@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 d20sor21739073qta.29.2019.06.12.04.44.21 for (Google Transport Security); Wed, 12 Jun 2019 04:44:21 -0700 (PDT) Received-SPF: pass (google.com: domain of 3louaxqokcfet6waxh36e4z77z4x.v75416dg-553etv3.7az@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=l++ZaaCo; spf=pass (google.com: domain of 3louaxqokcfet6waxh36e4z77z4x.v75416dg-553etv3.7az@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3lOUAXQoKCFEt6wAxH36E4z77z4x.v75416DG-553Etv3.7Az@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=dC40GuuRrFkQnjrApJXQmFxRiKKrkesKJBcqRTZL8Hw=; b=l++ZaaCoh/Va878Z1RknZZDdHUxfk157JnrRAUHz0jkL8fnv4FiiLmIp7Mk+/+dj5Z udFWoFOVhW7criNi8EMt8LBSnQaHvMhhUZ7BDvFNW7/H/rP4O9cpUiWmbFdx7WqJb0YL NYshnqAqHIeJqfZE1jL/Or9LTpuDIXYOfI1A2lvZRf82GFgwU4vOl8q53aA7Al9b8vAL /40xfjd6Br1Z56pIH7ZQuk9+yAf8Fr4GxAKL+l48BRvqpFH3utDdPvwMyQ57y2D4Zbcd AbEKWCBEQKFZuNPc6Vhcbi8LrlZtqOM5E/akcRiPUbRsuxCCoPgb7uahyTdqK4vvCrOk BhgQ== X-Google-Smtp-Source: APXvYqwZjeFH8QvU8JlQ9TXNVd73FVhiQa5kjrzjuBPKvVuXz62UTyjAI0ty22a00jJqk9SVHlzrZWd7SRmSPg0y X-Received: by 2002:ac8:30c4:: with SMTP id w4mr67672128qta.314.1560339860763; Wed, 12 Jun 2019 04:44:20 -0700 (PDT) Date: Wed, 12 Jun 2019 13:43:31 +0200 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.22.0.rc2.383.gf4fbbf30c2-goog Subject: [PATCH v17 14/15] vfio/type1, arm64: 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 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 arm64 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: Catalin Marinas Reviewed-by: Kees Cook Signed-off-by: Andrey Konovalov Reviewed-by: Vincenzo Frascino Reviewed-by: Eric Auger --- 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 3ddc375e7063..528e39a1c2dd 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -384,6 +384,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 Wed Jun 12 11:43:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10989591 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 6282C76 for ; Wed, 12 Jun 2019 11:44:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4DE782894D for ; Wed, 12 Jun 2019 11:44:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4105628A2E; Wed, 12 Jun 2019 11:44:29 +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 772D228A24 for ; Wed, 12 Jun 2019 11:44:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B58E46B026F; Wed, 12 Jun 2019 07:44:25 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B05A86B0270; Wed, 12 Jun 2019 07:44:25 -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 9595F6B0271; Wed, 12 Jun 2019 07:44:25 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yw1-f71.google.com (mail-yw1-f71.google.com [209.85.161.71]) by kanga.kvack.org (Postfix) with ESMTP id 6D0226B026F for ; Wed, 12 Jun 2019 07:44:25 -0400 (EDT) Received: by mail-yw1-f71.google.com with SMTP id b75so17011153ywh.8 for ; Wed, 12 Jun 2019 04:44:25 -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=gGgZ3a6eTnEUj++uQZqNg8ohQ9SAhJYSqDRRhc7mNEI=; b=T44tBTx971j7pGg7JRjO8iAbA60y8vfQaLNHeMUayxx2AauMDKYdXdB09vN3S7h3gw 8P8uskEG6wWSFHQuWKkGjq2sPQ3H5pY3O4ca6RPwfhcRxWBVlQpzV3t4/ci9DMjWtzzA S2RZ6CJFatng6X5stm9NGGU5d4v1xtWzaIQA/cEe9nUmIZHfxel8pECO+TKhyCdLNPNg oKf5CxEN0PKhVaxPwTVE1ImJiDGka+Tzy/pWA/PB6DVtLPqJx3yaj8RTXNFngq+jPpu6 gdDdw/OQ0ZXxGeD6fMOzm1q+++twKVw4sAWH2h8pm/a65T6qCmuSKDHbxkxGatRXsvzg /7TQ== X-Gm-Message-State: APjAAAWhirBHKSZnjSNqsYKamRUyQyZ5xb2y9sIJWrAg6x5aIHLZwubM 3xjxam7RWYhw+z2/Enixd92caFngeAdj/nuuOg9kPwnywLjDlNq9VHrekl9uQUDVVTHc7CgtUA0 24yCTXHk/96jUi3HIsuWe9ka91OSoSe8d2Ii6KOiPnyCvEXoyhIjEexbd9lGAul6P7w== X-Received: by 2002:a81:f011:: with SMTP id p17mr42126392ywm.89.1560339865177; Wed, 12 Jun 2019 04:44:25 -0700 (PDT) X-Received: by 2002:a81:f011:: with SMTP id p17mr42126351ywm.89.1560339864281; Wed, 12 Jun 2019 04:44:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560339864; cv=none; d=google.com; s=arc-20160816; b=kBHQCV5W/53qWQKqS3Q2vdGjzkHf+piyDOsQFHd4c9V7zCTdXfxZ7JiMz+F3AsSh7f 3TIHjdpvdpkLvWEYVupAj7EJ3/UPGuSaC880Un1Ub5pah39VN1v0XFAgf9PFsLaOkC8o lcgq70ZxEEiyw6Zqt27BjKhvG1y/Oq89rAltjBNvQ5q4tpy1HWw1oDMWpNp07+dDQajS sZhacFH7G06DQLnswRbHaAWINJivfRXP68E3SouR2L04M7nMIsr31n7UvYgXOIBycy7g rYrIickoof+ghJLMRG2d4m4NADdJ2EPLvMF7pLLAhMDl3S+0g7aoexbhrLsvVqnnfqRL TFLA== 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=gGgZ3a6eTnEUj++uQZqNg8ohQ9SAhJYSqDRRhc7mNEI=; b=04tDERl2uNyDOqWYLDv7NKWhGH7CVwgcAYIVLwZ04JZJrVnPHyRyHdCGAaj/HffdQa 3u/Ycu2kbmNj9cJD5ojYyA5DUXzc34bmUKaoj8L0cebyHFqMaghUA/a7RN82jmGrS+gN ARroMUdn2Hr3beXph1tJoifgqZQhMXeCWQZ/Z9ndO7acilSeXOYo1gRKlC9zid9IXmJP pyZoXkg6b5LT0s+i5s/FxlGFUvkBSmDRPyfR6u/WEe+AhYcdbXoTBT+3C+9Mevyl8vRx 6HxIBb6D+3Ppn6K5XUe3DxzhTq226bb8egM0oymSnLytkwM2aeJyjBZNtvQFPTHiwqxF k/GA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=IyYT4Uba; spf=pass (google.com: domain of 3l-uaxqokcfqw9zd0k69h72aa270.ya8749gj-886hwy6.ad2@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3l-UAXQoKCFQw9zD0K69H72AA270.yA8749GJ-886Hwy6.AD2@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 g7sor4022998ywl.183.2019.06.12.04.44.24 for (Google Transport Security); Wed, 12 Jun 2019 04:44:24 -0700 (PDT) Received-SPF: pass (google.com: domain of 3l-uaxqokcfqw9zd0k69h72aa270.ya8749gj-886hwy6.ad2@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=IyYT4Uba; spf=pass (google.com: domain of 3l-uaxqokcfqw9zd0k69h72aa270.ya8749gj-886hwy6.ad2@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3l-UAXQoKCFQw9zD0K69H72AA270.yA8749GJ-886Hwy6.AD2@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=gGgZ3a6eTnEUj++uQZqNg8ohQ9SAhJYSqDRRhc7mNEI=; b=IyYT4UbafS5twM0xOLKRaXywnDFDdbDqJgnUILJhttHP1uH2L+NNxbnxVgYAee8lTj qqRpjg9Px1/VzqAAM6upfA449si21/4lJ1XkboyBr77Ub0YTrQLbJn5sOIwz1IVA69V5 Ap8ARpNEkRP6VF2Emm63QaD9Cx3fvDSKZaN/HHC/Xocn6hv1419HlST6JCQQ1Z5EHlL/ CiJ+tHOg0rDi38FsnXC87324szrGfxAi8RWcHgDsH+2gfi2ulhbLZaNJ0gAKDJ3X8Gkg JxyfovuFPvVfND0iTfX5ByU+bmOloPTC5uiR6JL5swcvm2UzXNQY3tCHhrlAltKj98wk GeRA== X-Google-Smtp-Source: APXvYqw2mEWzgJjQoV5VS4+2oS4fV2R/NqpuRE12+fqx+o9WDuiIlBB+xhQmG1zgiCj0aRJhgLJNrenJlX6SsR3w X-Received: by 2002:a81:6d46:: with SMTP id i67mr906534ywc.103.1560339863971; Wed, 12 Jun 2019 04:44:23 -0700 (PDT) Date: Wed, 12 Jun 2019 13:43:32 +0200 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.22.0.rc2.383.gf4fbbf30c2-goog Subject: [PATCH v17 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 arm64 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. Co-developed-by: Catalin Marinas Signed-off-by: Andrey Konovalov --- tools/testing/selftests/arm64/.gitignore | 2 + tools/testing/selftests/arm64/Makefile | 22 +++++++ .../testing/selftests/arm64/run_tags_test.sh | 12 ++++ tools/testing/selftests/arm64/tags_lib.c | 62 +++++++++++++++++++ tools/testing/selftests/arm64/tags_test.c | 18 ++++++ 5 files changed, 116 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_lib.c 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..9b6a568de17f --- /dev/null +++ b/tools/testing/selftests/arm64/.gitignore @@ -0,0 +1,2 @@ +tags_test +tags_lib.so diff --git a/tools/testing/selftests/arm64/Makefile b/tools/testing/selftests/arm64/Makefile new file mode 100644 index 000000000000..9dee18727923 --- /dev/null +++ b/tools/testing/selftests/arm64/Makefile @@ -0,0 +1,22 @@ +# SPDX-License-Identifier: GPL-2.0 + +include ../lib.mk + +# 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_CUSTOM_PROGS := $(OUTPUT)/tags_test + +$(OUTPUT)/tags_test: tags_test.c $(OUTPUT)/tags_lib.so + $(CC) -o $@ $(CFLAGS) $(LDFLAGS) $< + +$(OUTPUT)/tags_lib.so: tags_lib.c + $(CC) -o $@ -shared $(CFLAGS) $(LDFLAGS) $^ + +TEST_PROGS := run_tags_test.sh + +all: $(TEST_CUSTOM_PROGS) + +endif 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..2bbe0cd4220b --- /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 "--------------------" +LD_PRELOAD=./tags_lib.so ./tags_test +if [ $? -ne 0 ]; then + echo "[FAIL]" +else + echo "[PASS]" +fi diff --git a/tools/testing/selftests/arm64/tags_lib.c b/tools/testing/selftests/arm64/tags_lib.c new file mode 100644 index 000000000000..55f64fc1aae6 --- /dev/null +++ b/tools/testing/selftests/arm64/tags_lib.c @@ -0,0 +1,62 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include + +#define TAG_SHIFT (56) +#define TAG_MASK (0xffUL << TAG_SHIFT) + +#define PR_SET_TAGGED_ADDR_CTRL 55 +#define PR_GET_TAGGED_ADDR_CTRL 56 +#define PR_TAGGED_ADDR_ENABLE (1UL << 0) + +void *__libc_malloc(size_t size); +void __libc_free(void *ptr); +void *__libc_realloc(void *ptr, size_t size); +void *__libc_calloc(size_t nmemb, size_t size); + +static void *tag_ptr(void *ptr) +{ + static int tagged_addr_err = 1; + unsigned long tag = 0; + + /* + * Note that this code is racy. We only use it as a part of a single + * threaded test application. Beware of using in multithreaded ones. + */ + if (tagged_addr_err == 1) + tagged_addr_err = prctl(PR_SET_TAGGED_ADDR_CTRL, + PR_TAGGED_ADDR_ENABLE, 0, 0, 0); + + if (!ptr) + return ptr; + if (!tagged_addr_err) + tag = rand() & 0xff; + + return (void *)((unsigned long)ptr | (tag << TAG_SHIFT)); +} + +static void *untag_ptr(void *ptr) +{ + return (void *)((unsigned long)ptr & ~TAG_MASK); +} + +void *malloc(size_t size) +{ + return tag_ptr(__libc_malloc(size)); +} + +void free(void *ptr) +{ + __libc_free(untag_ptr(ptr)); +} + +void *realloc(void *ptr, size_t size) +{ + return tag_ptr(__libc_realloc(untag_ptr(ptr), size)); +} + +void *calloc(size_t nmemb, size_t size) +{ + return tag_ptr(__libc_calloc(nmemb, size)); +} diff --git a/tools/testing/selftests/arm64/tags_test.c b/tools/testing/selftests/arm64/tags_test.c new file mode 100644 index 000000000000..263b302874ed --- /dev/null +++ b/tools/testing/selftests/arm64/tags_test.c @@ -0,0 +1,18 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#include +#include + +int main(void) +{ + struct utsname *ptr; + int err; + + ptr = (struct utsname *)malloc(sizeof(*ptr)); + err = uname(ptr); + free(ptr); + return err; +}