]> git.puffer.fish Git - mirror/frr.git/commitdiff
zebra: raise the privileges before calling socket()
authorMichal Sekletar <msekleta@redhat.com>
Fri, 16 May 2014 14:13:43 +0000 (14:13 +0000)
committerDavid Lamparter <equinox@opensourcerouting.org>
Tue, 27 May 2014 17:50:45 +0000 (19:50 +0200)
Because of recent changes when creating AF_NETLINK socket, kernel will
cache capabilities of the caller and if file descriptor is used or
otherwise handed to another process it will check that current user has
necessary capabilities to use the socket. Hence we need to ensure we
have necessary capabilities when creating the socket and at the time we
use the socket.

See: http://www.spinics.net/lists/netdev/msg280198.html

Signed-off-by: Michal Sekletar <msekleta@redhat.com>
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
zebra/rt_netlink.c

index ba0b0d7de2e12addf19512c9a80f11aac76c3ea9..6a802f6906007968630f2fa89b7c21dc83eb053b 100644 (file)
@@ -162,6 +162,12 @@ netlink_socket (struct nlsock *nl, unsigned long groups)
   int namelen;
   int save_errno;
 
+  if (zserv_privs.change (ZPRIVS_RAISE))
+    {
+      zlog (NULL, LOG_ERR, "Can't raise privileges");
+      return -1;
+    }
+
   sock = socket (AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
   if (sock < 0)
     {
@@ -175,12 +181,6 @@ netlink_socket (struct nlsock *nl, unsigned long groups)
   snl.nl_groups = groups;
 
   /* Bind the socket to the netlink structure for anything. */
-  if (zserv_privs.change (ZPRIVS_RAISE))
-    {
-      zlog (NULL, LOG_ERR, "Can't raise privileges");
-      return -1;
-    }
-
   ret = bind (sock, (struct sockaddr *) &snl, sizeof snl);
   save_errno = errno;
   if (zserv_privs.change (ZPRIVS_LOWER))