tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Basesystem programs redefine routine symbols from libc



On Mon, Dec 18, 2017 at 07:08:52PM +0000, David Holland wrote:
> In netbsd everything in libc with a name that isn't from Standard C
> (and thus not reusable by application code) is marked weak and aliased
> to a version of the name with a _ in front; also internal uses by libc
> are routed to those names so application use of conflicting symbols
> doesn't break libc. This is what libc's namespace.h is for, and
> somewhere there's actual documentation about it.
> 
> The sanitizer libraries should be doing the same things, and
> apparently they aren't.

They are on Linux (#else case, below) but not on FreeBSD.  It sounds
like FreeBSD's dynamic linker has a (grave?) bug: see the comment on the
FreeBSD case.  I hope we don't have the same bug in NetBSD!

#elif defined(__FreeBSD__)                                                      
# define WRAP(x) __interceptor_ ## x                                            
# define WRAPPER_NAME(x) "__interceptor_" #x                                    
# define INTERCEPTOR_ATTRIBUTE __attribute__((visibility("default")))           
// FreeBSD's dynamic linker (incompliantly) gives non-weak symbols higher       
// priority than weak ones so weak aliases won't work for indirect calls        
// in position-independent (-fPIC / -fPIE) mode.                                
# define DECLARE_WRAPPER(ret_type, func, ...) \                                 
     extern "C" ret_type func(__VA_ARGS__) \                                    
     __attribute__((alias("__interceptor_" #func), visibility("default")));     
#else                                                                           
# define WRAP(x) __interceptor_ ## x                                            
# define WRAPPER_NAME(x) "__interceptor_" #x                                    
# define INTERCEPTOR_ATTRIBUTE __attribute__((visibility("default")))           
# define DECLARE_WRAPPER(ret_type, func, ...) \                                 
    extern "C" ret_type func(__VA_ARGS__) \                                     
    __attribute__((weak, alias("__interceptor_" #func), visibility("default")));
#endif                                                                          

> Also, where the sanitizer libraries are trying to intercept and wrap
> libc calls they should be using the ELF dynamic linker's wrap
> functionality, and I'm not sure if they're doing that properly either.

I think that by "using the dynamic linker's wrap functionality" you mean
using dlsym(RTLD_NEXT, "<libc symbol name>") to find a pointer to libc's
definition?  The sanitizers do that.

Dave

-- 
David Young
dyoung%pobox.com@localhost    Urbana, IL    (217) 721-9981


Home | Main Index | Thread Index | Old Index