about summary refs log tree commit diff
path: root/sysdeps/unix/sysv/linux/netlinkaccess.h
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2015-11-09 12:48:41 +0100
committerFlorian Weimer <fweimer@redhat.com>2015-11-09 12:48:41 +0100
commit2eecc8afd02d8c65cf098cbae4de87f332dc21bd (patch)
treea36cb50020b3836a379e515af5d1874d8d8ea92f /sysdeps/unix/sysv/linux/netlinkaccess.h
parentf3d18efb8a720121066dc3401e822043beb98cde (diff)
downloadglibc-2eecc8afd02d8c65cf098cbae4de87f332dc21bd.tar.gz
glibc-2eecc8afd02d8c65cf098cbae4de87f332dc21bd.tar.xz
glibc-2eecc8afd02d8c65cf098cbae4de87f332dc21bd.zip
Terminate process on invalid netlink response from kernel [BZ #12926]
The recvmsg system calls for netlink sockets have been particularly
prone to picking up unrelated data after a file descriptor race
(where the descriptor is closed and reopened concurrently in a
multi-threaded process, as the result of a file descriptor
management issue elsewhere).  This commit adds additional error
checking and aborts the process if a datagram of unexpected length
(without the netlink header) is received, or an error code which
cannot happen due to the way the netlink socket is used.

	[BZ #12926]
	Terminate process on invalid netlink response.
	* sysdeps/unix/sysv/linux/netlinkaccess.h
	(__netlink_assert_response): Declare.
	* sysdeps/unix/sysv/linux/netlink_assert_response.c: New file.
	* sysdeps/unix/sysv/linux/Makefile [$(subdir) == inet]
	(sysdep_routines): Add netlink_assert_response.
	* sysdeps/unix/sysv/linux/check_native.c (__check_native): Call
	__netlink_assert_response.
	* sysdeps/unix/sysv/linux/check_pf.c (make_request): Likewise.
	* sysdeps/unix/sysv/linux/ifaddrs.c (__netlink_request): Likewise.
	* sysdeps/unix/sysv/linux/Versions (GLIBC_PRIVATE): Add
	__netlink_assert_response.
Diffstat (limited to 'sysdeps/unix/sysv/linux/netlinkaccess.h')
-rw-r--r--sysdeps/unix/sysv/linux/netlinkaccess.h6
1 files changed, 6 insertions, 0 deletions
diff --git a/sysdeps/unix/sysv/linux/netlinkaccess.h b/sysdeps/unix/sysv/linux/netlinkaccess.h
index c204b67a20..01ac35c641 100644
--- a/sysdeps/unix/sysv/linux/netlinkaccess.h
+++ b/sysdeps/unix/sysv/linux/netlinkaccess.h
@@ -19,6 +19,7 @@
 #define _NETLINKACCESS_H 1
 
 #include <stdint.h>
+#include <sys/types.h>
 #include <asm/types.h>
 #include <linux/netlink.h>
 #include <linux/rtnetlink.h>
@@ -48,5 +49,10 @@ extern void __netlink_close (struct netlink_handle *h);
 extern void __netlink_free_handle (struct netlink_handle *h);
 extern int __netlink_request (struct netlink_handle *h, int type);
 
+/* Terminate the process if RESULT is an invalid recvmsg result for
+   the netlink socket FD.  */
+void __netlink_assert_response (int fd, ssize_t result)
+  internal_function;
+libc_hidden_proto (__netlink_assert_response)
 
 #endif /* netlinkaccess.h */