From nobody@FreeBSD.org  Wed Jul 31 18:51:24 2013
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1])
	(using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by hub.freebsd.org (Postfix) with ESMTP id 1E373A4F
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 31 Jul 2013 18:51:24 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from oldred.freebsd.org (oldred.freebsd.org [8.8.178.121])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by mx1.freebsd.org (Postfix) with ESMTPS id E66A52275
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 31 Jul 2013 18:51:23 +0000 (UTC)
Received: from oldred.freebsd.org ([127.0.1.6])
	by oldred.freebsd.org (8.14.5/8.14.7) with ESMTP id r6VIpNSo083344
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 31 Jul 2013 18:51:23 GMT
	(envelope-from nobody@oldred.freebsd.org)
Received: (from nobody@localhost)
	by oldred.freebsd.org (8.14.5/8.14.5/Submit) id r6VIpNPi083341;
	Wed, 31 Jul 2013 18:51:23 GMT
	(envelope-from nobody)
Message-Id: <201307311851.r6VIpNPi083341@oldred.freebsd.org>
Date: Wed, 31 Jul 2013 18:51:23 GMT
From: Maxim Samsonov <xors@mailup.net>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [netsmb][patch]: Fix large files handling
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         180979
>Category:       kern
>Synopsis:       [netsmb][patch]: Fix large files handling
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-fs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jul 31 19:00:00 UTC 2013
>Closed-Date:    
>Last-Modified:  Fri Aug 02 07:04:25 UTC 2013
>Originator:     Maxim Samsonov
>Release:        9.2-BETA2
>Organization:
>Environment:
FreeBSD fern.localbroom.net 9.2-BETA2 FreeBSD 9.2-BETA2 #0: Wed Jul 31 13:50:29 MSK 2013     xors@fern.localbroom.net:/usr/obj/usr/src/sys/FERN  amd64
>Description:
NETSMB should honour SMB_CAP_LARGE_FILES capability as well as SMB_CAP_LARGE_READX and SMB_CAP_LARGE_WRITEX capabilities in order to read/write large files (over 4G) correctly.
So 64-bit file offsets are supported if SMB_CAP_LARGE_FILES capability is detected.

This fix was inspired from the following NetBSD patch:
http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/netsmb/smb_smb.c?rev=1.31&content-type=text/x-cvsweb-markup&only_with_tag=MAIN
..
Fix detection of SMB capabilities according to the CIFS spec:
1.) SMB_CAP_LARGE_FILES advertises support for 64-bit file offsets.
2.) SMB_CAP_LARGE_READX and SMB_CAP_LARGE_WRITEX advertise support for
    large reads and writes (larger than 64KB).
The code previously only used SMB_CAP_LARGE_READX and SMB_CAP_LARGE_WRITEX
which is not correct and doesn't work for the Apple Time Capsule which
only supports SMB_CAP_LARGE_FILES.
..

>How-To-Repeat:

>Fix:


Patch attached with submission follows:

diff --git a/sys/netsmb/smb_smb.c b/sys/netsmb/smb_smb.c
--- a/sys/netsmb/smb_smb.c
+++ b/sys/netsmb/smb_smb.c
@@ -771,7 +771,12 @@
 	u_int8_t wc;
 	int error, rlen, blksz;
 
-	if (SSTOVC(ssp)->vc_sopt.sv_caps & SMB_CAP_LARGE_READX)
+	if (uio->uio_offset > UINT32_MAX
+		&& !(SSTOVC(ssp)->vc_sopt.sv_caps & SMB_CAP_LARGE_FILES)) {
+		return (EFBIG);
+	}
+
+	if (SSTOVC(ssp)->vc_sopt.sv_caps & (SMB_CAP_LARGE_READX | SMB_CAP_LARGE_FILES))
 		return (smb_smb_readx(ssp, fid, len, rresid, uio, scred));
 
 	error = smb_rq_alloc(SSTOCP(ssp), SMB_COM_READ, scred, &rqp);
@@ -850,7 +855,12 @@
 	u_int8_t wc;
 	int error, blksz;
 
-	if (*len && SSTOVC(ssp)->vc_sopt.sv_caps & SMB_CAP_LARGE_WRITEX)
+	if (uio->uio_offset > UINT32_MAX
+		&& !(SSTOVC(ssp)->vc_sopt.sv_caps & SMB_CAP_LARGE_FILES)) {
+		return (EFBIG);
+	}
+
+	if (*len && SSTOVC(ssp)->vc_sopt.sv_caps & (SMB_CAP_LARGE_WRITEX | SMB_CAP_LARGE_FILES))
 		return (smb_smb_writex(ssp, fid, len, rresid, uio, scred));
  
 	blksz = SSTOVC(ssp)->vc_txmax - SMB_HDRLEN - 16;


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->open 
State-Changed-By: linimon 
State-Changed-When: Fri Aug 2 02:51:29 UTC 2013 
State-Changed-Why:  
sorry, wrong PR edited.  Please ignore. 


Responsible-Changed-From-To: freebsd-bugs->freebsd-bugs 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Fri Aug 2 02:51:29 UTC 2013 
Responsible-Changed-Why:  

http://www.freebsd.org/cgi/query-pr.cgi?pr=180979 
Responsible-Changed-From-To: freebsd-bugs->freebsd-fs 
Responsible-Changed-By: remko 
Responsible-Changed-When: Fri Aug 2 07:04:08 UTC 2013 
Responsible-Changed-Why:  
Filesystem related -> -fs 

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