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

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