Bug 279012 - Linuxulator: Glibc getaddrinfo(3) Breakage
Summary: Linuxulator: Glibc getaddrinfo(3) Breakage
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: Gleb Smirnoff
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-05-15 17:38 UTC by seafork
Modified: 2024-05-28 20:14 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description seafork 2024-05-15 17:38:02 UTC
In commit https://cgit.freebsd.org/src/commit?id=b977dd1ea5fbc2df3f1279330be4d089322eb2cf , the check

if (hdr->nlmsg_len < sizeof(struct nlmsghdr) + sizeof(struct ifaddrmsg))
    return (EBADMSG);

in `sys/compat/linux/linux_netlink.c:97` was added and caused glibc's 
getaddrinfo(3) to break. This, as one might think, causes quite a few 
programs in the linuxulator to stop working. After looking into it, glibc 
is indeed not sending what we're expecting. Not only are they not 
including the space of the header, but they're also using the seemingly 
depreciated (i.e no documentation [i could find] speaking of it) 
`rtgenmsg` format. [1] While indeed we also have this in our source tree 
`sys/netlink/route/route.h:363`, it's used nowhere except in 
`crypto/heimdal/lib/roken/getifaddrs.c:275`; however, even in that code, 
they make sure to include the space of the header with the 
`NLMSG_LENGTH` macro. Obliviously, please take this with a large grain 
of salt as I'm quite inexperienced. That being said, I believe our best 
bet would be to contact upstream, and in the meantime, implement this 
functionality. On the latter half, I would be more than happy to do said 
implementing, all I would need are some pointers to relevant 
documentation.

Cheers!

[1] https://elixir.bootlin.com/glibc/latest/source/sysdeps/unix/sysv/linux/check_pf.c#L92
Comment 1 commit-hook freebsd_committer freebsd_triage 2024-05-28 20:14:20 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=2780e5f43d5b0e8b155472300ee63816a660780e

commit 2780e5f43d5b0e8b155472300ee63816a660780e
Author:     Gleb Smirnoff <glebius@FreeBSD.org>
AuthorDate: 2024-05-28 20:13:08 +0000
Commit:     Gleb Smirnoff <glebius@FreeBSD.org>
CommitDate: 2024-05-28 20:13:08 +0000

    linux: allow RTM_GETADDR without full ifaddrmsg argument

    Even modern glibc uses truncated argument for RTM_GETADDR when it wants to
    list all addresses in a system.  See
    sysdeps/unix/sysv/linux/ifaddrs.c:__netlink_sendreq().  It sends a one
    char payload.  Linux kernel allows that as long as given socket is not
    marked as a 'strict'.  We have a similar flag in the general netlink code
    and it is checked in
    sys/netlink/netlink_message_parser.h:nl_parse_header().  If the flag is
    not present, parser will allocate a temporary zeroed buffer to make the
    message correct.  The checks added in b977dd1ea5fb blocked such message
    before the parser.  My reading of glibc says that there are two types of
    messages that are sent with __netlink_sendreq() - RTM_GETLINK and
    RTM_GETADDR.  The RTM_GETLINK is binary compatible between Linux and
    FreeBSD and thus doesn't need any ABI handler.

    PR:             279012
    Fixes:          b977dd1ea5fbc2df3f1279330be4d089322eb2cf

 sys/compat/linux/linux_netlink.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)