From patchwork Tue Jul 23 17:58:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11054863 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A8099746 for ; Tue, 23 Jul 2019 17:59:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 981EC286C6 for ; Tue, 23 Jul 2019 17:59:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8C1C9286E0; Tue, 23 Jul 2019 17:59:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1021E286C6 for ; Tue, 23 Jul 2019 17:59:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AC1818E000C; Tue, 23 Jul 2019 13:59:23 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A72678E0002; Tue, 23 Jul 2019 13:59:23 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8EBB18E000C; Tue, 23 Jul 2019 13:59:23 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by kanga.kvack.org (Postfix) with ESMTP id 70D3C8E0002 for ; Tue, 23 Jul 2019 13:59:23 -0400 (EDT) Received: by mail-qt1-f198.google.com with SMTP id x7so39141694qtp.15 for ; Tue, 23 Jul 2019 10:59:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=4Wn1GFyfxt3NCYf4PGNTFvqYM1MN1tNvgEFxNqktnk8=; b=ehu0SF9H7sKnJ8MLn2PFWfgGQ7WaKm+cMCFfy0QzeKrqEnq9Jin0bLO5+d0f6iRpOq dpsf7M6Gw+s+sH2qnkG2Mm2mRaXj7ukdMw/JsbdZ8dGn2Xa4isYBcGK1I41RKdk6+taA 1NO3F+GmXzDIYmSadMkiLcw3+aOlxDzhf/dtQUvjir/Ct0OaEwQ0git7HXfuH5prQm1n iI7/y/HRJ32T/weuSV/AP9y7EBEfKTyujIQVrmCHtOb1K/66GUROzOiY9KDAHol6grJM bWH3g0l/Qxv0N+5OeWOscx1LS9nyMW5goGNtvTZ08RhLZNAnxyFX6dXlpOKNawT6mgBA xV1w== X-Gm-Message-State: APjAAAW+udCRfheZw8FDVhcsaY0hmcOPCWl1YBKG30n8+cY6+krQDUEk sdUvYzrAfJnnJuG8+vlnJl6Wi/Rwbiyo53Ew/umkJVpikyRup3K1TUXU2lijOilSHLZQYCDHIGf w2/1TSCqc69FMH/RlP+aTmTBG6sJj0AwxULZBh0558eM6H4WYV43KcgxycZsnnZx1WQ== X-Received: by 2002:a37:98c3:: with SMTP id a186mr51731249qke.498.1563904763233; Tue, 23 Jul 2019 10:59:23 -0700 (PDT) X-Received: by 2002:a37:98c3:: with SMTP id a186mr51731239qke.498.1563904762727; Tue, 23 Jul 2019 10:59:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563904762; cv=none; d=google.com; s=arc-20160816; b=NJQVvp+6NIQfqglfp3UOd0GHyk8jGIEGokIUEiu9Il0MuTxZQUXQ0/SjM0wHJN8GzI gMyhub5UQ8howHIsN3VQ/Kz+Go8oui4UFThSMHlyxpYgjc2oVA/Dtn4Jlv3LOVtfGJEp RitNFwq2yXriZfQNH5nEgtRpOYqk8Bw391Ddyq/6dQL9q1XoEL/a0IqA/t1LBG4MSC3c Hng3PKm8MrffEEAvGos7MYw1x0aZ+aGQZ6jekl1+Z0CT6EiXSmjUAY4vAJlwdNPLNEwU zXDm9k6ZyCNMvJAlJtgSpdPSVAvUiTCrBDdClSlrnV2o4lUKXIDNJ3WOmiaYIB4qYuC/ /SeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:dkim-signature; bh=4Wn1GFyfxt3NCYf4PGNTFvqYM1MN1tNvgEFxNqktnk8=; b=jjYMdLUSDO7PFSXsfqQ+0HTWGU3Mm9mgGHwwFqqSFOg+8HIzh0ADpVMOzd/Kuj7gv+ uJVEfYEE7gmr4B7vOI5aLGWO2gO9MoCDIWgsTkMRcXvXcqXKHcTJ5BcW5k+rQJS1Mjz1 bQ2f4Ijo6VwtjGNHMTknQx0VxKM7ZNAveFUSEI/MgCl937Bi9kdPLKWQQEl5vygc6o4W +Bab8kPcTK1HgM2pFZAQtAzosCKc4fSzVbArHMbuENi1C1KY061inJAX5NZrmOFalO5T IHCYh1/YsioKnMr0b7IYNJ4tk+rp2gADC5nOagnjJCcztbHN1uGXNaBj7w3FEsYUw5Aw fBDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=XwZfpnbX; spf=pass (google.com: domain of 3-ko3xqokcf05i8m9tfiqgbjjbg9.7jhgdips-hhfq57f.jmb@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3-ko3XQoKCF05I8M9TFIQGBJJBG9.7JHGDIPS-HHFQ57F.JMB@flex--andreyknvl.bounces.google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from mail-sor-f73.google.com (mail-sor-f73.google.com. [209.85.220.73]) by mx.google.com with SMTPS id c73sor24926420qkb.105.2019.07.23.10.59.22 for (Google Transport Security); Tue, 23 Jul 2019 10:59:22 -0700 (PDT) Received-SPF: pass (google.com: domain of 3-ko3xqokcf05i8m9tfiqgbjjbg9.7jhgdips-hhfq57f.jmb@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) client-ip=209.85.220.73; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=XwZfpnbX; spf=pass (google.com: domain of 3-ko3xqokcf05i8m9tfiqgbjjbg9.7jhgdips-hhfq57f.jmb@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3-ko3XQoKCF05I8M9TFIQGBJJBG9.7JHGDIPS-HHFQ57F.JMB@flex--andreyknvl.bounces.google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=4Wn1GFyfxt3NCYf4PGNTFvqYM1MN1tNvgEFxNqktnk8=; b=XwZfpnbXFN1ibF12kJh4UX27GKqgHpAYVMgncvRg2XMsGuyHBAM2BbcbV2FMLG6KI2 Eail8AtVvVEkdWyRNAKDAPdYJBEXOQRcSGAF4Z+pO2ORJP6spfMGKAIf7M0K0GlZ5J+x 8yVEMOwDv+oyp2b+30vvjnV2SNVEvVcKU1T+4yjg+W1ok7J01teWzQ68jS7jmU8ro/kC Oxn9FlCYKBVtK3Jwi5MWr/zhUNuljezL1OPreJbqbiZZtnxrZ1CQ3LvL2shMV2iJ2vVT olnzEJp2mTvJs0fngbdCdc/sbDwJUI9/28M468SMn/xpTOjrRZ2LIWF7gDkmDS+GMcl9 Q1sg== X-Google-Smtp-Source: APXvYqy0Hkccu8SUSwSAcf0RwepBseg9rSnBcrNaRpXVNhE8d6jRb6uSi4vWmbN3MkxTqVVfEdk8tSl4b+EbX0xe X-Received: by 2002:a37:4f47:: with SMTP id d68mr50765232qkb.104.1563904762211; Tue, 23 Jul 2019 10:59:22 -0700 (PDT) Date: Tue, 23 Jul 2019 19:58:42 +0200 In-Reply-To: Message-Id: <4731bddba3c938658c10ff4ed55cc01c60f4c8f8.1563904656.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.22.0.709.g102302147b-goog Subject: [PATCH v19 05/15] mm: untag user pointers in mm/gup.c From: Andrey Konovalov To: linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-rdma@vger.kernel.org, linux-media@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: Catalin Marinas , Vincenzo Frascino , Will Deacon , Mark Rutland , Andrew Morton , Greg Kroah-Hartman , Kees Cook , Yishai Hadas , Felix Kuehling , Alexander Deucher , Christian Koenig , Mauro Carvalho Chehab , Jens Wiklander , Alex Williamson , Leon Romanovsky , Luc Van Oostenryck , Dave Martin , Khalid Aziz , enh , Jason Gunthorpe , Christoph Hellwig , Dmitry Vyukov , Kostya Serebryany , Evgeniy Stepanov , Lee Smith , Ramana Radhakrishnan , Jacob Bramley , Ruben Ayrapetyan , Robin Murphy , Kevin Brodsky , Szabolcs Nagy , Andrey Konovalov X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP This patch is a part of a series that extends kernel ABI to allow to pass tagged user pointers (with the top byte set to something else other than 0x00) as syscall arguments. mm/gup.c provides a kernel interface that accepts user addresses and manipulates user pages directly (for example get_user_pages, that is used by the futex syscall). Since a user can provided tagged addresses, we need to handle this case. Add untagging to gup.c functions that use user addresses for vma lookups. Reviewed-by: Khalid Aziz Reviewed-by: Vincenzo Frascino Reviewed-by: Kees Cook Reviewed-by: Catalin Marinas Signed-off-by: Andrey Konovalov --- mm/gup.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mm/gup.c b/mm/gup.c index 98f13ab37bac..1c1c97ec63df 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -799,6 +799,8 @@ static long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm, if (!nr_pages) return 0; + start = untagged_addr(start); + VM_BUG_ON(!!pages != !!(gup_flags & FOLL_GET)); /* @@ -961,6 +963,8 @@ int fixup_user_fault(struct task_struct *tsk, struct mm_struct *mm, struct vm_area_struct *vma; vm_fault_t ret, major = 0; + address = untagged_addr(address); + if (unlocked) fault_flags |= FAULT_FLAG_ALLOW_RETRY;