From patchwork Wed Jun 24 08:33:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrei Vagin X-Patchwork-Id: 11622597 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F2D88913 for ; Wed, 24 Jun 2020 08:35:29 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BC04E2088E for ; Wed, 24 Jun 2020 08:35:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="spXF7T9i"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LuLWGAHb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BC04E2088E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:References:In-Reply-To:Message-Id:Date:Subject:To: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=bQyjZcx5gFV1vXzfOVa1wSJoO4lC4jUFmCYZ5CMKRRQ=; b=spXF7T9iDh92rmGgJBf9caeDjD VHJ/7h8FSE+2/692X/FdAizcS8DWuprcwwSEuYHXSp+8I9GCMyU9z+zurxO9GD/QzwUNMeyNnFytU rtIfz9Y9W8SYAxTAdd5Yo4GzcTmKNJhJsMy2XN6eFr7jSjK5Tp9RzKcqg0wXs3rnCtG3nL1wdsTiR F+56TkFZAMdtXBD6MA7VjSpkEucdBw+wyW1MiPmKfyn7Gc755Qt4HvRJQX4rpqonuu5r284BbaC5k sU2TgYf5V42xgE3eLoPgetiquYEx+0ll33ftfT75MDJpcxolbJyLj/0RrkJybuvnW6MSivpuDu+eJ HB5OKcjA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jo0ql-0008K3-0l; Wed, 24 Jun 2020 08:33:43 +0000 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jo0qY-0008Fd-0d for linux-arm-kernel@lists.infradead.org; Wed, 24 Jun 2020 08:33:31 +0000 Received: by mail-pf1-x441.google.com with SMTP id d66so848093pfd.6 for ; Wed, 24 Jun 2020 01:33:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=/8shzvkLZsRhF8EZiKwRb8IF1NpqovkVn3jBNb1PgYM=; b=LuLWGAHbvAtYucC3BWurHeM1ccLgXcqjPYvzH4nrLZhaqZNRwbLU+BAqXwo9nAZakQ OlnmNWE/wAi55BiWJJeFq8T3XTxJ0V1JMtYMEyV4Mhdyq8MOBGWPRdOw8JVg5Zs+vopT GVUnEjOm7YQHarNfqJrqIIishg88JZlRTVyuxyoifLWAdu8Gi3KUSIo2upbLSqkaBcFb v1h4TNUpp1IZh6RG2r9dPj3zrEJIIr+p5yO3UAE5J0bRVcVQbBQ4YtotNxhoIbqRIZy3 bCODgJ360ezsnoQtu8zOABWR2lffiYDpMA8G+CRVGt8xYV+9X+tBQ253tAB8EaYvU6vY PiuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=/8shzvkLZsRhF8EZiKwRb8IF1NpqovkVn3jBNb1PgYM=; b=DzFr5W6lcW2IHxe7twMpCvAW1ceoHeXroRvH75u16l7o3QnU0ZtQFtRB9i9AM52NzA 6jLxyzfYskb7446/RuGm7OwM9baEQDHGqxYcTpRn/blXiXSNfyZ0CUhMz3fQ8iYRSwvj tOJfR7IZEnnr2GD3V1XRo6gv1QbDgL1AfaNpAoLwqpVJEF/HgAH9PfsViiHjmYrJagz/ Y9Azdld6FtdbLwu/YIfTtBIPzXP/abx/gCL65z2YmptggHs7MTizahDPpazeqzy1IPtk G6RDCHFm0LKLfE2VUJC7sLPp6tBywkbAj6yXQHvJayxPTsBu0mzftvtf+RWahlKSb338 waQQ== X-Gm-Message-State: AOAM530ce/8/wpmLelJEDvlt/1bjwarc0MQweUrPDYnLl0QqIWfCg8cU v8Xv9eHnR4uonhEjo+vgp8kFWeBZjyQ= X-Google-Smtp-Source: ABdhPJzYJoJE7U5Ie3r319LMCTJWxMmY7lcknEIGWp2J7pdOc0e/Zdap0hYIF7xt/sfeYsFxWwNAxg== X-Received: by 2002:a05:6a00:14d4:: with SMTP id w20mr29268187pfu.279.1592987607681; Wed, 24 Jun 2020 01:33:27 -0700 (PDT) Received: from laptop.hsd1.wa.comcast.net ([2601:600:9b7f:872e:a655:30fb:7373:c762]) by smtp.gmail.com with ESMTPSA id g17sm4558614pju.11.2020.06.24.01.33.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jun 2020 01:33:27 -0700 (PDT) From: Andrei Vagin To: Catalin Marinas , Will Deacon , Mark Rutland Subject: [PATCH 4/6] arm64/vdso: Handle faults on timens page Date: Wed, 24 Jun 2020 01:33:19 -0700 Message-Id: <20200624083321.144975-5-avagin@gmail.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20200624083321.144975-1-avagin@gmail.com> References: <20200624083321.144975-1-avagin@gmail.com> X-Spam-Note: CRM114 invocation failed X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:441 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [avagin[at]gmail.com] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Dmitry Safonov , linux-kernel@vger.kernel.org, Andrei Vagin , Thomas Gleixner , Vincenzo Frascino , Christian Brauner , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org If a task belongs to a time namespace then the VVAR page which contains the system wide VDSO data is replaced with a namespace specific page which has the same layout as the VVAR page. Reviewed-by: Vincenzo Frascino Reviewed-by: Dmitry Safonov Signed-off-by: Andrei Vagin --- arch/arm64/kernel/vdso.c | 57 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 4 deletions(-) diff --git a/arch/arm64/kernel/vdso.c b/arch/arm64/kernel/vdso.c index 18854e6c1373..be9ca8c46cff 100644 --- a/arch/arm64/kernel/vdso.c +++ b/arch/arm64/kernel/vdso.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -164,15 +165,63 @@ int vdso_join_timens(struct task_struct *task, struct time_namespace *ns) mmap_read_unlock(mm); return 0; } + +static struct page *find_timens_vvar_page(struct vm_area_struct *vma) +{ + if (likely(vma->vm_mm == current->mm)) + return current->nsproxy->time_ns->vvar_page; + + /* + * VM_PFNMAP | VM_IO protect .fault() handler from being called + * through interfaces like /proc/$pid/mem or + * process_vm_{readv,writev}() as long as there's no .access() + * in special_mapping_vmops(). + * For more details check_vma_flags() and __access_remote_vm() + */ + + WARN(1, "vvar_page accessed remotely"); + + return NULL; +} +#else +static inline struct page *find_timens_vvar_page(struct vm_area_struct *vma) +{ + return NULL; +} #endif static vm_fault_t vvar_fault(const struct vm_special_mapping *sm, struct vm_area_struct *vma, struct vm_fault *vmf) { - if (vmf->pgoff == 0) - return vmf_insert_pfn(vma, vmf->address, - sym_to_pfn(vdso_data)); - return VM_FAULT_SIGBUS; + struct page *timens_page = find_timens_vvar_page(vma); + unsigned long pfn; + + switch (vmf->pgoff) { + case VVAR_DATA_PAGE_OFFSET: + if (timens_page) + pfn = page_to_pfn(timens_page); + else + pfn = sym_to_pfn(vdso_data); + break; +#ifdef CONFIG_TIME_NS + case VVAR_TIMENS_PAGE_OFFSET: + /* + * If a task belongs to a time namespace then a namespace + * specific VVAR is mapped with the VVAR_DATA_PAGE_OFFSET and + * the real VVAR page is mapped with the VVAR_TIMENS_PAGE_OFFSET + * offset. + * See also the comment near timens_setup_vdso_data(). + */ + if (!timens_page) + return VM_FAULT_SIGBUS; + pfn = sym_to_pfn(vdso_data); + break; +#endif /* CONFIG_TIME_NS */ + default: + return VM_FAULT_SIGBUS; + } + + return vmf_insert_pfn(vma, vmf->address, pfn); } static int __setup_additional_pages(enum vdso_abi abi,