From: "H. Peter Anvin" <hpa@zytor.com>
To: Andy Lutomirski <luto@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>
Cc: x86@kernel.org, hpa@zytor.com, linux-kernel@vger.kernel.org
Subject: Address fixups in arch/x86/entry/vdso/vma.c
Date: Thu, 17 Jul 2025 10:34:27 -0700 [thread overview]
Message-ID: <5a2667c8-bad4-4079-90a2-e387b4472164@zytor.com> (raw)
Hi guys,
I was looking through the vdso setup code (because what I meant to be an
easy optimization turned out to be more "interesting" than expected...)
One of the thing that my mind flagged was this:
static void vdso_fix_landing(const struct vdso_image *image,
struct vm_area_struct *new_vma)
{
if (in_ia32_syscall() && image == &vdso_image_32) {
struct pt_regs *regs = current_pt_regs();
unsigned long vdso_land = image->sym_int80_landing_pad;
unsigned long old_land_addr = vdso_land +
(unsigned long)current->mm->context.vdso;
/* Fixing userspace landing - look at do_fast_syscall_32 */
if (regs->ip == old_land_addr)
regs->ip = new_vma->vm_start + vdso_land;
}
}
static int vdso_mremap(const struct vm_special_mapping *sm,
struct vm_area_struct *new_vma)
{
const struct vdso_image *image =
current->mm->context.vdso_image;
vdso_fix_landing(image, new_vma);
current->mm->context.vdso = (void __user *)new_vma->vm_start;
return 0;
}
--- ---
This feels *way* more complicated than it should need to be. It seems
to me that if the ip is inside the vdso at all, it would need to be
adjusted, regardless of if it in an ia32 system call or not, and if it
is at the specific landing spot or not.
It is possible that it doesn't *matter*, but that's not really a good
reason to make the code more complex.
I came up with the following version as an alternative; I would be
interesting to hear what you think.
(Also, (unsigned long)current->mm->context.vdso occurs *all over the
place*, but there is also a macro defined for it (VDSO_CURRENT_BASE, in
<asm/elf.h>. My personal preference would be to replace both with an
inline function.)
If you don't think I'm missing something, I would like to do something
like this:
static inline void
vdso_fix_address(unsigned long *ptr, const struct vdso_image *image,
unsigned long from, unsigned long to)
{
if (!image) /* For potential uses elsewhere */
return;
unsigned long offset = *ptr - from;
if (offset < image->size)
*ptr = offset + to;
}
static int vdso_mremap(const struct vm_special_mapping *sm,
struct vm_area_struct *new_vma)
{
vdso_fix_address(¤t_pt_regs()->ip,
current->mm->context.vdso_image,
vdso_current_base(),
new_vma->vm_start);
current->mm->context.vdso = (void __user *)new_vma->vm_start;
return 0;
}
next reply other threads:[~2025-07-17 17:35 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-17 17:34 H. Peter Anvin [this message]
2025-07-21 22:02 ` Address fixups in arch/x86/entry/vdso/vma.c Thomas Gleixner
2025-07-21 22:36 ` H. Peter Anvin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5a2667c8-bad4-4079-90a2-e387b4472164@zytor.com \
--to=hpa@zytor.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.