From nobody@FreeBSD.org  Mon Sep  7 15:58:09 2009
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 E424A106566B
	for <freebsd-gnats-submit@FreeBSD.org>; Mon,  7 Sep 2009 15:58:09 +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 D33DD8FC08
	for <freebsd-gnats-submit@FreeBSD.org>; Mon,  7 Sep 2009 15:58:09 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id n87Fw9HI050968
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 7 Sep 2009 15:58:09 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id n87Fw9ph050967;
	Mon, 7 Sep 2009 15:58:09 GMT
	(envelope-from nobody)
Message-Id: <200909071558.n87Fw9ph050967@www.freebsd.org>
Date: Mon, 7 Sep 2009 15:58:09 GMT
From: Archer <none@FreeBSD.org>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Kernel memory corruption, kernel panic as a result
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         138613
>Category:       i386
>Synopsis:       Kernel memory corruption, kernel panic as a result
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    freebsd-i386
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Sep 07 16:00:02 UTC 2009
>Closed-Date:    Wed Sep 09 14:37:48 UTC 2009
>Last-Modified:  Wed Sep 09 14:37:48 UTC 2009
>Originator:     Archer
>Release:        8.0-BETA3
>Organization:
none
>Environment:
FreeBSD serv 8.0-BETA3 FreeBSD 8.0-BETA3 #1: Sat Sep  5 09:33:03 MSD 2009     root@serv:/usr/obj/usr/src/sys/MYKERN  i386

>Description:
Lets take a look at this code in ufs_vnops.c file:
refcount_init(&ucred.cr_ref, 1);
ucred.cr_uid = ip->i_uid;
ucred.cr_ngroups = 1;
ucred.cr_groups[0] = dp->i_gid;<---problem here
ucp = &ucred;

ucred structure variable is used here. It's a local structure so it's allocated on stack. Now lets take a look at the structure definition:
struct ucred {
--skipped...
gid_t *cr_groups;
--skipped...
};

As we see we've got a pointer. But this pointer is not initialized at the point of usage. So it contains some arbitrary value from the stack. And then that memory gets overwritten. Lets take a look at the assembly listing:
mov     edx, [esi+6Ch]
mov     eax, [ebp+var_140]<---here we read some arbitrary pointer from the stack
mov     [eax], edx<---and here we smash the data at our arbitrary pointer

In my case some memory around ufs_lookup was overwritten.

>How-To-Repeat:
Enable QUOTA and SUIDDIR at the kernel, set them on some partition and try to create a directory there.
For me worked tar -xvjf phpMyAdmin-3.2.1-all-languages.tar.bz2 which also calls mkdir when extracting files.
>Fix:
I suppose we should allocate memory for our pointer before using it so recklessly. And I suggest to review the code that works with this pointer, the same mistake may happen elsewhere.

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed  
State-Changed-By: brucec 
State-Changed-When: Wed Sep 9 14:37:13 UTC 2009 
State-Changed-Why:  
Duplicate of kern/138657 

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