Bug 405201

Summary: Incorrect size of struct vki_siginfo on 64-bit Linux architectures
Product: [Developer tools] valgrind Reporter: Dmitry V. Levin <ldv>
Component: memcheckAssignee: Mark Wielaard <mark>
Status: RESOLVED FIXED    
Severity: normal CC: mark
Priority: NOR    
Version First Reported In: unspecified   
Target Milestone: ---   
Platform: Other   
OS: Linux   
URL: https://sourceforge.net/p/valgrind/mailman/message/36606811/
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:
Attachments: include/vki: fix vki_siginfo_t definition on amd64, arm64, and ppc64
include/vki: fix vki_siginfo_t definition on amd64, arm64, and ppc64

Description Dmitry V. Levin 2019-03-08 02:46:23 UTC
strace's "make check-valgind-memcheck" produces false reports about out-of-bounds writes on ptrace(PTRACE_GETSIGINFO) invocations on x86_64.

This turned out to be a bug in the definition of struct vki_siginfo: its size is 136 which exceeds VKI_SI_MAX_SIZE==128 by 8 bytes.

As all 64-bit architectures have union _sifields aligned to wordsize
boundary, there is a hole between the preamble and _sifields.

Unfortunately, __VKI_ARCH_SI_PREAMBLE_SIZE doesn't take this into account,
this results to off-by-one bug in VKI_SI_PAD_SIZE and the whole structure being 8 bytes larger on 64-bit architectures.
Comment 1 Julian Seward 2019-03-10 10:07:29 UTC
Do you have a patch to fix this?
Comment 2 Dmitry V. Levin 2019-03-10 14:14:13 UTC
(In reply to Julian Seward from comment #1)
> Do you have a patch to fix this?

https://sourceforge.net/p/valgrind/mailman/message/36606811/

Besides that, Eugene is working on a test for this bug.
Comment 3 Mark Wielaard 2019-09-17 03:14:50 UTC
Created attachment 122687 [details]
include/vki: fix vki_siginfo_t definition on amd64, arm64, and ppc64

Patch from the mailinglist
Comment 4 Mark Wielaard 2019-09-19 22:18:08 UTC
Created attachment 122744 [details]
include/vki: fix vki_siginfo_t definition on amd64, arm64, and ppc64

Thanks. I pushed the commit as attached.
Checked that running make check-valgrind-memcheck doesn't show any issues anymore (at least no ptrace related).

commit 3bac39a10abf292d332bb20ab58c6dd5c28f9108
Comment 5 Mark Wielaard 2020-01-29 22:39:13 UTC
Not that this patch caused bug #416760