[PATCH v4] socket: Check lengths before advancing pointer in CMSG_NXTHDR
Carlos O'Donell
carlos@redhat.com
Fri Jul 29 16:43:01 GMT 2022
On 7/29/22 12:40, Siddhesh Poyarekar wrote:
> On 2022-07-29 09:26, Arjun Shankar wrote:
>> The inline and library functions that the CMSG_NXTHDR macro may expand
>> to increment the pointer to the header before checking the stride of
>> the increment against available space. Since C only allows incrementing
>> pointers to one past the end of an array, the increment must be done
>> after a length check. This commit fixes that and includes a regression
>> test for CMSG_FIRSTHDR and CMSG_NXTHDR.
>>
>> The Linux, Hurd, and generic headers are all changed.
>>
>> Tested on Linux on armv7hl, i686, x86_64, aarch64, ppc64le, and s390x.
>>
>> [BZ #28846]
>> ---
>> v3: https://sourceware.org/pipermail/libc-alpha/2022-July/140854.html
>>
>> Notes on v4:
>>
>> * Addressed review comments from Siddhesh:
>>
>> 1. (sizeof (struct cmsghdr) + __CMSG_PADDING (cmsg_len)):
>> defined as size_needed.
>>
>> 2.
>>> OK, but I wonder if there's utility in making the padding a generic
>>> macro, e.g.
>>
>>> #define ALIGN_PADDING(n, a) ((a - (n & (a - 1))) & (a - 1))
>>
>> This sounds useful, and actually it would be great to move *all* of the
>> duplicate code between these versions into a separate file and include it
>> in these variants. I'll try to do a follow-up with this soon. I'm going to
>> note it down in my TODO.
>>
>> 3.
>>> __msg_control_ptr doesn't really need the __ since it's a local variable.
>>
>> I thought so too. But Florian pointed out that it would interfere with
>> things like users #define'ing msg_control_ptr before including socket.h.
>> ---
>> bits/socket.h | 40 ++++++++++--
>> socket/Makefile | 1 +
>> socket/tst-cmsghdr-skeleton.c | 92 +++++++++++++++++++++++++++
>> socket/tst-cmsghdr.c | 56 ++++++++++++++++
>> sysdeps/mach/hurd/bits/socket.h | 40 ++++++++++--
>> sysdeps/unix/sysv/linux/bits/socket.h | 40 ++++++++++--
>> sysdeps/unix/sysv/linux/cmsg_nxthdr.c | 36 ++++++++---
>> 7 files changed, 276 insertions(+), 29 deletions(-)
>> create mode 100644 socket/tst-cmsghdr-skeleton.c
>> create mode 100644 socket/tst-cmsghdr.c
>
> LGTM.
>
> Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
Just a reminder that the branch is frozen for glibc 2.36 release.
This is good for 2.37 when it opens.
--
Cheers,
Carlos.
More information about the Libc-alpha
mailing list