Skip to contentSkip to conversation

unix domain sockets bugfix

PATCH In review Balazs Scheidler 3 participants 5 messages Oct 7, 2002

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 unix domain sockets bugfix

Hi,

I've found a bug with unix domain sockets in both kernels 2.2 and 2.4. If the program issues a recvfrom() on a SOCK_DGRAM socket, and the sender had no name, the sockaddr returned is not filled in.

The returned socklen is 2, but the sockaddr.family is not touched. A fix is below:

af_unix.c renamed from af_unix.c~ +3 -0
@@ -1392,6 +1392,9 @@
 		       sk->protinfo.af_unix.addr->name,
 		       sk->protinfo.af_unix.addr->len);
 	}
+	else {
+		((struct sockaddr *) msg->msg_name)->sa_family = AF_UNIX;
+	}
 }
 
 static int unix_dgram_recvmsg(struct socket *sock, struct msghdr *msg, int size,
Signature · 2 lines
Bazsi
PGP info: KeyID 9AF8D0A9 Fingerprint CD27 CFB0 802C 0944 9CFD 804E C82C 8EB1
#1 lore raw

From: Balazs Scheidler <[email protected]>
Date: Mon, 7 Oct 2002 09:35:32 +0200

The returned socklen is 2, but the sockaddr.family is not touched. A fix is below:

Since msg->msg_namelen is zero, msg->msg_name should not be interpreted in any way at all.

#2 lore raw
Quoted 8 lines · David S. Miller

From: Balazs Scheidler <[email protected]>
Date: Mon, 7 Oct 2002 09:35:32 +0200

The returned socklen is 2, but the sockaddr.family is not touched. A fix is below:

Since msg->msg_namelen is zero, msg->msg_name should not be interpreted in any way at all.

You would be right, if it would be zero, but it isn't:

373 res = recvfrom(closure->fd, buffer, length, 0, (struct sockaddr *) addr, (socklen_t *) addrlen);
(gdb) n
375 if (*addrlen == 2) {
(gdb) p *addrlen
$2 = 2

Checking out the code again:

static void unix_copy_addr(struct msghdr *msg, struct sock *sk)

{
        msg->msg_namelen = sizeof(short);
        if (sk->protinfo.af_unix.addr) {
                msg->msg_namelen=sk->protinfo.af_unix.addr->len;
                memcpy(msg->msg_name,
                       sk->protinfo.af_unix.addr->name,
                       sk->protinfo.af_unix.addr->len);
        }
}

namelen is explicitly set to sizeof(short) == 2.

This is 2.4.18

Signature · 2 lines
Bazsi
PGP info: KeyID 9AF8D0A9 Fingerprint CD27 CFB0 802C 0944 9CFD 804E C82C 8EB1