From nobody@FreeBSD.org  Thu May 17 20:46:54 2012
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 8BFDC1065686
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 17 May 2012 20:46:54 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 5DC618FC0C
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 17 May 2012 20:46:54 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id q4HKksrH055981
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 17 May 2012 20:46:54 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id q4HKksdg055980;
	Thu, 17 May 2012 20:46:54 GMT
	(envelope-from nobody)
Message-Id: <201205172046.q4HKksdg055980@red.freebsd.org>
Date: Thu, 17 May 2012 20:46:54 GMT
From: Devin Teske <dteske@FreeBSD.org>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [kernel] [PATCH] SMBFS option causes panic-on-boot with VIMAGE enabled
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         168077
>Category:       kern
>Synopsis:       [netsmb] [patch] SMBFS option causes panic-on-boot with VIMAGE enabled
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    davide
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu May 17 20:50:02 UTC 2012
>Closed-Date:    Sun Apr 13 22:13:12 UTC 2014
>Last-Modified:  Sun Apr 13 22:20:01 UTC 2014
>Originator:     Devin Teske
>Release:        FreeBSD 8.3-RELEASE i386
>Organization:
FIS Global, Inc.
>Environment:
FreeBSD push830.vicor.com 8.3-RELEASE FreeBSD 8.3-RELEASE #0: Mon Apr  9 21:47:23 UTC 2012     root@almeida.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  i386
>Description:
Compiling a kernel with both the SMBFS and VIMAGE options enabled produces a kernel that panics immediately upon attempt to mount an SMB filesystem (using mount_smbfs(8)) -- regardless of whether the VIMAGE feature is used or not.
>How-To-Repeat:
Compile a custom kernel with both VIMAGE and SMBFS enabled. Boot said kernel. Attempt to use mount_smbfs(8) to mount an SMB share. Kernel Panic!
>Fix:
See attached patch.

Patch attached with submission follows:

--- sys/netsmb/smb_trantcp.c.orig	2010-06-13 19:09:06.000000000 -0700
+++ sys/netsmb/smb_trantcp.c	2011-12-05 17:16:50.000000000 -0800
@@ -52,6 +52,7 @@
 
 #include <net/if.h>
 #include <net/route.h>
+#include <net/vnet.h>
 
 #include <netinet/in.h>
 #include <netinet/tcp.h>
@@ -85,13 +86,17 @@
 nb_setsockopt_int(struct socket *so, int level, int name, int val)
 {
 	struct sockopt sopt;
+	int error;
 
 	bzero(&sopt, sizeof(sopt));
 	sopt.sopt_level = level;
 	sopt.sopt_name = name;
 	sopt.sopt_val = &val;
 	sopt.sopt_valsize = sizeof(val);
-	return sosetopt(so, &sopt);
+	CURVNET_SET(so->so_vnet);
+	error = sosetopt(so, &sopt);
+	CURVNET_RESTORE();
+	return error;
 }
 
 static int
@@ -292,8 +297,10 @@
 	auio.uio_offset = 0;
 	auio.uio_resid = sizeof(len);
 	auio.uio_td = td;
+	CURVNET_SET(so->so_vnet);
 	error = soreceive(so, (struct sockaddr **)NULL, &auio,
 	    (struct mbuf **)NULL, (struct mbuf **)NULL, &flags);
