I'm trying to create a seccomp sandbox for a project and I need to override libc functions related to ambient authority. So far I had success with many functions as most of them are weak symbols and I can just override them in static builds. For getaddrinfo(), I wasn't so lucky as the symbol is not declared as weak. Can the symbol getaddrinfo() be declared as weak in static builds? I can offer more details of my use case if there's interest.
It's not clear to me what this would solve. There are only three symbols defined in nss/getaddrinfo.o: __libc_getaddrinfo_freemem, getaddrinfo, freeaddrinfo. There is no strong reference that would pull in this object through __libc_getaddrinfo_freemem, so only getaddrinfo and freeaddrinfo remain for consideration. Is the idea that you can redefine getaddrinfo without defining freeaddrinfo? I don't think this is wise because how memory is to be freed by freeaddrinfo is an internal implementation detail of getaddrinfo.
> Is the idea that you can redefine getaddrinfo without defining freeaddrinfo? I don't think this is wise because how memory is to be freed by freeaddrinfo is an internal implementation detail of getaddrinfo. First I resolve the requested name to an IP address + port. Then I define two string buffers to hold the string-encoded values: * https://gitlab.com/emilua/emilua/-/blob/ded3de90974f854fb637afb6c9d4dda4f40dc3bd/src/proc_set_libc_service.cpp#L1834 * https://gitlab.com/emilua/emilua/-/blob/ded3de90974f854fb637afb6c9d4dda4f40dc3bd/src/proc_set_libc_service.cpp#L1884 Then I call getaddrinfo() (the libc one) with AI_NUMERICHOST|AI_NUMERICSERV: https://gitlab.com/emilua/emilua/-/blob/ded3de90974f854fb637afb6c9d4dda4f40dc3bd/src/proc_set_libc_service.cpp#L1898 freeaddrinfo() will do the right thing because the buffers were allocated by libc's getaddrinfo().
I don't see how making getaddrinfo or freeaddrinfo weak would help you.
> I don't see how making getaddrinfo or freeaddrinfo weak would help you. That's the error I get when I try to build a static binary: /usr/bin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../lib/libc.a(getaddrinfo.o): in function `getaddrinfo': (.text+0x1f30): multiple definition of `getaddrinfo'; libemilua-libc-service.a.p/src_linux_glibc_libc_service.cpp.o:/home/vinipsmaker/Projects/emilua/build3/../src/linux/glibc/libc_service.cpp:141: first defined here This error doesn't happen for other libc functions because they're defined as weak so you can just define your function with the same name and your function will override the libc's. That's how a weak getaddrinfo() will help me. It allows me to override getaddrinfo() in static builds.