From owner-freebsd-bugs@FreeBSD.ORG Tue Jul 24 16:40:01 2007 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BFB5D16A417 for ; Tue, 24 Jul 2007 16:40:01 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 99DDD13C46B for ; Tue, 24 Jul 2007 16:40:01 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.1/8.14.1) with ESMTP id l6OGe1E8013251 for ; Tue, 24 Jul 2007 16:40:01 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.1/8.14.1/Submit) id l6OGe1od013250; Tue, 24 Jul 2007 16:40:01 GMT (envelope-from gnats) Resent-Date: Tue, 24 Jul 2007 16:40:01 GMT Resent-Message-Id: <200707241640.l6OGe1od013250@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Craig Boston Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2DCB116A421 for ; 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 ; 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 ; 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 To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.0 Cc: Subject: kern/114870: tmpfs max file size overflow X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Jul 2007 16:40:01 -0000 >Number: 114870 >Category: kern >Synopsis: tmpfs max file size overflow >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Tue Jul 24 16:40:01 GMT 2007 >Closed-Date: >Last-Modified: >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: >Unformatted: