Skip to content

Commit

Permalink
FROMLIST: [PATCH 5/6] arm64: compat: 32-bit vDSO setup
Browse files Browse the repository at this point in the history
(cherry pick from url https://patchwork.kernel.org/patch/10060459/)

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 <kevin.brodsky@arm.com>
Signed-off-by: Mark Salyzyn <salyzyn@android.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Dave Martin <Dave.Martin@arm.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
Bug: 63737556
Bug: 20045882
Change-Id: Ia6acf4c3ffea636bc750ac00853ea762c182e5b5
Signed-off-by: starlight5234 <ifist2834@gmail.com>
Signed-off-by: TheSync <repo-sync@outlook.com>
  • Loading branch information
kevin-brodsky-arm authored and Hadenix committed Feb 2, 2024
1 parent cadcd0a commit 02c3363
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions arch/arm64/kernel/vdso.c
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = {
{
Expand All @@ -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)
{
Expand All @@ -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;
Expand All @@ -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 */
Expand All @@ -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;
Expand Down Expand Up @@ -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 __init vdso_mappings_init(const char *name,
Expand Down Expand Up @@ -208,6 +218,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)
Expand Down Expand Up @@ -250,6 +277,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;
Expand Down

0 comments on commit 02c3363

Please sign in to comment.