From nobody@FreeBSD.org  Sat Jun 30 05:30:20 2001
Return-Path: <nobody@FreeBSD.org>
Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21])
	by hub.freebsd.org (Postfix) with ESMTP id 27E9E37B401
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 30 Jun 2001 05:30:20 -0700 (PDT)
	(envelope-from nobody@FreeBSD.org)
Received: (from nobody@localhost)
	by freefall.freebsd.org (8.11.3/8.11.3) id f5UCUKS04942;
	Sat, 30 Jun 2001 05:30:20 -0700 (PDT)
	(envelope-from nobody)
Message-Id: <200106301230.f5UCUKS04942@freefall.freebsd.org>
Date: Sat, 30 Jun 2001 05:30:20 -0700 (PDT)
From: Jiangyi Liu <jyliu@163.net>
To: freebsd-gnats-submit@FreeBSD.org
Subject: writing to corrupted msdosfs causes kernel panic 
X-Send-Pr-Version: www-1.0

>Number:         28536
>Category:       i386
>Synopsis:       writing to corrupted msdosfs causes kernel panic
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    trhodes
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Jun 30 05:40:01 PDT 2001
>Closed-Date:    Wed Dec 11 22:19:22 PST 2002
>Last-Modified:  Wed Dec 11 22:19:22 PST 2002
>Originator:     Jiangyi Liu
>Release:        4.3-STABLE
>Organization:
>Environment:
FreeBSD fatcow.home 4.3-STABLE FreeBSD 4.3-STABLE #0: Sat Jun 30 14:52:22 CST 2001     jyliu@fatcow.home:/usr/src/sys/compile/FATCOW  i386

>Description:
In -current and -stable, mountmsdosfs()@ msdosfs_vfsops.c doesn't not check if pm_nxtfree exceeds the max cluster in the file system. So if a corrupted msdos filesystem(which is not uncommon) is written, the following code in updatefats()@msdosfs_fat.c will generate a panic. 

	u_long cn = pmp->pm_nxtfree;

	if (pmp->pm_freeclustercount
	    && (pmp->pm_inusemap[cn / N_INUSEBITS]
        	& (1 << (cn % N_INUSEBITS)))) { .... }

>How-To-Repeat:
Mount a corrupted msdos filesystem(e.g. not probably shutdown) and write to it.
>Fix:
Apply the following patch to test if next free cluster exceeds the max cluster in mountmsdosfs().

*** msdosfs_vfsops.c.orig	Sat Jun 30 14:21:15 2001
--- msdosfs_vfsops.c	Sat Jun 30 14:30:25 2001
***************
*** 681,686 ****
--- 681,692 ----
  	/*
  	 * Check and validate (or perhaps invalidate?) the fsinfo structure?		XXX
  	 */
+     if (pmp->pm_fsinfo && pmp->pm_nxtfree > pmp->pm_maxcluster) {
+         printf ("Next free cluster in FSInfo (%u) exceeds maxcluster (%u)\n",
+                pmp->pm_nxtfree, pmp->pm_maxcluster);
+         error = EINVAL;
+         goto error_exit;
+     }
  
  	/*
  	 * Allocate memory for the bitmap of allocated clusters, and then
>Release-Note:
>Audit-Trail:

From: Hiten Pandya <hiten@uk.FreeBSD.org>
To: freebsd-gnats-submit@FreeBSD.org
Cc: jyliu@163.net
Subject: Re: i386/28536: writing to corrupted msdosfs causes kernel panic
Date: Wed, 30 Jan 2002 08:12:13 +0000

 I think, this should be noted by the MSDOSFS maintainer.
 
 --Hiten
State-Changed-From-To: open->patched 
State-Changed-By: trhodes 
State-Changed-When: Thu Aug 22 15:17:46 PDT 2002 
State-Changed-Why:  
Just applied a patch to CURRENT which should fix this problem.  With no 
problems I'll MFC in a week.  Thanks 


Responsible-Changed-From-To: freebsd-bugs->trhodes 
Responsible-Changed-By: trhodes 
Responsible-Changed-When: Thu Aug 22 15:17:46 PDT 2002 
Responsible-Changed-Why:  
Just applied a patch to CURRENT which should fix this problem.  With no 
problems I'll MFC in a week.  Thanks 

http://www.freebsd.org/cgi/query-pr.cgi?pr=28536 
State-Changed-From-To: patched->feedback 
State-Changed-By: trhodes 
State-Changed-When: Thu Sep 12 14:58:25 PDT 2002 
State-Changed-Why:  
Applied to STABLE, please let me know if you still have problems. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=28536 
State-Changed-From-To: feedback->closed 
State-Changed-By: trhodes 
State-Changed-When: Wed Dec 11 22:18:28 PST 2002 
State-Changed-Why:  
Closed.  I can not reproduce this, and it has been in the feedback state for 
awhile now. 

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