Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix resolver if_* namespace (bug 17717).
Resolver code, brought in by pthreads (at least), uses if_* interfaces
that weren't in POSIX before 2001, resulting in linknamespace
failures.  This patch changes those interfaces to be weak aliases of
__if_* and makes the resolver use __if_* directly.

Tested for x86_64 (testsuite, and that disassembly of installed shared
libraries is unchanged by this patch).

	[BZ #17717]
	* inet/if_index.c (if_nametoindex): Rename to __if_nametoindex and
	define as weak alias of __if_nametoindex.  Use libc_hidden_weak.
	(if_indextoname): Rename to __if_indextoname and define as weak
	alias of __if_indextoname.  Use libc_hidden_weak.
	(if_freenameindex): Rename to __if_freenameindex and define as
	weak alias of __if_freenameindex.
	(if_nameindex): Rename to __if_nameindex and define as weak alias
	of __if_nameindex.
	* sysdeps/mach/hurd/if_index.c (if_nametoindex): Rename to
	__if_nametoindex and define as weak alias of __if_nametoindex.
	Use libc_hidden_weak.
	(if_freenameindex): Rename to __if_freenameindex and define as
	weak alias of __if_freenameindex.
	(if_nameindex): Rename to __if_nameindex and define as weak alias
	of __if_nameindex.
	(if_indextoname): Rename to __if_indextoname and define as weak
	alias of __if_indextoname.  Use libc_hidden_weak.
	* sysdeps/unix/sysv/linux/if_index.c (if_nametoindex): Rename to
	__if_nametoindex and define as weak alias of __if_nametoindex.
	Use libc_hidden_weak.
	(if_freenameindex): Rename to __if_freenameindex and define as
	weak alias of __if_freenameindex.  Use libc_hidden_weak.
	(if_nameindex_netlink): Use __if_freenameindex instead of
	if_freenameindex.
	(if_nameindex): Rename to __if_nameindex and define as weak alias
	of __if_nameindex.  Use libc_hidden_weak.
	(if_indextoname): Rename to __if_indextoname and define as weak
	alias of __if_indextoname.  Use libc_hidden_weak.
	* include/net/if.h [!_ISOMAC] (__if_nametoindex): Declare and use
	libc_hidden_proto.
	[!_ISOMAC] (__if_freenameindex): Likewise.
	* resolv/res_init.c (__res_vinit): Use __if_nametoindex instead of
	if_nametoindex.
	* conform/Makefile (test-xfail-XPG4/grp.h/linknamespace): Remove
	variable.
	(test-xfail-XPG4/pwd.h/linknamespace): Likewise.
	(test-xfail-UNIX98/aio.h/linknamespace): Likewise.
	(test-xfail-UNIX98/grp.h/linknamespace): Likewise.
	(test-xfail-UNIX98/pthread.h/linknamespace): Likewise.
	(test-xfail-UNIX98/pwd.h/linknamespace): Likewise.
	(test-xfail-UNIX98/sched.h/linknamespace): Likewise.
	(test-xfail-UNIX98/time.h/linknamespace): Likewise.
  • Loading branch information
Joseph Myers committed Dec 16, 2014
1 parent d003ada commit 9a44d53
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 31 deletions.
44 changes: 44 additions & 0 deletions ChangeLog
@@ -1,5 +1,49 @@
2014-12-16 Joseph Myers <joseph@codesourcery.com>

[BZ #17717]
* inet/if_index.c (if_nametoindex): Rename to __if_nametoindex and
define as weak alias of __if_nametoindex. Use libc_hidden_weak.
(if_indextoname): Rename to __if_indextoname and define as weak
alias of __if_indextoname. Use libc_hidden_weak.
(if_freenameindex): Rename to __if_freenameindex and define as
weak alias of __if_freenameindex.
(if_nameindex): Rename to __if_nameindex and define as weak alias
of __if_nameindex.
* sysdeps/mach/hurd/if_index.c (if_nametoindex): Rename to
__if_nametoindex and define as weak alias of __if_nametoindex.
Use libc_hidden_weak.
(if_freenameindex): Rename to __if_freenameindex and define as
weak alias of __if_freenameindex.
(if_nameindex): Rename to __if_nameindex and define as weak alias
of __if_nameindex.
(if_indextoname): Rename to __if_indextoname and define as weak
alias of __if_indextoname. Use libc_hidden_weak.
* sysdeps/unix/sysv/linux/if_index.c (if_nametoindex): Rename to
__if_nametoindex and define as weak alias of __if_nametoindex.
Use libc_hidden_weak.
(if_freenameindex): Rename to __if_freenameindex and define as
weak alias of __if_freenameindex. Use libc_hidden_weak.
(if_nameindex_netlink): Use __if_freenameindex instead of
if_freenameindex.
(if_nameindex): Rename to __if_nameindex and define as weak alias
of __if_nameindex. Use libc_hidden_weak.
(if_indextoname): Rename to __if_indextoname and define as weak
alias of __if_indextoname. Use libc_hidden_weak.
* include/net/if.h [!_ISOMAC] (__if_nametoindex): Declare and use
libc_hidden_proto.
[!_ISOMAC] (__if_freenameindex): Likewise.
* resolv/res_init.c (__res_vinit): Use __if_nametoindex instead of
if_nametoindex.
* conform/Makefile (test-xfail-XPG4/grp.h/linknamespace): Remove
variable.
(test-xfail-XPG4/pwd.h/linknamespace): Likewise.
(test-xfail-UNIX98/aio.h/linknamespace): Likewise.
(test-xfail-UNIX98/grp.h/linknamespace): Likewise.
(test-xfail-UNIX98/pthread.h/linknamespace): Likewise.
(test-xfail-UNIX98/pwd.h/linknamespace): Likewise.
(test-xfail-UNIX98/sched.h/linknamespace): Likewise.
(test-xfail-UNIX98/time.h/linknamespace): Likewise.

* conform/Makefile (test-xfail-UNIX98/semaphore.h/linknamespace):
Remove variable.
(test-xfail-XOPEN2K/semaphore.h/linknamespace): Likewise.
Expand Down
2 changes: 1 addition & 1 deletion NEWS
Expand Up @@ -14,7 +14,7 @@ Version 2.21
17363, 17370, 17371, 17411, 17460, 17475, 17485, 17501, 17506, 17508,
17522, 17555, 17570, 17571, 17572, 17573, 17574, 17581, 17582, 17583,
17584, 17585, 17589, 17594, 17601, 17608, 17616, 17625, 17630, 17633,
17634, 17647, 17653, 17657, 17664, 17665, 17668, 17682.
17634, 17647, 17653, 17657, 17664, 17665, 17668, 17682, 17717.

* CVE-2104-7817 The wordexp function could ignore the WRDE_NOCMD flag
under certain input conditions resulting in the execution of a shell for
Expand Down
8 changes: 0 additions & 8 deletions conform/Makefile
Expand Up @@ -359,10 +359,8 @@ test-xfail-XPG4/ctype.h/linknamespace = yes
test-xfail-XPG4/fmtmsg.h/linknamespace = yes
test-xfail-XPG4/fnmatch.h/linknamespace = yes
test-xfail-XPG4/glob.h/linknamespace = yes
test-xfail-XPG4/grp.h/linknamespace = yes
test-xfail-XPG4/libgen.h/linknamespace = yes
test-xfail-XPG4/netdb.h/linknamespace = yes
test-xfail-XPG4/pwd.h/linknamespace = yes
test-xfail-XPG4/regex.h/linknamespace = yes
test-xfail-XPG4/search.h/linknamespace = yes
test-xfail-XPG4/stdio.h/linknamespace = yes
Expand All @@ -381,24 +379,18 @@ test-xfail-POSIX/semaphore.h/linknamespace = yes
test-xfail-POSIX/time.h/linknamespace = yes
test-xfail-POSIX/unistd.h/linknamespace = yes
test-xfail-POSIX/wordexp.h/linknamespace = yes
test-xfail-UNIX98/aio.h/linknamespace = yes
test-xfail-UNIX98/ctype.h/linknamespace = yes
test-xfail-UNIX98/fmtmsg.h/linknamespace = yes
test-xfail-UNIX98/fnmatch.h/linknamespace = yes
test-xfail-UNIX98/glob.h/linknamespace = yes
test-xfail-UNIX98/grp.h/linknamespace = yes
test-xfail-UNIX98/libgen.h/linknamespace = yes
test-xfail-UNIX98/mqueue.h/linknamespace = yes
test-xfail-UNIX98/netdb.h/linknamespace = yes
test-xfail-UNIX98/pthread.h/linknamespace = yes
test-xfail-UNIX98/pwd.h/linknamespace = yes
test-xfail-UNIX98/regex.h/linknamespace = yes
test-xfail-UNIX98/sched.h/linknamespace = yes
test-xfail-UNIX98/search.h/linknamespace = yes
test-xfail-UNIX98/stdio.h/linknamespace = yes
test-xfail-UNIX98/stdlib.h/linknamespace = yes
test-xfail-UNIX98/syslog.h/linknamespace = yes
test-xfail-UNIX98/time.h/linknamespace = yes
test-xfail-UNIX98/unistd.h/linknamespace = yes
test-xfail-UNIX98/wchar.h/linknamespace = yes
test-xfail-UNIX98/wordexp.h/linknamespace = yes
Expand Down
4 changes: 4 additions & 0 deletions include/net/if.h
Expand Up @@ -4,9 +4,13 @@

#ifndef _ISOMAC
libc_hidden_proto (if_nametoindex)
extern __typeof (if_nametoindex) __if_nametoindex;
libc_hidden_proto (__if_nametoindex)
libc_hidden_proto (if_indextoname)
libc_hidden_proto (if_nameindex)
libc_hidden_proto (if_freenameindex)
extern __typeof (if_freenameindex) __if_freenameindex;
libc_hidden_proto (__if_freenameindex)
#endif

#endif
17 changes: 11 additions & 6 deletions inet/if_index.c
Expand Up @@ -20,35 +20,40 @@
#include <stddef.h>

unsigned int
if_nametoindex (const char *ifname)
__if_nametoindex (const char *ifname)
{
__set_errno (ENOSYS);
return 0;
}
libc_hidden_def (if_nametoindex)
libc_hidden_def (__if_nametoindex)
weak_alias (__if_nametoindex, if_nametoindex)
libc_hidden_weak (if_nametoindex)
stub_warning (if_nametoindex)

char *
if_indextoname (unsigned int ifindex, char *ifname)
__if_indextoname (unsigned int ifindex, char *ifname)
{
__set_errno (ENOSYS);
return NULL;
}
libc_hidden_def (if_indextoname)
weak_alias (__if_indextoname, if_indextoname)
libc_hidden_weak (if_indextoname)
stub_warning (if_indextoname)

void
if_freenameindex (struct if_nameindex *ifn)
__if_freenameindex (struct if_nameindex *ifn)
{
}
weak_alias (__if_freenameindex, if_freenameindex)
stub_warning (if_freenameindex)

struct if_nameindex *
if_nameindex (void)
__if_nameindex (void)
{
__set_errno (ENOSYS);
return NULL;
}
weak_alias (__if_nameindex, if_nameindex)
stub_warning (if_nameindex)

#if 0
Expand Down
2 changes: 1 addition & 1 deletion resolv/res_init.c
Expand Up @@ -341,7 +341,7 @@ __res_vinit(res_state statp, int preinit) {
if (IN6_IS_ADDR_LINKLOCAL (&a6)
|| IN6_IS_ADDR_MC_LINKLOCAL (&a6)) {
sa6->sin6_scope_id
= if_nametoindex (el + 1);
= __if_nametoindex (el + 1);
if (sa6->sin6_scope_id != 0)
try_numericscope = 0;
}
Expand Down
17 changes: 11 additions & 6 deletions sysdeps/mach/hurd/if_index.c
Expand Up @@ -29,7 +29,7 @@
/* Return the interface index corresponding to interface IFNAME.
On error, return 0. */
unsigned int
if_nametoindex (const char *ifname)
__if_nametoindex (const char *ifname)
{
struct ifreq ifr;
int fd = __opensock ();
Expand All @@ -49,11 +49,13 @@ if_nametoindex (const char *ifname)
__close (fd);
return ifr.ifr_ifindex;
}
libc_hidden_def (if_nametoindex)
libc_hidden_def (__if_nametoindex)
weak_alias (__if_nametoindex, if_nametoindex)
libc_hidden_weak (if_nametoindex)

/* Free the structure IFN returned by if_nameindex. */
void
if_freenameindex (struct if_nameindex *ifn)
__if_freenameindex (struct if_nameindex *ifn)
{
struct if_nameindex *ptr = ifn;
while (ptr->if_name || ptr->if_index)
Expand All @@ -63,12 +65,13 @@ if_freenameindex (struct if_nameindex *ifn)
}
free (ifn);
}
weak_alias (__if_freenameindex, if_freenameindex)

/* Return an array of if_nameindex structures, one for each network
interface present, plus one indicating the end of the array. On
error, return NULL. */
struct if_nameindex *
if_nameindex (void)
__if_nameindex (void)
{
error_t err = 0;
char data[2048];
Expand Down Expand Up @@ -148,12 +151,13 @@ if_nameindex (void)
__set_errno (err);
return idx;
}
weak_alias (__if_nameindex, if_nameindex)

/* Store the name of the interface corresponding to index IFINDEX in
IFNAME (which has space for at least IFNAMSIZ characters). Return
IFNAME, or NULL on error. */
char *
if_indextoname (unsigned int ifindex, char *ifname)
__if_indextoname (unsigned int ifindex, char *ifname)
{
struct ifreq ifr;
int fd = __opensock ();
Expand All @@ -175,7 +179,8 @@ if_indextoname (unsigned int ifindex, char *ifname)
__close (fd);
return strncpy (ifname, ifr.ifr_name, IFNAMSIZ);
}
libc_hidden_def (if_indextoname)
weak_alias (__if_indextoname, if_indextoname)
libc_hidden_weak (if_indextoname)

#if 0
void
Expand Down
24 changes: 15 additions & 9 deletions sysdeps/unix/sysv/linux/if_index.c
Expand Up @@ -31,7 +31,7 @@


unsigned int
if_nametoindex (const char *ifname)
__if_nametoindex (const char *ifname)
{
#ifndef SIOCGIFINDEX
__set_errno (ENOSYS);
Expand All @@ -56,11 +56,13 @@ if_nametoindex (const char *ifname)
return ifr.ifr_ifindex;
#endif
}
libc_hidden_def (if_nametoindex)
libc_hidden_def (__if_nametoindex)
weak_alias (__if_nametoindex, if_nametoindex)
libc_hidden_weak (if_nametoindex)


void
if_freenameindex (struct if_nameindex *ifn)
__if_freenameindex (struct if_nameindex *ifn)
{
struct if_nameindex *ptr = ifn;
while (ptr->if_name || ptr->if_index)
Expand All @@ -70,7 +72,9 @@ if_freenameindex (struct if_nameindex *ifn)
}
free (ifn);
}
libc_hidden_def (if_freenameindex)
libc_hidden_def (__if_freenameindex)
weak_alias (__if_freenameindex, if_freenameindex)
libc_hidden_weak (if_freenameindex)


static struct if_nameindex *
Expand Down Expand Up @@ -162,7 +166,7 @@ if_nameindex_netlink (void)
if (idx[nifs].if_name == NULL)
{
idx[nifs].if_index = 0;
if_freenameindex (idx);
__if_freenameindex (idx);
idx = NULL;
goto nomem;
}
Expand All @@ -189,7 +193,7 @@ if_nameindex_netlink (void)


struct if_nameindex *
if_nameindex (void)
__if_nameindex (void)
{
#ifndef SIOCGIFINDEX
__set_errno (ENOSYS);
Expand All @@ -199,11 +203,12 @@ if_nameindex (void)
return result;
#endif
}
libc_hidden_def (if_nameindex)
weak_alias (__if_nameindex, if_nameindex)
libc_hidden_weak (if_nameindex)


char *
if_indextoname (unsigned int ifindex, char *ifname)
__if_indextoname (unsigned int ifindex, char *ifname)
{
/* We may be able to do the conversion directly, rather than searching a
list. This ioctl is not present in kernels before version 2.1.50. */
Expand Down Expand Up @@ -232,4 +237,5 @@ if_indextoname (unsigned int ifindex, char *ifname)
else
return strncpy (ifname, ifr.ifr_name, IFNAMSIZ);
}
libc_hidden_def (if_indextoname)
weak_alias (__if_indextoname, if_indextoname)
libc_hidden_weak (if_indextoname)

0 comments on commit 9a44d53

Please sign in to comment.