+	CURVNET_RESTORE();
 	if (error)
 		return error;
 	if (auio.uio_resid > 0) {
@@ -377,8 +384,10 @@
 			 */
 			do {
 				rcvflg = MSG_WAITALL;
+				CURVNET_SET(so->so_vnet);
 				error = soreceive(so, (struct sockaddr **)NULL,
 				    &auio, &tm, (struct mbuf **)NULL, &rcvflg);
+				CURVNET_RESTORE();
 			} while (error == EWOULDBLOCK || error == EINTR ||
 				 error == ERESTART);
 			if (error)


>Release-Note:
>Audit-Trail:

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/168077: commit references a PR
Date: Sat,  4 May 2013 16:56:03 +0000 (UTC)

 Author: davide
 Date: Sat May  4 16:55:48 2013
 New Revision: 250243
 URL: http://svnweb.freebsd.org/changeset/base/250243
 
 Log:
   If the kernel is compiled with VMIMAGE support, the first attempt of
   mounting smbfs share will cause a panic. Fix setting setting/restoring
   vnet context when needed.
   
   PR:		kern/168077
   Submitted by:	dteske
 
 Modified:
   head/sys/netsmb/smb_trantcp.c
 
 Modified: head/sys/netsmb/smb_trantcp.c
 ==============================================================================
 --- head/sys/netsmb/smb_trantcp.c	Sat May  4 16:41:14 2013	(r250242)
 +++ head/sys/netsmb/smb_trantcp.c	Sat May  4 16:55:48 2013	(r250243)
 @@ -46,6 +46,7 @@ __FBSDID("$FreeBSD$");
  
  #include <net/if.h>
  #include <net/route.h>
 +#include <net/vnet.h>
  
  #include <netinet/in.h>
  #include <netinet/tcp.h>
 @@ -79,13 +80,17 @@ static int
  nb_setsockopt_int(struct socket *so, int level, int name, int val)
  {
  	struct sockopt sopt;
 +	int error;
  
  	bzero(&sopt, sizeof(sopt));
  	sopt.sopt_level = level;
  	sopt.sopt_name = name;
  	sopt.sopt_val = &val;
  	sopt.sopt_valsize = sizeof(val);
 -	return sosetopt(so, &sopt);
 +	CURVNET_SET(so->so_vnet);
 +	error = sosetopt(so, &sopt);
 +	CURVNET_RESTORE();
 +	return error;
  }
  
  static int
 @@ -299,8 +304,10 @@ nbssn_recvhdr(struct nbpcb *nbp, int *le
  	auio.uio_offset = 0;
  	auio.uio_resid = sizeof(len);
  	auio.uio_td = td;
 +	CURVNET_SET(so->so_vnet);
  	error = soreceive(so, (struct sockaddr **)NULL, &auio,
  	    (struct mbuf **)NULL, (struct mbuf **)NULL, &flags);
 +	CURVNET_RESTORE();
  	if (error)
  		return error;
  	if (auio.uio_resid > 0) {
 @@ -384,8 +391,10 @@ nbssn_recv(struct nbpcb *nbp, struct mbu
  			 */
  			do {
  				rcvflg = MSG_WAITALL;
 +				CURVNET_SET(so->so_vnet);
  				error = soreceive(so, (struct sockaddr **)NULL,
  				    &auio, &tm, (struct mbuf **)NULL, &rcvflg);
 +				CURVNET_RESTORE();
  			} while (error == EWOULDBLOCK || error == EINTR ||
  				 error == ERESTART);
  			if (error)
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->patched 
State-Changed-By: linimon 
State-Changed-When: Fri Aug 2 02:51:29 UTC 2013 
State-Changed-Why:  
Over to committer as possible MFC reminder. 


Responsible-Changed-From-To: freebsd-bugs->davide 
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=168077 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/168077: commit references a PR
Date: Sun, 13 Apr 2014 22:00:54 +0000 (UTC)

 Author: dteske
 Date: Sun Apr 13 22:00:50 2014
 New Revision: 264425
 URL: http://svnweb.freebsd.org/changeset/base/264425
 
 Log:
   MFC r250243:
   
   If the kernel is compiled with VMIMAGE support, the first attempt of
   mounting smbfs share will cause a panic. Fix setting/restoring vnet
   context when needed.
   
   PR:		kern/168077
   Submitted by:	dteske
 
 Modified:
   stable/9/sys/netsmb/smb_trantcp.c
 Directory Properties:
   stable/9/   (props changed)
   stable/9/sys/   (props changed)
 
 Modified: stable/9/sys/netsmb/smb_trantcp.c
 ==============================================================================
 --- stable/9/sys/netsmb/smb_trantcp.c	Sun Apr 13 21:52:27 2014	(r264424)
 +++ stable/9/sys/netsmb/smb_trantcp.c	Sun Apr 13 22:00:50 2014	(r264425)
 @@ -46,6 +46,7 @@ __FBSDID("$FreeBSD$");
  
  #include <net/if.h>
  #include <net/route.h>
 +#include <net/vnet.h>
  
  #include <netinet/in.h>
  #include <netinet/tcp.h>
 @@ -79,13 +80,17 @@ static int
  nb_setsockopt_int(struct socket *so, int level, int name, int val)
  {
  	struct sockopt sopt;
 +	int error;
  
  	bzero(&sopt, sizeof(sopt));
  	sopt.sopt_level = level;
  	sopt.sopt_name = name;
  	sopt.sopt_val = &val;
  	sopt.sopt_valsize = sizeof(val);
 -	return sosetopt(so, &sopt);
 +	CURVNET_SET(so->so_vnet);
 +	error = sosetopt(so, &sopt);
 +	CURVNET_RESTORE();
 +	return error;
  }
  
  static int
 @@ -286,8 +291,10 @@ nbssn_recvhdr(struct nbpcb *nbp, int *le
  	auio.uio_offset = 0;
  	auio.uio_resid = sizeof(len);
  	auio.uio_td = td;
 +	CURVNET_SET(so->so_vnet);
  	error = soreceive(so, (struct sockaddr **)NULL, &auio,
  	    (struct mbuf **)NULL, (struct mbuf **)NULL, &flags);
 +	CURVNET_RESTORE();
  	if (error)
  		return error;
  	if (auio.uio_resid > 0) {
 @@ -371,8 +378,10 @@ nbssn_recv(struct nbpcb *nbp, struct mbu
  			 */
  			do {
  				rcvflg = MSG_WAITALL;
 +				CURVNET_SET(so->so_vnet);
  				error = soreceive(so, (struct sockaddr **)NULL,
  				    &auio, &tm, (struct mbuf **)NULL, &rcvflg);
 +				CURVNET_RESTORE();
  			} while (error == EWOULDBLOCK || error == EINTR ||
  				 error == ERESTART);
  			if (error)
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: dteske 
State-Changed-When: Sun Apr 13 22:12:27 UTC 2014 
State-Changed-Why:  
MFC'd to stable/9 with r264425 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/168077: commit references a PR
Date: Sun, 13 Apr 2014 22:16:22 +0000 (UTC)

 Author: dteske
 Date: Sun Apr 13 22:16:18 2014
 New Revision: 264426
 URL: http://svnweb.freebsd.org/changeset/base/264426
 
 Log:
   MFC r250243:
   
   If the kernel is compiled with VMIMAGE support, the first attempt of
   mounting smbfs share will cause a panic. Fix setting/restoring vnet
   context when needed.
   
   PR:		kern/168077
   Submitted by:	dteske
 
 Modified:
   stable/8/sys/netsmb/smb_trantcp.c
 Directory Properties:
   stable/8/   (props changed)
   stable/8/sys/   (props changed)
   stable/8/sys/netsmb/   (props changed)
 
 Modified: stable/8/sys/netsmb/smb_trantcp.c
 ==============================================================================
 --- stable/8/sys/netsmb/smb_trantcp.c	Sun Apr 13 22:00:50 2014	(r264425)
 +++ stable/8/sys/netsmb/smb_trantcp.c	Sun Apr 13 22:16:18 2014	(r264426)
 @@ -52,6 +52,7 @@ __FBSDID("$FreeBSD$");
  
  #include <net/if.h>
  #include <net/route.h>
 +#include <net/vnet.h>
  
  #include <netinet/in.h>
  #include <netinet/tcp.h>
 @@ -85,13 +86,17 @@ static int
  nb_setsockopt_int(struct socket *so, int level, int name, int val)
  {
  	struct sockopt sopt;
 +	int error;
  
  	bzero(&sopt, sizeof(sopt));
  	sopt.sopt_level = level;
  	sopt.sopt_name = name;
  	sopt.sopt_val = &val;
  	sopt.sopt_valsize = sizeof(val);
 -	return sosetopt(so, &sopt);
 +	CURVNET_SET(so->so_vnet);
 +	error = sosetopt(so, &sopt);
 +	CURVNET_RESTORE();
 +	return error;
  }
  
  static int
 @@ -292,8 +297,10 @@ nbssn_recvhdr(struct nbpcb *nbp, int *le
  	auio.uio_offset = 0;
  	auio.uio_resid = sizeof(len);
  	auio.uio_td = td;
 +	CURVNET_SET(so->so_vnet);
  	error = soreceive(so, (struct sockaddr **)NULL, &auio,
  	    (struct mbuf **)NULL, (struct mbuf **)NULL, &flags);
 +	CURVNET_RESTORE();
  	if (error)
  		return error;
  	if (auio.uio_resid > 0) {
 @@ -377,8 +384,10 @@ nbssn_recv(struct nbpcb *nbp, struct mbu
  			 */
  			do {
  				rcvflg = MSG_WAITALL;
 +				CURVNET_SET(so->so_vnet);
  				error = soreceive(so, (struct sockaddr **)NULL,
  				    &auio, &tm, (struct mbuf **)NULL, &rcvflg);
 +				CURVNET_RESTORE();
  			} while (error == EWOULDBLOCK || error == EINTR ||
  				 error == ERESTART);
  			if (error)
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
>Unformatted:
