[PATCH] fix AF_UNIX socketpair peercred

From: Malcolm Beattie (mbeattie@sable.ox.ac.uk)
Date: Thu May 11 2000 - 05:09:30 EST


In both 2.2.x and 2.3.x, socketpair(AF_UNIX,...) fails to initialise
the peercred part of its skbuffs. That means that getsockopt with
SO_PEERCRED on such sockets reads uninitialised (and wrong) data.
Here's a patch for 2.2 and 2.3 (basically the same modulo fuzz).
It's untested but it's short enough that it "can't be wrong (TM)".
Please apply.

[This doesn't apply to 2.0 which doesn't have peercreds. It bit me
when trying to write a reliable autoconf script to check existence of
SO_PEERCRED (yes it's Linux-only at the moment but we can hope).]

-------------------- patch against 2.3.99pre6 --------------------
--- net/unix/af_unix.c.ORI Wed May 3 13:01:19 2000
+++ net/unix/af_unix.c Thu May 11 10:50:06 2000
@@ -45,6 +45,7 @@
  * dgram receiver.
  * Artur Skawina : Hash function optimizations
  * Alexey Kuznetsov : Full scale SMP. Lot of bugs are introduced 8)
+ * Malcolm Beattie : Set peercred for socketpair
  *
  *
  * Known differences from reference BSD that was tested:
@@ -947,6 +948,9 @@
         sock_hold(skb);
         unix_peer(ska)=skb;
         unix_peer(skb)=ska;
+ ska->peercred.pid = skb->peercred.pid = current->pid;
+ ska->peercred.uid = skb->peercred.uid = current->euid;
+ ska->peercred.gid = skb->peercred.gid = current->egid;
 
         if (ska->type != SOCK_DGRAM)
         {
------------------ end patch against 2.3.99pre6 ------------------

---------------------- patch against 2.2.12 ----------------------
--- net/unix/af_unix.c.ORI Thu May 11 10:52:46 2000
+++ net/unix/af_unix.c Thu May 11 10:56:15 2000
@@ -43,6 +43,7 @@
  * number of socks to 2*max_files and
  * the number of skb queueable in the
  * dgram receiver.
+ * Malcolm Beattie : Set peercred for socketpair
  *
  * Known differences from reference BSD that was tested:
  *
@@ -814,6 +815,9 @@
         unix_lock(skb);
         unix_peer(ska)=skb;
         unix_peer(skb)=ska;
+ ska->peercred.pid = skb->peercred.pid = current->pid;
+ ska->peercred.uid = skb->peercred.uid = current->euid;
+ ska->peercred.gid = skb->peercred.gid = current->egid;
 
         if (ska->type != SOCK_DGRAM)
         {
-------------------- end patch against 2.2.12 --------------------

--Malcolm

-- 
Malcolm Beattie <mbeattie@sable.ox.ac.uk>
Unix Systems Programmer
Oxford University Computing Services

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Mon May 15 2000 - 21:00:17 EST