lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250427145606.GC9350@redhat.com>
Date: Sun, 27 Apr 2025 16:56:06 +0200
From: Oleg Nesterov <oleg@...hat.com>
To: Jiri Olsa <jolsa@...nel.org>
Cc: Peter Zijlstra <peterz@...radead.org>,
	Andrii Nakryiko <andrii@...nel.org>, bpf@...r.kernel.org,
	linux-kernel@...r.kernel.org, linux-trace-kernel@...r.kernel.org,
	x86@...nel.org, Song Liu <songliubraving@...com>,
	Yonghong Song <yhs@...com>,
	John Fastabend <john.fastabend@...il.com>,
	Hao Luo <haoluo@...gle.com>, Steven Rostedt <rostedt@...dmis.org>,
	Masami Hiramatsu <mhiramat@...nel.org>,
	Alan Maguire <alan.maguire@...cle.com>,
	David Laight <David.Laight@...LAB.COM>,
	Thomas Weißschuh <thomas@...ch.de>,
	Ingo Molnar <mingo@...nel.org>
Subject: Re: [PATCH perf/core 08/22] uprobes/x86: Add mapping for optimized
 uprobe trampolines

On 04/21, Jiri Olsa wrote:
>
> +static unsigned long find_nearest_page(unsigned long vaddr)
> +{
> +	struct vm_area_struct *vma, *prev = NULL;
> +	unsigned long prev_vm_end = PAGE_SIZE;
> +	VMA_ITERATOR(vmi, current->mm, 0);
> +
> +	vma = vma_next(&vmi);
> +	while (vma) {
> +		if (prev)
> +			prev_vm_end = prev->vm_end;
> +		if (vma->vm_start - prev_vm_end  >= PAGE_SIZE) {
> +			if (is_reachable_by_call(prev_vm_end, vaddr))
> +				return prev_vm_end;
> +			if (is_reachable_by_call(vma->vm_start - PAGE_SIZE, vaddr))
> +				return vma->vm_start - PAGE_SIZE;
> +		}
> +		prev = vma;
> +		vma = vma_next(&vmi);
> +	}
> +
> +	return 0;
> +}

This can be simplified afaics... We don't really need prev, and we can
use for_each_vma(),

	static unsigned long find_nearest_page(unsigned long vaddr)
	{
		struct vm_area_struct *vma;
		unsigned long prev_vm_end = PAGE_SIZE;
		VMA_ITERATOR(vmi, current->mm, 0);

		for_each_vma(vmi, vma) {
			if (vma->vm_start - prev_vm_end  >= PAGE_SIZE) {
				if (is_reachable_by_call(prev_vm_end, vaddr))
					return prev_vm_end;
				if (is_reachable_by_call(vma->vm_start - PAGE_SIZE, vaddr))
					return vma->vm_start - PAGE_SIZE;
			}
			prev_vm_end = vma->vm_end;
		}

		return 0;
	}

> +static struct uprobe_trampoline *create_uprobe_trampoline(unsigned long vaddr)
> +{
> +	struct pt_regs *regs = task_pt_regs(current);
> +	struct mm_struct *mm = current->mm;
> +	struct uprobe_trampoline *tramp;
> +	struct vm_area_struct *vma;
> +
> +	if (!user_64bit_mode(regs))
> +		return NULL;

Cosmetic, but I think it would be better to move this check into the
caller, uprobe_trampoline_get().

> +	vma = _install_special_mapping(mm, tramp->vaddr, PAGE_SIZE,
> +				VM_READ|VM_EXEC|VM_MAYEXEC|VM_MAYREAD|VM_DONTCOPY|VM_IO,
> +				&tramp_mapping);

Note that xol_add_vma() -> _install_special_mapping() uses VM_SEALED_SYSMAP.
Perhaps create_uprobe_trampoline() should use this flag too for consistency?

Oleg.


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