From nobody@FreeBSD.org  Tue Aug 21 18:49:24 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 A2DDB1065674
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 21 Aug 2012 18:49:24 +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 73D7A8FC1B
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 21 Aug 2012 18:49:24 +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 q7LInON2000230
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 21 Aug 2012 18:49:24 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id q7LInOA1000229;
	Tue, 21 Aug 2012 18:49:24 GMT
	(envelope-from nobody)
Message-Id: <201208211849.q7LInOA1000229@red.freebsd.org>
Date: Tue, 21 Aug 2012 18:49:24 GMT
From: Oleg Ginzburg <olevole@olevole.ru>
To: freebsd-gnats-submit@FreeBSD.org
Subject: jail v2 loses a binding of ip which sets after ips with /"network prefix"
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         170832
>Category:       misc
>Synopsis:       jail v2 loses a binding of ip which sets after ips with /"network prefix"
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    jamie
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Aug 21 18:50:10 UTC 2012
>Closed-Date:    Wed Aug 29 18:53:02 UTC 2012
>Last-Modified:  Wed Aug 29 18:53:02 UTC 2012
>Originator:     Oleg Ginzburg
>Release:        9.1-PRERELEASE, 10-CURRENT
>Organization:
>Environment:
FreeBSD cbuilder64.my.domain 10.0-CURRENT FreeBSD 10.0-CURRENT #4 r239330: Thu Aug 16 22:08:12 MSK 2012     root@cbuilder64.my.domain:/usr/obj/usr/src/sys/GENERIC  amd64
>Description:
when the jail is created by config file with multiple ips, jail loses all ip assignment which sets after ips with /"network prefix"
Nevertheless, all IP are established on the interface with the correct mask
>How-To-Repeat:
Have jail config with multiple ips with prefix in the list. Config sample (we mean that in /usr/jails/jail1 we have a complete freebsd base environment):

% cat jail1.conf 
jail1 {
exec.start = "/bin/sh /etc/rc";
exec.stop = "/bin/sh /etc/rc.shutdown";
exec.clean;
#mount.devfs;
host.hostname = "jail1.my.domain";
path = "/usr/jails/jail1";
allow.raw_sockets;
allow.socket_af;
allow.chflags;
allow.sysvipc;
ip4.addr = 10.0.0.1,10.0.0.2,172.17.0.0/16,10.0.0.3;
interface="em0";
mount.devfs;
devfs_ruleset="4";
}

// Before jail creation, interfaces em0 have:
% ifconfig em0 | grep "inet "
        inet 192.168.1.2 netmask 0xffffff00 broadcast 192.168.1.255

// Jail start:
% jail -f jail1.conf -c jail1
jail1: created
..

//done. Check for IPs on interface. 172.17.0.0 have correct mask:
ifconfig em0 | grep "inet "
        inet 192.168.1.2 netmask 0xffffff00 broadcast 192.168.1.255 
        inet 10.0.0.1 netmask 0xffffffff broadcast 10.0.0.1 
        inet 10.0.0.2 netmask 0xffffffff broadcast 10.0.0.2 
        inet 172.17.0.0 netmask 0xffff0000 broadcast 172.17.255.255 
        inet 10.0.0.3 netmask 0xffffffff broadcast 10.0.0.3 

//Check for IP in jls:
% jls -v
   JID  Hostname                      Path
        Name                          State
        CPUSetID
        IP Address(es)
     1  jail1.my.domain               /usr/jails/jail1
        jail1                         ACTIVE
        2     
        10.0.0.1       
        10.0.0.2       
        172.17.0.0     

We have 10.0.0.1/32,10.0.0.2/32 and 172.17.0.0/16 but loose 10.0.0.3

>Fix:


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->jamie 
Responsible-Changed-By: bz 
Responsible-Changed-When: Wed Aug 22 01:44:26 UTC 2012 
Responsible-Changed-Why:  
I think this is yours. 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: misc/170832: commit references a PR
Date: Thu, 23 Aug 2012 01:43:12 +0000 (UTC)

 Author: jamie
 Date: Thu Aug 23 01:43:01 2012
 New Revision: 239601
 URL: http://svn.freebsd.org/changeset/base/239601
 
 Log:
   Remember that I'm using length-defined strings in parameters:
   
    Remove a bogus null terminator when stripping the netmask from
    IP addresses.  This was causing later addresses in a comma-separated
    string to disappear.
   
    Use memcpy instead of strcpy.  This could just cause Bad Things.
   
   PR:		170832
   MFC after:	1 week
 
 Modified:
   head/usr.sbin/jail/config.c
 
 Modified: head/usr.sbin/jail/config.c
 ==============================================================================
 --- head/usr.sbin/jail/config.c	Thu Aug 23 00:39:08 2012	(r239600)
 +++ head/usr.sbin/jail/config.c	Thu Aug 23 01:43:01 2012	(r239601)
 @@ -597,8 +597,7 @@ check_intparams(struct cfjail *j)
  					    "ip4.addr: bad netmask \"%s\"", cs);
  					error = -1;	
  				}
 -				*cs = '\0';
 -				s->len = cs - s->s + 1;
 +				s->len = cs - s->s;
  			}
  		}
  	}
 @@ -621,8 +620,7 @@ check_intparams(struct cfjail *j)
  					    cs);
  					error = -1;	
  				}
 -				*cs = '\0';
 -				s->len = cs - s->s + 1;
 +				s->len = cs - s->s;
  			}
  		}
  	}
 @@ -714,7 +712,7 @@ import_params(struct cfjail *j)
  			value = alloca(vallen);
  			cs = value;
  			TAILQ_FOREACH_SAFE(s, &p->val, tq, ts) {
 -				strcpy(cs, s->s);
 +				memcpy(cs, s->s, s->len);
  				if (ts != NULL) {
  					cs += s->len + 1;
  					cs[-1] = ',';
 _______________________________________________
 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: jamie 
State-Changed-When: Thu Aug 23 02:03:03 UTC 2012 
State-Changed-Why:  
Fixed in r239601: I had a '0' where it didn't belong. 

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

From: Oleg Ginzburg <olevole@olevole.ru>
To: bug-followup@freebsd.org,
 olevole@olevole.ru
Cc:  
Subject: Re: misc/170832: jail v2 loses a binding of ip which sets after ips with /&quot;network prefix&quot;
Date: Thu, 23 Aug 2012 12:16:39 +0400

 Ive got another problem now.
 
 root@gizmo:/ # cat jail1.conf=20
 jail1 {
 exec.start =3D "/bin/sh /etc/rc";
 exec.stop =3D "/bin/sh /etc/rc.shutdown";
 exec.clean;
 #mount.devfs;
 host.hostname =3D "jail1.my.domain";
 path =3D "/usr/jails/jail1";
 allow.raw_sockets;
 allow.socket_af;
 allow.chflags;
 allow.sysvipc;
 ip4.addr =3D 10.0.0.2/24;
 ip4.addr +=3D 192.168.0.4/24;
 ip4.addr +=3D 172.17.9.99/16;
 ip4.addr +=3D 10.0.0.4;
 interface=3D"re0";
 mount.devfs;
 devfs_ruleset=3D"4";
 }
 
 root@gizmo:/ # jail -f jail1.conf -c jail1
 jail: jail1: ip4.addr: not an IPv4 address: 10.0.0.4=B1
 

From: Mark Linimon <linimon@lonesome.com>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: misc/170832: jail v2 loses a binding of ip which sets after
 ips with /"network prefix"
Date: Thu, 23 Aug 2012 07:13:30 -0500

 ----- Forwarded message from Jamie Gritton <jamie@FreeBSD.org> -----
 
 Date: Wed, 22 Aug 2012 19:47:11 -0600
 From: Jamie Gritton <jamie@FreeBSD.org>
 To: Oleg Ginzburg <olevole@olevole.ru>
 Cc: FreeBSD-Jail <freebsd-jail@FreeBSD.org>
 Subject: Re: misc/170832: jail v2 loses a binding of ip which sets after ips
 	with /"network prefix"
 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64;
 	rv:9.0) Gecko/20120126 Thunderbird/9.0
 
 I confused myself on the difference between null-terminated and
 length-defined strings, and stuck a '\0' were it didn't belong.
 I've committed the fix to HEAD, and I'll have it in 9.1 next week.
 
 - Jamie
 
 ----- End forwarded message -----

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: misc/170832: commit references a PR
Date: Wed, 29 Aug 2012 16:11:24 +0000 (UTC)

 Author: jamie
 Date: Wed Aug 29 16:11:03 2012
 New Revision: 239854
 URL: http://svn.freebsd.org/changeset/base/239854
 
 Log:
   MFC r239601:
   
    Remember that I'm using length-defined strings in parameters:
   
     Remove a bogus null terminator when stripping the netmask from
     IP addresses.  This was causing later addresses in a comma-separated
     string to disappear.
   
     Use memcpy instead of strcpy.  This could just cause Bad Things.
   
   MFC r239602:
   
    Pre-separate IP addresses passed on the command line, so they can be
    properly parsed for interface prefixes and netmask suffixes.  This was
    already done for the old-style (fixed) command line, but missed for
    the new-style.
   
   MFC r239621:
   
    Partially roll back r239601 - keep parameter strings both length-delimited
    and null-terminated at the same time, because they're later passed to
    libjail as null-terminated.  That means I also need to add a nul byte when
    comma-combining array parameters.
   
   PR:		170832
 
 Modified:
   stable/9/usr.sbin/jail/config.c
   stable/9/usr.sbin/jail/jail.c
 Directory Properties:
   stable/9/usr.sbin/jail/   (props changed)
 
 Modified: stable/9/usr.sbin/jail/config.c
 ==============================================================================
 --- stable/9/usr.sbin/jail/config.c	Wed Aug 29 16:00:26 2012	(r239853)
 +++ stable/9/usr.sbin/jail/config.c	Wed Aug 29 16:11:03 2012	(r239854)
 @@ -596,7 +596,7 @@ check_intparams(struct cfjail *j)
  					error = -1;	
  				}
  				*cs = '\0';
 -				s->len = cs - s->s + 1;
 +				s->len = cs - s->s;
  			}
  		}
  	}
 @@ -620,7 +620,7 @@ check_intparams(struct cfjail *j)
  					error = -1;	
  				}
  				*cs = '\0';
 -				s->len = cs - s->s + 1;
 +				s->len = cs - s->s;
  			}
  		}
  	}
 @@ -712,12 +712,11 @@ import_params(struct cfjail *j)
  			value = alloca(vallen);
  			cs = value;
  			TAILQ_FOREACH_SAFE(s, &p->val, tq, ts) {
 -				strcpy(cs, s->s);
 -				if (ts != NULL) {
 -					cs += s->len + 1;
 -					cs[-1] = ',';
 -				}
 +				memcpy(cs, s->s, s->len);
 +				cs += s->len + 1;
 +				cs[-1] = ',';
  			}
 +			value[vallen - 1] = '\0';
  		}
  		if (jailparam_import(jp, value) < 0) {
  			error = -1;
 
 Modified: stable/9/usr.sbin/jail/jail.c
 ==============================================================================
 --- stable/9/usr.sbin/jail/jail.c	Wed Aug 29 16:00:26 2012	(r239853)
 +++ stable/9/usr.sbin/jail/jail.c	Wed Aug 29 16:11:03 2012	(r239854)
 @@ -304,9 +304,33 @@ main(int argc, char **argv)
  				for (i++; i < argc; i++)
  					add_param(NULL, NULL, IP_COMMAND,
  					    argv[i]);
 -				break;
  			}
 -			add_param(NULL, NULL, 0, argv[i]);
 +#ifdef INET
 +			else if (!strncmp(argv[i], "ip4.addr=", 9)) {
 +				for (cs = argv[i] + 9;; cs = ncs + 1) {
 +					ncs = strchr(cs, ',');
 +					if (ncs)
 +						*ncs = '\0';
 +					add_param(NULL, NULL, KP_IP4_ADDR, cs);
 +					if (!ncs)
 +						break;
 +				}
 +			}
 +#endif
 +#ifdef INET6
 +			else if (!strncmp(argv[i], "ip6.addr=", 9)) {
 +				for (cs = argv[i] + 9;; cs = ncs + 1) {
 +					ncs = strchr(cs, ',');
 +					if (ncs)
 +						*ncs = '\0';
 +					add_param(NULL, NULL, KP_IP6_ADDR, cs);
 +					if (!ncs)
 +						break;
 +				}
 +			}
 +#endif
 +			else
 +				add_param(NULL, NULL, 0, argv[i]);
  		}
  	} else {
  		/* From the config file, perhaps with a specified jail */
 _______________________________________________
 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"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: misc/170832: commit references a PR
Date: Wed, 29 Aug 2012 18:40:27 +0000 (UTC)

 Author: jamie
 Date: Wed Aug 29 18:40:12 2012
 New Revision: 239871
 URL: http://svn.freebsd.org/changeset/base/239871
 
 Log:
   MFS r239854 (including MFC r239601, r239602, r239621):
   
    Remember that I'm using length-defined strings in parameters:
   
     Don't include the null terminator when recomputing the parameter
     length when stripping the netmask from IP addresses.  This was
     causing later addresses in a comma-separated string to disappear.
   
     Use memcpy instead of strcpy.  This could just cause Bad Things.
   
     Add a null byte when comma-combining array parameters.
   
     Pre-separate IP addresses passed on the command line, so they can be
     properly parsed for interface prefixes and netmask suffixes.  This was
     already done for the old-style (fixed) command line, but missed for
     the new-style.
   
   PR:		170832
   Approved by:	re (kib)
 
 Modified:
   releng/9.1/usr.sbin/jail/config.c
   releng/9.1/usr.sbin/jail/jail.c
 Directory Properties:
   releng/9.1/usr.sbin/jail/   (props changed)
 
 Modified: releng/9.1/usr.sbin/jail/config.c
 ==============================================================================
 --- releng/9.1/usr.sbin/jail/config.c	Wed Aug 29 18:37:10 2012	(r239870)
 +++ releng/9.1/usr.sbin/jail/config.c	Wed Aug 29 18:40:12 2012	(r239871)
 @@ -596,7 +596,7 @@ check_intparams(struct cfjail *j)
  					error = -1;	
  				}
  				*cs = '\0';
 -				s->len = cs - s->s + 1;
 +				s->len = cs - s->s;
  			}
  		}
  	}
 @@ -620,7 +620,7 @@ check_intparams(struct cfjail *j)
  					error = -1;	
  				}
  				*cs = '\0';
 -				s->len = cs - s->s + 1;
 +				s->len = cs - s->s;
  			}
  		}
  	}
 @@ -712,12 +712,11 @@ import_params(struct cfjail *j)
  			value = alloca(vallen);
  			cs = value;
  			TAILQ_FOREACH_SAFE(s, &p->val, tq, ts) {
 -				strcpy(cs, s->s);
 -				if (ts != NULL) {
 -					cs += s->len + 1;
 -					cs[-1] = ',';
 -				}
 +				memcpy(cs, s->s, s->len);
 +				cs += s->len + 1;
 +				cs[-1] = ',';
  			}
 +			value[vallen - 1] = '\0';
  		}
  		if (jailparam_import(jp, value) < 0) {
  			error = -1;
 
 Modified: releng/9.1/usr.sbin/jail/jail.c
 ==============================================================================
 --- releng/9.1/usr.sbin/jail/jail.c	Wed Aug 29 18:37:10 2012	(r239870)
 +++ releng/9.1/usr.sbin/jail/jail.c	Wed Aug 29 18:40:12 2012	(r239871)
 @@ -304,9 +304,33 @@ main(int argc, char **argv)
  				for (i++; i < argc; i++)
  					add_param(NULL, NULL, IP_COMMAND,
  					    argv[i]);
 -				break;
  			}
 -			add_param(NULL, NULL, 0, argv[i]);
 +#ifdef INET
 +			else if (!strncmp(argv[i], "ip4.addr=", 9)) {
 +				for (cs = argv[i] + 9;; cs = ncs + 1) {
 +					ncs = strchr(cs, ',');
 +					if (ncs)
 +						*ncs = '\0';
 +					add_param(NULL, NULL, KP_IP4_ADDR, cs);
 +					if (!ncs)
 +						break;
 +				}
 +			}
 +#endif
 +#ifdef INET6
 +			else if (!strncmp(argv[i], "ip6.addr=", 9)) {
 +				for (cs = argv[i] + 9;; cs = ncs + 1) {
 +					ncs = strchr(cs, ',');
 +					if (ncs)
 +						*ncs = '\0';
 +					add_param(NULL, NULL, KP_IP6_ADDR, cs);
 +					if (!ncs)
 +						break;
 +				}
 +			}
 +#endif
 +			else
 +				add_param(NULL, NULL, 0, argv[i]);
  		}
  	} else {
  		/* From the config file, perhaps with a specified jail */
 _______________________________________________
 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: jamie 
State-Changed-When: Wed Aug 29 18:52:01 UTC 2012 
State-Changed-Why:  
MFCd to 9 and 9.1. 

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