From: Guilherme Giacomo Simoes <trintaeoitogc@gmail.com>
To: thomas.weissschuh@linutronix.de
Cc: bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com,
linux-kernel@vger.kernel.org, luto@kernel.org, mingo@redhat.com,
tglx@kernel.org, trintaeoitogc@gmail.com, x86@kernel.org
Subject: Re: [PATCH] x86/vdso: fix incorrect size in munmap during map_vdso failure
Date: Tue, 5 May 2026 09:24:16 -0300 [thread overview]
Message-ID: <20260505122416.1037381-1-trintaeoitogc@gmail.com> (raw)
In-Reply-To: <20260505133747-904434f5-1bd3-467b-a9a1-99f48a4322fc@linutronix.de>
> On Sun, May 03, 2026 at 04:16:09PM -0300, Guilherme Giacomo Simoes wrote:
> > In the map_vdso function, if a failure occurs during the installation of
> > the VVAR mappings, the error path attempts to clean up previously
> > allocated mappings using do_munmap. However, the cleanup for the VVAR
> > mapping was incorrectly using image->size (the size of the vDSO text)
> > instead of the actual size allocated for the VVAR area.
> >
> > Replace the incorrect image->size parameter with the constant
> > VDSO_NR_PAGES * PAGE_SIZE in the do_munmap call. Ensure the unmap size
> > exactly matches the size used during the vdso_install_vvar_mapping()
> > phase to provide a symmetrical and complete teardown of the memory
> > region.
>
> Out of curiosity, did you encounter this in the real world?
When I was debug another problem (another unreferenced object), I compile the
kernel, up a qemu with a very small RAM (348MB) and I was run a simple .c
program to debug with a kmemleak scan:
```
./seupai & while true; do echo scan > /sys/kernel/debug/kmemleak; cat /sys/kernel/debug/kmemleak; sleep 10; done
```
But, I accidentally stumbled upon on this "unreferenced code" in the vdso.
I saw this stack:
```
unreferenced object 0xff110000168eed80 (size 192):
comm "seupai", pid 7917, jiffies 4294975318
hex dump (first 32 bytes):
00 90 f9 2b 7a 7f 00 00 00 b0 f9 2b 7a 7f 00 00 ...+z......+z...
00 80 a2 12 00 00 11 ff 25 00 00 00 00 00 00 00 ........%.......
backtrace (crc ee5fc346):
kmem_cache_alloc_noprof+0x278/0x4c0
vm_area_alloc+0x20/0x80
_install_special_mapping+0x2a/0x160
map_vdso+0x115/0x250
load_elf_binary+0x109f/0x15c0
bprm_execve+0x2d2/0x720
do_execveat_common+0x519/0x580
__x64_sys_execve+0x38/0x50
do_syscall_64+0x60/0x1e0
entry_SYSCALL_64_after_hwframe+0x76/0x7e
```
And I started thinking about this problem, until I found this little bug.
But I had a problem, I couldn't reproduce that bug again... For test my
solution I manually force a problem on third __install_special_mapping from
map_vdso() putting `vma = -ENOMEM` limiting by process name:
```
if (strcmp(current->comm, "seupai") == 0)
vma = -ENOMEM
```
prev parent reply other threads:[~2026-05-05 12:24 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-03 19:16 [PATCH] x86/vdso: fix incorrect size in munmap during map_vdso failure Guilherme Giacomo Simoes
2026-05-05 11:39 ` Thomas Weißschuh
2026-05-05 12:24 ` Guilherme Giacomo Simoes [this message]
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=20260505122416.1037381-1-trintaeoitogc@gmail.com \
--to=trintaeoitogc@gmail.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@kernel.org \
--cc=thomas.weissschuh@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox