From f324e3cfdf28d60d80c68f24ddf808e39bf016e4 Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Wed, 10 Jul 2002 00:04:57 +0000 Subject: [PATCH] reviewed: bwelling 1241. [bug] Drop received UDP messsages with a zero source port as these are invariably forged. [RT #2621] --- CHANGES | 3 +++ lib/isc/include/isc/msgs.h | 3 ++- lib/isc/unix/socket.c | 14 ++++++++++++-- lib/isc/win32/socket.c | 14 ++++++++++++-- 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/CHANGES b/CHANGES index 867e9fa2e8..d706a3ed27 100644 --- a/CHANGES +++ b/CHANGES @@ -43,6 +43,9 @@ 1273. [bug] The dnssec system test failed to remove the correct files. +1241. [bug] Drop received UDP messsages with a zero source port + as these are invariably forged. [RT #2621] + --- 9.2.1 released --- 1271. [port] win32: a make file contained absolute version specific diff --git a/lib/isc/include/isc/msgs.h b/lib/isc/include/isc/msgs.h index 1706503607..a8c2f4593a 100644 --- a/lib/isc/include/isc/msgs.h +++ b/lib/isc/include/isc/msgs.h @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: msgs.h,v 1.5 2001/04/26 23:45:55 gson Exp $ */ +/* $Id: msgs.h,v 1.5.2.1 2002/07/10 00:04:53 marka Exp $ */ #ifndef ISC_MSGS_H #define ISC_MSGS_H 1 @@ -144,6 +144,7 @@ #define ISC_MSG_BOUND 1417 /* "bound" */ #define ISC_MSG_ACCEPTRETURNED 1418 /* accept() returned %d/%s */ #define ISC_MSG_TOOMANYFDS 1419 /* %s: too many open file descriptors */ +#define ISC_MSG_ZEROPORT 1420 /* dropping source port zero packet */ #define ISC_MSG_AWAKE 1502 /* "awake" */ #define ISC_MSG_WORKING 1503 /* "working" */ diff --git a/lib/isc/unix/socket.c b/lib/isc/unix/socket.c index 462d2eff0e..847310a730 100644 --- a/lib/isc/unix/socket.c +++ b/lib/isc/unix/socket.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: socket.c,v 1.207.2.10 2002/03/20 20:56:44 marka Exp $ */ +/* $Id: socket.c,v 1.207.2.11 2002/07/10 00:04:55 marka Exp $ */ #include @@ -948,8 +948,18 @@ doio_recv(isc_socket_t *sock, isc_socketevent_t *dev) { if ((sock->type == isc_sockettype_tcp) && (cc == 0)) return (DOIO_EOF); - if (sock->type == isc_sockettype_udp) + if (sock->type == isc_sockettype_udp) { dev->address.length = msghdr.msg_namelen; + if (isc_sockaddr_getport(&dev->address) == 0) { + if (isc_log_wouldlog(isc_lctx, IOEVENT_LEVEL)) { + socket_log(sock, &dev->address, IOEVENT, + isc_msgcat, ISC_MSGSET_SOCKET, + ISC_MSG_ZEROPORT, + "dropping source port zero packet"); + } + return (DOIO_SOFT); + } + } socket_log(sock, &dev->address, IOEVENT, isc_msgcat, ISC_MSGSET_SOCKET, ISC_MSG_PKTRECV, diff --git a/lib/isc/win32/socket.c b/lib/isc/win32/socket.c index 5b690ef643..e5fec4ccd2 100644 --- a/lib/isc/win32/socket.c +++ b/lib/isc/win32/socket.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: socket.c,v 1.5.2.5 2002/02/19 00:40:09 marka Exp $ */ +/* $Id: socket.c,v 1.5.2.6 2002/07/10 00:04:57 marka Exp $ */ #define MAKE_EXTERNAL 1 @@ -1057,8 +1057,18 @@ doio_recv(isc_socket_t *sock, isc_socketevent_t *dev) { if ((sock->type == isc_sockettype_tcp) && (cc == 0)) return (DOIO_EOF); - if (sock->type == isc_sockettype_udp) + if (sock->type == isc_sockettype_udp) { dev->address.length = msghdr.msg_namelen; + if (isc_sockaddr_getport(&dev->address) == 0) { + if (isc_log_wouldlog(isc_lctx, IOEVENT_LEVEL)) { + socket_log(sock, &dev->address, IOEVENT, + isc_msgcat, ISC_MSGSET_SOCKET, + ISC_MSG_ZEROPORT, + "dropping source port zero packet"); + } + return (DOIO_SOFT); + } + } socket_log(sock, &dev->address, IOEVENT, isc_msgcat, ISC_MSGSET_SOCKET, ISC_MSG_PKTRECV,