From nobody@FreeBSD.org  Tue Jul 24 16:37:20 2007
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 2DCB116A421
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 24 Jul 2007 16:37:20 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (unknown [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 1A1B113C4CC
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 24 Jul 2007 16:37:20 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.1/8.14.1) with ESMTP id l6OGbJjX067087
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 24 Jul 2007 16:37:19 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.1/8.14.1/Submit) id l6OGbJZI067086;
	Tue, 24 Jul 2007 16:37:19 GMT
	(envelope-from nobody)
Message-Id: <200707241637.l6OGbJZI067086@www.freebsd.org>
Date: Tue, 24 Jul 2007 16:37:19 GMT
From: Craig Boston <craig@xfoil.gank.org>
To: freebsd-gnats-submit@FreeBSD.org
Subject: tmpfs max file size overflow
X-Send-Pr-Version: www-3.0

>Number:         114870
>Category:       kern
>Synopsis:       tmpfs max file size overflow
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    delphij
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Jul 24 16:40:01 GMT 2007
>Closed-Date:    Tue Jul 24 17:16:09 GMT 2007
>Last-Modified:  Tue Jul 24 17:20:00 GMT 2007
>Originator:     Craig Boston
>Release:        7.0-CURRENT
>Organization:
>Environment:
FreeBSD test 7.0-CURRENT FreeBSD 7.0-CURRENT #0: Wed Jul 18 13:40:41 CDT 2007     me@test:/compile/obj/compile/src/sys/TEST  i386

>Description:
tmpfs calculates tm_maxfilesize by first finding the number of usable swap pages in get_swpgtotal(), then multiplying by PAGE_SIZE.  While tm_maxfilesize is a u_int64_t, get_swpgtotal() returns a u_int, and multiplying by a constant may result in an overflow on i386.

In my case with 12GB of swap, get_swpgtotal() returned 3145944, but tm_maxfilesize ended up as 884736, making it impossible to create files in /tmp larger than 864k without getting "File too large" (EFBIG).

The problem exists on any 32-bit system with > 4GB of swap, though the resulting limit may or may not be noticeable depending on what the final value is.
>How-To-Repeat:
Set up more than 4GB of swap on an i386 system, mount a tmpfs filesystem somewhere, and examine the incorrect value of tm_maxfilesize
>Fix:
Casting the return of get_swpgtotal() to u_int64_t causes the calculation to be made correctly.

=== sys/fs/tmpfs/tmpfs_vfsops.c
==================================================================
--- sys/fs/tmpfs/tmpfs_vfsops.c (revision 777)
+++ sys/fs/tmpfs/tmpfs_vfsops.c (local)
@@ -268,7 +268,7 @@
        mtx_init(&tmp->allnode_lock, "tmpfs allnode lock", NULL, MTX_DEF);
        tmp->tm_nodes_max = nodes;
        tmp->tm_nodes_inuse = 0;
-       tmp->tm_maxfilesize = get_swpgtotal() * PAGE_SIZE;
+       tmp->tm_maxfilesize = (u_int64_t)get_swpgtotal() * PAGE_SIZE;
        LIST_INIT(&tmp->tm_nodes_used);
 
        tmp->tm_pages_max = pages;

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: delphij 
State-Changed-When: Tue Jul 24 17:15:20 UTC 2007 
State-Changed-Why:  
Take. 


Responsible-Changed-From-To: freebsd-bugs->delphij 
Responsible-Changed-By: delphij 
Responsible-Changed-When: Tue Jul 24 17:15:20 UTC 2007 
Responsible-Changed-Why:  
A fix has been applied against -HEAD, thanks for your submission. 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/114870: commit references a PR
Date: Tue, 24 Jul 2007 17:15:01 +0000 (UTC)

 delphij     2007-07-24 17:14:53 UTC
 
   FreeBSD src repository
 
   Modified files:
     sys/fs/tmpfs         tmpfs_vfsops.c 
   Log:
   MFp4: Force 64-bit arithmatic when caculating the maximum file size.
   This fixes tmpfs caculations on 32-bit systems equipped with more than
   4GB swap.
   
   Reported by:    Craig Boston <craig xfoil gank org>
   PR:             kern/114870
   Approved by:    re (tmpfs blanket)
   
   Revision  Changes    Path
   1.8       +1 -1      src/sys/fs/tmpfs/tmpfs_vfsops.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
>Unformatted:
