Module Name: src
Committed By: drochner
Date: Thu Aug 1 19:33:21 UTC 2013
Modified Files:
src/sys/kern: uipc_usrreq.c
Log Message:
In unp_externalize, don't do anything if an SCM_RIGHTS control message
was sent with zero file descriptors in it. Otherwise, a zero-length
temporary storage would be allocated which triggers panic on DIAGNOSTIC
kernels (but is harmless for release kernels).
reviewed by Taylor R Campbell
To generate a diff of this commit:
cvs rdiff -u -r1.142 -r1.143 src/sys/kern/uipc_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/kern/uipc_usrreq.c
diff -u src/sys/kern/uipc_usrreq.c:1.142 src/sys/kern/uipc_usrreq.c:1.143
--- src/sys/kern/uipc_usrreq.c:1.142 Thu Jun 27 18:54:31 2013
+++ src/sys/kern/uipc_usrreq.c Thu Aug 1 19:33:21 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: uipc_usrreq.c,v 1.142 2013/06/27 18:54:31 christos Exp $ */
+/* $NetBSD: uipc_usrreq.c,v 1.143 2013/08/01 19:33:21 drochner Exp $ */
/*-
* Copyright (c) 1998, 2000, 2004, 2008, 2009 The NetBSD Foundation, Inc.
@@ -96,7 +96,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_usrreq.c,v 1.142 2013/06/27 18:54:31 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_usrreq.c,v 1.143 2013/08/01 19:33:21 drochner Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -1242,6 +1242,8 @@ unp_externalize(struct mbuf *rights, str
const size_t nfds = (cm->cmsg_len - CMSG_ALIGN(sizeof(*cm))) /
sizeof(file_t *);
+ if (nfds == 0)
+ goto noop;
int * const fdp = kmem_alloc(nfds * sizeof(int), KM_SLEEP);
rw_enter(&p->p_cwdi->cwdi_lock, RW_READER);
@@ -1346,16 +1348,16 @@ unp_externalize(struct mbuf *rights, str
cm->cmsg_len = CMSG_LEN(0);
rights->m_len = CMSG_SPACE(0);
}
+ rw_exit(&p->p_cwdi->cwdi_lock);
+ kmem_free(fdp, nfds * sizeof(int));
+ noop:
/*
* Don't disclose kernel memory in the alignment space.
*/
KASSERT(cm->cmsg_len <= rights->m_len);
memset(&mtod(rights, char *)[cm->cmsg_len], 0, rights->m_len -
cm->cmsg_len);
-
- rw_exit(&p->p_cwdi->cwdi_lock);
- kmem_free(fdp, nfds * sizeof(int));
return error;
}