Bug 1344082 - valgrind mishandles pselect with null sigmask
Summary: valgrind mishandles pselect with null sigmask
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: valgrind
Version: 23
Hardware: x86_64
OS: Linux
unspecified
medium
Target Milestone: ---
Assignee: Mark Wielaard
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks: 1347626
TreeView+ depends on / blocked
 
Reported: 2016-06-08 17:19 UTC by Paul Eggert
Modified: 2016-06-30 21:27 UTC (History)
5 users (show)

Fixed In Version: valgrind-3.11.0-23.fc24
Clone Of:
: 1347626 (view as bug list)
Environment:
Last Closed: 2016-06-30 21:27:12 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)
test program illustrating valgrind bug (325 bytes, text/plain)
2016-06-08 17:19 UTC, Paul Eggert
no flags Details


Links
System ID Private Priority Status Summary Last Updated
KDE Software Compilation 364413 0 None None None 2016-06-17 09:10:05 UTC

Description Paul Eggert 2016-06-08 17:19:44 UTC
Created attachment 1166064 [details]
test program illustrating valgrind bug

valgrind-3.11.0 (in Fedora 23) x86-64 mishandles pselect with a null sigmask argument. It reports an error even though this is a valid use of pselect. To reproduce the problem, take the attached program pselect.c and run:

gcc pselect.c
valgrind ./a.out

The output will say something like this:

==22567== Syscall param pselect6(sig->ss) points to unaddressable byte(s)
==22567==    at 0x4F2D921: pselect (in /usr/lib64/libc-2.22.so)
==22567==    by 0x400613: main (in /home/eggert/junk/a.out)
==22567==  Address 0x0 is not stack'd, malloc'd or (recently) free'd

This diagnostic is bogus, as the pselect call is fine.

Comment 1 Mark Wielaard 2016-06-16 14:23:09 UTC
replicated with valgrind-3.11.0-18.fc23.x86_64 and upstream valgrind
This seems to be a regression since valgrind 3.10.0 doesn't show this bogus diagnostic.

Comment 2 Mark Wielaard 2016-06-16 14:35:47 UTC
Caused by this backported patch: valgrind-3.11.0-ppoll-mask.patch
Which is upstream valgrind svn r15823

    Sanitize signal mask in ppoll and pselect syscalls
    Reported and Linux patch contributed by Steven Smith <sos22.uk>
    Fixes BZ#359871

Which references upstream valgrind bug:
https://bugs.kde.org/359871
Incorrect mask handling in ppoll

Comment 3 Mark Wielaard 2016-06-16 14:58:48 UTC
And the issue is caused by this C library/kernel ABI differences according to http://man7.org/linux/man-pages/man2/pselect6.2.html

       The Linux pselect6() system call modifies its timeout argument.
       However, the glibc wrapper function hides this behavior by using a
       local variable for the timeout argument that is passed to the system
       call.  Thus, the glibc pselect() function does not modify its timeout
       argument; this is the behavior required by POSIX.1-2001.

       The final argument of the pselect6() system call is not a sigset_t *
       pointer, but is instead a structure of the form:

           struct {
               const sigset_t *ss;     /* Pointer to signal set */
               size_t          ss_len; /* Size (in bytes) of object pointed
                                          to by 'ss' */
           };

       This allows the system call to obtain both a pointer to the signal
       set and its size, while allowing for the fact that most architectures
       support a maximum of 6 arguments to a system call.

What we are seeing is glibc modifying the timeout argument (NULL) and passing it as a struct { NULL, 8 } (where 8 is the correct ss_len if ss wouldn't be NULL).

valgrind doesn't check whether ss is NULL before calling PRE_MEM_READ on it and so generates the bogus warning.

Comment 4 Mark Wielaard 2016-06-17 09:10:05 UTC
Pushing bug, testcase and fix upstream:
https://bugs.kde.org/show_bug.cgi?id=364413

Comment 5 Fedora Update System 2016-06-22 11:07:18 UTC
valgrind-3.11.0-23.fc24 has been submitted as an update to Fedora 24. https://bodhi.fedoraproject.org/updates/FEDORA-2016-d448fefa4a

Comment 6 Fedora Update System 2016-06-22 23:02:44 UTC
valgrind-3.11.0-23.fc24 has been pushed to the Fedora 24 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2016-d448fefa4a

Comment 7 Fedora Update System 2016-06-30 21:27:08 UTC
valgrind-3.11.0-23.fc24 has been pushed to the Fedora 24 stable repository. If problems still persist, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.