tags 636943 + patch thanks Hi!
On Thu, Nov 03, 2011 at 07:00:13PM +0100, intrigeri wrote: > unfortunately, torsocks 1.2 does not fix this bug, but only the > res_send() part of it; it seems like nothing has changed since what > I wrote in August: > > > Also, this is related to upstream issue #3 [0]; not marking as > > forwarded, since upstream issue is about res_send() only (fixed in > > 441fb10e), although the other messages are mentioned at the end of > > the discussion too. It looks like libresolv is actually a complicated case. It is considered a private interface of the glibc, and thus symbols have varied over time. One can look at `abilist/libresolv.abilist` in the eglibc source tree to see which symbols were exported for which versions+architecture. `res_init` lies in libc6.so and its history can be seen in `abilist/libc.abilist`. With glibc 2.3, all function symbols got exported prefixed with `__` like all private symbols of the glibc. For the sake of compatiblity with older variants, older symbols still exists, but _only_ on architectures which already had a release with the symbols. That's was never a `res_send` defined on x86_64, for example. It looks like to ideally solve this, proper probing logic must be implemented to support all OS, architectures and glibc variants. The attached patch uses a more brute force approach and always try the `__` variants if a `res_*` fails to be found. But the change that was made in Torsocks 1.2 in expansion_table.h should have made the overloaded `res_send` complain about not being able to find `res_send` within the RTLD_NEXT context. As we have seen no report of such message, I wonder if there is that many applications that uses libresolv directly, and if those parts of torsocks are really needed… Robert, your opinion on that last statement would be of real interest. Cheers, -- Jérémy Bobbio .''`. lu...@debian.org : :Ⓐ : # apt-get install anarchism `. `'` `-
--- torsocks-1.2.orig/src/torsocks.c +++ torsocks-1.2/src/torsocks.c @@ -150,10 +150,11 @@ void torsocks_init(void) dlerror(); #ifndef USE_OLD_DLSYM #ifdef SUPPORT_RES_API - if ((realres_init = dlsym(RTLD_NEXT, "res_init")) == NULL) + if (((realres_init = dlsym(RTLD_NEXT, "res_init")) == NULL) && + ((realres_init = dlsym(RTLD_NEXT, "__res_init")) == NULL)) LOAD_ERROR("res_init", MSGERR); #endif - #define PATCH_TABLE_EXPANSION(e,r,s,n,b,m) if ((real##n = dlsym(RTLD_NEXT, m)) == NULL) LOAD_ERROR(m, MSG##e); + #define PATCH_TABLE_EXPANSION(e,r,s,n,b,m) if (((real##n = dlsym(RTLD_NEXT, m)) == NULL) && ((real##n = dlsym(RTLD_NEXT, "__" m)) == NULL)) LOAD_ERROR(m, MSG##e); #include "expansion_table.h" #undef PATCH_TABLE_EXPANSION #else @@ -856,7 +857,8 @@ int res_init(void) { int rc; - if (!realres_init && ((realres_init = dlsym(RTLD_NEXT, "res_init")) == NULL)) + if (!realres_init && ((realres_init = dlsym(RTLD_NEXT, "res_init")) == NULL) && + ((realres_init = dlsym(RTLD_NEXT, "__res_init")) == NULL)) LOAD_ERROR("res_init", MSGERR); show_msg(MSGTEST, "Got res_init request\n"); @@ -877,7 +879,8 @@ int EXPAND_GUTS_NAME(res_query)(RES_QUER { int rc; - if (!original_res_query && ((original_res_query = dlsym(RTLD_NEXT, "res_query")) == NULL)) + if (!original_res_query && ((original_res_query = dlsym(RTLD_NEXT, "res_query")) == NULL) && + ((original_res_query = dlsym(RTLD_NEXT, "__res_query")) == NULL)) LOAD_ERROR("res_query", MSGERR); show_msg(MSGTEST, "Got res_query request\n"); @@ -903,7 +906,8 @@ int EXPAND_GUTS_NAME(res_querydomain)(RE int rc; if (!original_res_querydomain && - ((original_res_querydomain = dlsym(RTLD_NEXT, "res_querydomain")) == NULL)) + ((original_res_querydomain = dlsym(RTLD_NEXT, "res_querydomain")) == NULL) && + ((original_res_querydomain = dlsym(RTLD_NEXT, "__res_querydomain")) == NULL)) LOAD_ERROR("res_querydoimain", MSGERR); show_msg(MSGDEBUG, "Got res_querydomain request\n"); @@ -929,7 +933,8 @@ int EXPAND_GUTS_NAME(res_search)(RES_SEA int rc; if (!original_res_search && - ((original_res_search = dlsym(RTLD_NEXT, "res_search")) == NULL)) + ((original_res_search = dlsym(RTLD_NEXT, "res_search")) == NULL) && + ((original_res_search = dlsym(RTLD_NEXT, "__res_search")) == NULL)) LOAD_ERROR("res_search", MSGERR); show_msg(MSGTEST, "Got res_search request\n"); @@ -954,7 +959,8 @@ int EXPAND_GUTS_NAME(res_send)(RES_SEND_ { int rc; - if (!original_res_send && ((original_res_send = dlsym(RTLD_NEXT, "res_send")) == NULL)) + if (!original_res_send && ((original_res_send = dlsym(RTLD_NEXT, "res_send")) == NULL) + && ((original_res_send = dlsym(RTLD_NEXT, "__res_send")) == NULL)) LOAD_ERROR("res_send", MSGERR); show_msg(MSGTEST, "Got res_send request\n"); --- torsocks-1.2.orig/src/expansion_table.h +++ torsocks-1.2/src/expansion_table.h @@ -76,12 +76,7 @@ /*RES_FUNC (ERR, int, RES_INIT_, res_init, res_init, "res_init") */ RES_FUNC (ERR, int, RES_QUERY_, res_query, res_query, "res_query") RES_FUNC (ERR, int, RES_SEARCH_, res_search, res_search, "res_search") -#if defined(__APPLE__) || defined(__darwin__) RES_FUNC (ERR, int, RES_SEND_, res_send, res_send, "res_send") -#else -/* It is a bit of a mystery why this is required on Linux. See http://code.google.com/p/torsocks/issues/detail?id=3 */ -RES_FUNC (ERR, int, RES_SEND_, res_send, res_send, "__res_send") -#endif RES_FUNC (ERR, int, RES_QUERYDOMAIN_, res_querydomain, res_querydomain, "res_querydomain") DNS_FUNC (ERR, struct hostent *, GETHOSTBYNAME_, gethostbyname, gethostbyname, "gethostbyname")
signature.asc
Description: Digital signature