Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp362824imm; Mon, 1 Oct 2018 11:05:56 -0700 (PDT) X-Google-Smtp-Source: ACcGV63KFMSAWcPuAppwPxZjUK4TgiOUDf6EGdG2/BJ4SYwjNwYW5d3mApEjeZbRb7w58/ZKstdb X-Received: by 2002:a17:902:b08e:: with SMTP id p14-v6mr13067717plr.241.1538417156489; Mon, 01 Oct 2018 11:05:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538417156; cv=none; d=google.com; s=arc-20160816; b=ROoXM/EdsPsmTpV552sh2HHR65b/mnKmETI0Q/F7mP51IdnOD3/eLr2oTkE4Q6Cpbb kTOsgUClbNtkuZKfIKX6fE/j0a8ntw45sBpBh3r15kwxvu6wfQXOKU4gXvgyNSzYeacF cXUnRB53F5wNZOelBLaL4ZNSuzpoG2oM4MNnT/Gvcb/OmOq33PJGAJKsAAQUSqUg8AQ1 CTylC0qG5o3mH/sxjapfaw/sg3F+FrAk5gZibY855CEd24lbdXGc8COPZyGyooJK9Zgv m05NkPLxi90xwUkdyAq48G+cFUHIP+311M4MEM0Bj2uNPfBwI+B70eNbHN45DJAu5/4y n6dQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=WWliIodzBkjg/YvVrM0vD1BBjyk86A4iDE2GhInXr68=; b=fpHJlu+iOtdUH98ni28hIVowR13nzwyeLp1JLnvQydQ2ytXq+B5wvEAvJM6DfDuZhJ ucOVQvSkO0jUUlXeJdxwK6vktfYrlm74ji7W8SPltEgRrwQruI6le360GWyRiwcm02wm jOmj7XQKhBEiX5zUDvHudkHpFTd5BBLdepQrFt0mveVWwnTExeyXXwHVsds9jZFPmFjj IXE9klB5Ar7cPH7SVYbcUZtWOG6vlul8rGqGbOX7C8PYAPU/7Tt3r3jyttrx9YUScG36 /ZOFrci9EYn86DDFZLnMwZ9J2+s2Hb1GPNlZLQQDlcsMSuOvJ/KvivCCVtkMT3x9iTV2 0GgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@android.com header.s=20161025 header.b=qJBcg+SM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=android.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d66-v6si14388514pfa.186.2018.10.01.11.05.32; Mon, 01 Oct 2018 11:05:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@android.com header.s=20161025 header.b=qJBcg+SM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=android.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726782AbeJBAnw (ORCPT + 99 others); Mon, 1 Oct 2018 20:43:52 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:44816 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726138AbeJBAnv (ORCPT ); Mon, 1 Oct 2018 20:43:51 -0400 Received: by mail-pf1-f195.google.com with SMTP id k21-v6so9778908pff.11 for ; Mon, 01 Oct 2018 11:04:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=android.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WWliIodzBkjg/YvVrM0vD1BBjyk86A4iDE2GhInXr68=; b=qJBcg+SMf0bBhav/XKsrHsnUEr8fqNOqIyTleeRJtIIeO2LHHW8liGZ6Bj0zbZ26kz JTWQ0VFWqLKU/uKRX3GxAB9hyGw7JLltnKBNLfYIhiAH5SnMJZDNcfLR09K7UfIvA6S+ Cpv3C6FCTDUrK1ZT89uK5g6IbB4XDo9117ERAoGZLKOhCx9klEvMP24zdatyH1syLZLx TAq2H759J2P0+lB/+rP1F8BNZiIWkOqkuVydkFbmxAFVVRZOl9dQGHuAyo7E4o7XdavS MLH39vo6cv0njDhtp9JPBRURhEGywmjGDft+L6aaQcNoRc5Jcq2BiOs/SylpKnsoTN4t eQFQ== 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:mime-version:content-transfer-encoding; bh=WWliIodzBkjg/YvVrM0vD1BBjyk86A4iDE2GhInXr68=; b=t7i0RgaeItd1B5eTnO7Tzk9z1+ecpUwY25aCFzTLk9oP8vLCvGynO9r4GH4bUBN35R HVHFbDvO18aP15cK+ZEREiVKbEJO/dR194QNE2/x5BtxITky3lXXBWt8RoeiWwb67ed0 PkHco0svnb7aIQ0cEGKLLQBkkiEhaw3naU+WCWzw6scHfHsYuYt50ypnnv08OnfnVmaI QoXNAsrMU/14dXsMS4ybOq8NLtEVo2Q/pQLoH+4FF+ytpp6qNBzSyxBWnAJdfkjRlNsR IIQmobxpUDAkEEkD2POJICraDldkLPd0CED9QxakPj/Bv13dYG4ztN18NuKu1LvHQg0P WitQ== X-Gm-Message-State: ABuFfojcTPqeH5AWDn8E7mJDxIQNn2PDPcqc37RRYnOLgVrLJHf5dLOM CxwmPdsQiHu+4C7q0ztUWGVIpiqchws= X-Received: by 2002:a63:8c0b:: with SMTP id m11-v6mr11187164pgd.372.1538417092395; Mon, 01 Oct 2018 11:04:52 -0700 (PDT) Received: from nebulus.mtv.corp.google.com ([2620:0:1000:1612:b4fb:6752:f21f:3502]) by smtp.gmail.com with ESMTPSA id d186-v6sm24469261pfg.173.2018.10.01.11.04.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 01 Oct 2018 11:04:51 -0700 (PDT) From: Mark Salyzyn To: linux-kernel@vger.kernel.org Cc: Kevin Brodsky , Mark Salyzyn , James Morse , Russell King , Catalin Marinas , Will Deacon , Andy Lutomirski , Dmitry Safonov , John Stultz , Mark Rutland , Laura Abbott , Kees Cook , Ard Biesheuvel , Andy Gross , Andrew Pinski , Thomas Gleixner , linux-arm-kernel@lists.infradead.org, Jeremy Linton , android-kernel@android.com Subject: RESEND [PATCH 5/6] arm64: compat: 32-bit vDSO setup Date: Mon, 1 Oct 2018 10:58:42 -0700 Message-Id: <20181001175845.168430-23-salyzyn@android.com> X-Mailer: git-send-email 2.19.0.605.g01d371f741-goog In-Reply-To: <20181001175845.168430-1-salyzyn@android.com> References: <20181001175845.168430-1-salyzyn@android.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kevin Brodsky If the compat vDSO is enabled, install it in compat processes. In this case, the compat vDSO replaces the sigreturn page (it provides its own sigreturn trampolines). Signed-off-by: Kevin Brodsky Signed-off-by: Mark Salyzyn Tested-by: Mark Salyzyn Cc: James Morse Cc: Russell King Cc: Catalin Marinas Cc: Will Deacon Cc: Andy Lutomirski Cc: Dmitry Safonov Cc: John Stultz Cc: Mark Rutland Cc: Laura Abbott Cc: Kees Cook Cc: Ard Biesheuvel Cc: Andy Gross Cc: Andrew Pinski Cc: Thomas Gleixner Cc: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org Cc: Jeremy Linton Cc: android-kernel@android.com --- arch/arm64/kernel/vdso.c | 55 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/arch/arm64/kernel/vdso.c b/arch/arm64/kernel/vdso.c index 8529e85a521f..9fb1e0d380ab 100644 --- a/arch/arm64/kernel/vdso.c +++ b/arch/arm64/kernel/vdso.c @@ -58,6 +58,7 @@ struct vdso_data *vdso_data = &vdso_data_store.data; /* * Create and map the vectors page for AArch32 tasks. */ +#if !defined(CONFIG_VDSO32) || defined(CONFIG_KUSER_HELPERS) static struct page *vectors_page[] __ro_after_init; static const struct vm_special_mapping compat_vdso_spec[] = { { @@ -73,6 +74,7 @@ static const struct vm_special_mapping compat_vdso_spec[] = { #endif }; static struct page *vectors_page[ARRAY_SIZE(compat_vdso_spec)] __ro_after_init; +#endif static int __init alloc_vectors_page(void) { @@ -82,6 +84,7 @@ static int __init alloc_vectors_page(void) unsigned long kuser_vpage; #endif +#ifndef CONFIG_VDSO32 extern char __aarch32_sigret_code_start[], __aarch32_sigret_code_end[]; size_t sigret_sz = __aarch32_sigret_code_end - __aarch32_sigret_code_start; @@ -90,19 +93,24 @@ static int __init alloc_vectors_page(void) sigret_vpage = get_zeroed_page(GFP_ATOMIC); if (!sigret_vpage) return -ENOMEM; +#endif #ifdef CONFIG_KUSER_HELPERS kuser_vpage = get_zeroed_page(GFP_ATOMIC); if (!kuser_vpage) { +#ifndef CONFIG_VDSO32 free_page(sigret_vpage); +#endif return -ENOMEM; } #endif +#ifndef CONFIG_VDSO32 /* sigreturn code */ memcpy((void *)sigret_vpage, __aarch32_sigret_code_start, sigret_sz); flush_icache_range(sigret_vpage, sigret_vpage + PAGE_SIZE); vectors_page[0] = virt_to_page(sigret_vpage); +#endif #ifdef CONFIG_KUSER_HELPERS /* kuser helpers */ @@ -116,6 +124,7 @@ static int __init alloc_vectors_page(void) } arch_initcall(alloc_vectors_page); +#ifndef CONFIG_VDSO32 int aarch32_setup_vectors_page(struct linux_binprm *bprm, int uses_interp) { struct mm_struct *mm = current->mm; @@ -151,6 +160,7 @@ int aarch32_setup_vectors_page(struct linux_binprm *bprm, int uses_interp) return PTR_ERR_OR_ZERO(ret); } +#endif /* !CONFIG_VDSO32 */ #endif /* CONFIG_COMPAT */ static int vdso_mremap(const struct vm_special_mapping *sm, @@ -221,6 +231,23 @@ static int __init vdso_mappings_init(const char *name, return 0; } +#ifdef CONFIG_COMPAT +#ifdef CONFIG_VDSO32 + +static struct vdso_mappings vdso32_mappings __ro_after_init; + +static int __init vdso32_init(void) +{ + extern char vdso32_start[], vdso32_end[]; + + return vdso_mappings_init("vdso32", vdso32_start, vdso32_end, + &vdso32_mappings); +} +arch_initcall(vdso32_init); + +#endif /* CONFIG_VDSO32 */ +#endif /* CONFIG_COMPAT */ + static struct vdso_mappings vdso_mappings __ro_after_init; static int __init vdso_init(void) @@ -263,6 +290,34 @@ static int vdso_setup(struct mm_struct *mm, return PTR_ERR_OR_ZERO(ret); } +#ifdef CONFIG_COMPAT +#ifdef CONFIG_VDSO32 +int aarch32_setup_vectors_page(struct linux_binprm *bprm, int uses_interp) +{ + struct mm_struct *mm = current->mm; + void *ret; + + if (down_write_killable(&mm->mmap_sem)) + return -EINTR; + + ret = ERR_PTR(vdso_setup(mm, &vdso32_mappings)); +#ifdef CONFIG_KUSER_HELPERS + if (!IS_ERR(ret)) + /* Map the kuser helpers at the ABI-defined high address. */ + ret = _install_special_mapping(mm, AARCH32_KUSER_HELPERS_BASE, + PAGE_SIZE, + VM_READ|VM_EXEC| + VM_MAYREAD|VM_MAYEXEC, + &compat_vdso_spec[1]); +#endif + + up_write(&mm->mmap_sem); + + return PTR_ERR_OR_ZERO(ret); +} +#endif /* CONFIG_VDSO32 */ +#endif /* CONFIG_COMPAT */ + int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp) { struct mm_struct *mm = current->mm; -- 2.19.0.605.g01d371f741-goog