Module Name:    src
Committed By:   christos
Date:           Fri Oct  4 16:20:35 UTC 2013

Modified Files:
        src/sys/netinet: tcp_usrreq.c

Log Message:
PR/48098: Brian Marcotte: Avoid kernel assertion for embryonic sockets that
don't have credentials yet.
XXX: pullup-6


To generate a diff of this commit:
cvs rdiff -u -r1.167 -r1.168 src/sys/netinet/tcp_usrreq.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netinet/tcp_usrreq.c
diff -u src/sys/netinet/tcp_usrreq.c:1.167 src/sys/netinet/tcp_usrreq.c:1.168
--- src/sys/netinet/tcp_usrreq.c:1.167	Sun Sep 15 10:45:50 2013
+++ src/sys/netinet/tcp_usrreq.c	Fri Oct  4 12:20:35 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_usrreq.c,v 1.167 2013/09/15 14:45:50 martin Exp $	*/
+/*	$NetBSD: tcp_usrreq.c,v 1.168 2013/10/04 16:20:35 christos Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -95,7 +95,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tcp_usrreq.c,v 1.167 2013/09/15 14:45:50 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_usrreq.c,v 1.168 2013/10/04 16:20:35 christos Exp $");
 
 #include "opt_inet.h"
 #include "opt_ipsec.h"
@@ -1164,18 +1164,20 @@ sysctl_net_inet_ip_ports(SYSCTLFN_ARGS)
 static inline int
 copyout_uid(struct socket *sockp, void *oldp, size_t *oldlenp)
 {
-	size_t sz;
-	int error;
-	uid_t uid;
-
-	uid = kauth_cred_geteuid(sockp->so_cred);
 	if (oldp) {
+		size_t sz;
+		uid_t uid;
+		int error;
+
+		if (sockp->so_cred == NULL)
+			return EPERM;
+
+		uid = kauth_cred_geteuid(sockp->so_cred);
 		sz = MIN(sizeof(uid), *oldlenp);
-		error = copyout(&uid, oldp, sz);
-		if (error)
+		if ((error = copyout(&uid, oldp, sz)) != 0)
 			return error;
 	}
-	*oldlenp = sizeof(uid);
+	*oldlenp = sizeof(uid_t);
 	return 0;
 }
 

Reply via email to