Blame SOURCES/xinetd-2.3.15-bad-port-check.patch

01101d
Re-introduce bad_port_check(), which upstream dropped between 2.3.13 and 2.3.14
01101d
for it having been "rather antiquated for years", with no justification given
01101d
for that claim.
01101d
01101d
--- xinetd-2.3.15/xinetd/builtins.c	2012-05-09 17:40:29.000000000 +0200
01101d
+++ xinetd-2.3.15.new/xinetd/builtins.c	2012-05-14 10:25:00.431529805 +0200
01101d
@@ -52,6 +52,7 @@ static void dgram_daytime(const struct s
01101d
 static void stream_chargen(const struct server *) ;
01101d
 static void dgram_chargen(const struct server *) ;
01101d
 static void tcpmux_handler(const struct server *) ;
01101d
+static int bad_port_check(const union xsockaddr *, const char *);
01101d
 
01101d
 /*
01101d
  * SG - This is the call sequence to get to a built-in service
01101d
@@ -163,6 +164,25 @@ static void stream_echo( const struct se
01101d
       Sclose(descriptor);
01101d
 }
01101d
 
01101d
+/* For internal UDP services, make sure we don't respond to our ports
01101d
+ * on other servers and to low ports of other services (such as DNS).
01101d
+ * This can cause looping.
01101d
+ */
01101d
+static int bad_port_check( const union xsockaddr *sa, const char *func )
01101d
+{
01101d
+   uint16_t port = 0;
01101d
+
01101d
+   port = ntohs( xaddrport( sa ) );
01101d
+
01101d
+   if ( port < 1024 ) {
01101d
+      msg(LOG_WARNING, func,
01101d
+         "Possible Denial of Service attack from %s %d", xaddrname(sa), port);
01101d
+      return (-1);
01101d
+   }
01101d
+
01101d
+   return (0);
01101d
+}
01101d
+
01101d
 static void dgram_echo( const struct server *serp )
01101d
 {
01101d
    char            buf[ DATAGRAM_SIZE ] ;
01101d
@@ -170,6 +190,7 @@ static void dgram_echo( const struct ser
01101d
    ssize_t             cc ;
01101d
    socklen_t       sin_len = 0;
01101d
    int             descriptor = SERVER_FD( serp ) ;
01101d
+   const char      *func = "dgram_echo" ;
01101d
 
01101d
    if( SC_IPV4( SVC_CONF( SERVER_SERVICE( serp ) ) ) )
01101d
       sin_len = sizeof( struct sockaddr_in );
01101d
@@ -178,6 +199,7 @@ static void dgram_echo( const struct ser
01101d
 
01101d
    cc = recvfrom( descriptor, buf, sizeof( buf ), 0, (struct sockaddr *)( &lsin ), &sin_len ) ;
01101d
    if ( cc != (ssize_t)-1 ) {
01101d
+      if( bad_port_check(&lsin, func) != 0 ) return;
01101d
       (void) sendto( descriptor, buf, (size_t)cc, 0, SA( &lsin ), sizeof( lsin ) ) ;
01101d
    }
01101d
 }
01101d
@@ -292,6 +314,7 @@ static void dgram_daytime( const struct
01101d
    unsigned int    buflen      = sizeof( time_buf ) ;
01101d
    int             descriptor  = SERVER_FD( serp ) ;
01101d
    ssize_t         val;
01101d
+   const char      *func = "dgram_daytime" ;
01101d
 
01101d
    if ( SC_IPV4( SVC_CONF( SERVER_SERVICE( serp ) ) ) ) 
01101d
       sin_len = sizeof( struct sockaddr_in );
01101d
@@ -303,6 +326,8 @@ static void dgram_daytime( const struct
01101d
    if ( val == (ssize_t)-1 )
01101d
       return ;
01101d
 
01101d
+   if( bad_port_check(&lsin, func) != 0 ) return;
01101d
+
01101d
    daytime_protocol( time_buf, &buflen ) ;
01101d
    
01101d
    (void) sendto( descriptor, time_buf, buflen, 0, SA(&lsin), sizeof( lsin ) ) ;
01101d
@@ -359,6 +384,7 @@ static void dgram_time( const struct ser
01101d
    socklen_t       sin_len = 0 ;
01101d
    int             fd      = SERVER_FD( serp ) ;
01101d
    ssize_t         val;
01101d
+   const char      *func = "dgram_time" ;
01101d
 
01101d
    if ( SC_IPV4( SVC_CONF( SERVER_SERVICE( serp ) ) ) ) 
01101d
       sin_len = sizeof( struct sockaddr_in );
01101d
@@ -368,6 +394,7 @@ static void dgram_time( const struct ser
01101d
    val = recvfrom( fd, buf, sizeof( buf ), 0, (struct sockaddr *)( &lsin ), &sin_len );
01101d
    if ( val == (ssize_t)-1 )
01101d
       return ;
01101d
+   if( bad_port_check(&lsin, func) != 0 ) return;
01101d
 
01101d
    time_protocol( time_buf ) ;
01101d
    (void) sendto( fd, (char *) time_buf, 4, 0, SA( &lsin ), sin_len ) ;
01101d
@@ -466,6 +493,7 @@ static void dgram_chargen( const struct
01101d
    int             fd      = SERVER_FD( serp ) ;
01101d
    unsigned int    left    = sizeof( buf ) ;
01101d
    ssize_t         val;
01101d
+   const char      *func = "dgram_chargen" ;
01101d
 
01101d
    if ( SC_IPV4( SVC_CONF( SERVER_SERVICE( serp ) ) ) ) 
01101d
       sin_len = sizeof( struct sockaddr_in );
01101d
@@ -480,6 +508,8 @@ static void dgram_chargen( const struct
01101d
    bad_variable = 1 ;      /* this will cause a compilation error */
01101d
 #endif
01101d
 
01101d
+   if( bad_port_check(&lsin, func) != 0 ) return;
01101d
+
01101d
    for ( p = buf ; left > 2 ; left -= len, p += len )
01101d
    {
01101d
       len = min( LINE_LENGTH+2, left ) ;