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

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