Skip to content

core: fill out msg_controllen for IPV6_PKTINFO control messages correctly#912

Merged
evverx merged 2 commits into
avahi:masterfrom
evverx:openbsd
May 8, 2026
Merged

core: fill out msg_controllen for IPV6_PKTINFO control messages correctly#912
evverx merged 2 commits into
avahi:masterfrom
evverx:openbsd

Conversation

@evverx
Copy link
Copy Markdown
Collaborator

@evverx evverx commented May 8, 2026

to prevent avahi_send_dns_packet_ipv6 from failing on systems where the
length is strictly validated. For example without this patch on OpenBSD
all the attempts to send packets over IPv6 get rejected with

CALL  sendmsg(13,0x7d91b98158c8,0)
STRU  struct msghdr { name=0x7d91b98158f8, namelen=28, iov=0x7d91b98158b8, iovlen=1, control=0x7d91b9815880, controllen=36, flags=0 }
STRU  struct iovec { base=0x8f99574c030, len=228 }
STRU  struct sockaddr { AF_INET6, [ff02::fb]:5353 }
STRU  struct cmsghdr { len=36, level=41<ipv6>, type=46 }
RET   sendmsg -1 errno 22 Invalid argument

It has been addressed downstream with a similar patch:
https://github.com/openbsd/ports/blob/92b23c283dfd8173e6035db42b5ec82acad64ae8/net/avahi/patches/patch-avahi-core_socket_c

OpenBSD is rolled out to make sure it's buildable and releasable there.

evverx added 2 commits May 8, 2026 11:41
…ctly

to prevent avahi_send_dns_packet_ipv6 from failing on systems where the
length is strictly validated. For example without this patch on OpenBSD
all the attempts to send packets over IPv6 get rejected with
```
CALL  sendmsg(13,0x7d91b98158c8,0)
STRU  struct msghdr { name=0x7d91b98158f8, namelen=28, iov=0x7d91b98158b8, iovlen=1, control=0x7d91b9815880, controllen=36, flags=0 }
STRU  struct iovec { base=0x8f99574c030, len=228 }
STRU  struct sockaddr { AF_INET6, [ff02::fb]:5353 }
STRU  struct cmsghdr { len=36, level=41<ipv6>, type=46 }
RET   sendmsg -1 errno 22 Invalid argument
```
It has been addressed downstream with a similar patch:
https://github.com/openbsd/ports/blob/92b23c283dfd8173e6035db42b5ec82acad64ae8/net/avahi/patches/patch-avahi-core_socket_c
Comment thread avahi-core/socket.c
union {
uint8_t cmsg_data[CMSG_SPACE(sizeof(struct in6_pktinfo))];
struct cmsghdr hdr;
} u;
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OpenScanHub complains https://openscanhub.fedoraproject.org/task/114977/log/added.html

Error: CPPCHECK_WARNING ([CWE-398](https://cwe.mitre.org/data/definitions/398.html)): [[#def1]](https://openscanhub.fedoraproject.org/task/114977/log/added.html#def1)
avahi-0.9.rc4/avahi-core/socket.c:590: style[variableScope]: The scope of the variable 'u' can be reduced.
#  588|           uint8_t cmsg_data[CMSG_SPACE(sizeof(struct in6_pktinfo))];
#  589|           struct cmsghdr hdr;
#  590|->     } u;

but it's a false positive. The scope can't be reduced because msg points to it so if u was moved to the inner scope it would lead to

==35332==ERROR: AddressSanitizer: stack-use-after-scope on address 0xff6d208172f0 at pc 0xff6d23cce194 bp 0xffffe1975030 sp 0xffffe1974810
READ of size 8 at 0xff6d208172f0 thread T0
     #0 0xff6d23cce190 in read_msghdr_control ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:3177
     #1 0xff6d23cce190 in read_msghdr ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:3215
     #2 0xff6d23ce35e4 in sendmsg ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:3230
     #3 0xff6d2391cb94 in sendmsg_loop /home/runner/work/avahi/avahi/avahi-core/socket.c:450
     #4 0xff6d2391e6d4 in avahi_send_dns_packet_ipv6 /home/runner/work/avahi/avahi/avahi-core/socket.c:637

@evverx evverx merged commit 3737842 into avahi:master May 8, 2026
62 checks passed
@evverx evverx added the bug label May 8, 2026
@evverx evverx added this to the v0.9 milestone May 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant