From nobody@FreeBSD.org  Thu Dec 10 23:56:22 2009
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 9350E106566B
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 10 Dec 2009 23:56:22 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 683DD8FC12
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 10 Dec 2009 23:56:22 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id nBANuMdc040768
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 10 Dec 2009 23:56:22 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id nBANuL2S040750;
	Thu, 10 Dec 2009 23:56:21 GMT
	(envelope-from nobody)
Message-Id: <200912102356.nBANuL2S040750@www.freebsd.org>
Date: Thu, 10 Dec 2009 23:56:21 GMT
From: Kevin Day <kevin@your.org>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] jls(8) segfault if a jail has more than 6 ipv4 addresses
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         141359
>Category:       bin
>Synopsis:       [patch] jls(8) segfault if a jail has more than 6 ipv4 addresses
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Dec 11 00:00:14 UTC 2009
>Closed-Date:    Sun Dec 20 04:51:25 UTC 2009
>Last-Modified:  Sun Dec 20 04:51:25 UTC 2009
>Originator:     Kevin Day
>Release:        8.0-RELEASE
>Organization:
Your.Org, Inc.
>Environment:
FreeBSD cs03.your.org 8.0-RELEASE-p1 FreeBSD 8.0-RELEASE-p1 #4: Thu Dec  3 19:11:35 UTC 2009     root@cs03.your.org:/usr/src/sys/amd64/compile/SERVER  amd64
>Description:
If you bind more than 6 ipv4 addresses to a jail, then run jls(8), it segfaults after trying to copy the array of IPs to a single jail.

The crash appears in:

#1  0x000000080064d6c7 in jailparam_get (jp=0x800a02600, njp=5, flags=0) at /usr/src/lib/libjail/jail.c:581

(gdb) list
576                                                 JAIL_ERRMSGLEN);
577                                             return (-1);
578                                     }
579                             }
580                             jiov[ai].iov_base = jp[j].jp_value;
581                             memset(jiov[ai].iov_base, 0, jiov[ai].iov_len);
582                             ai++;
583                     } else if (jp + j != jp_key) {
584                             jiov[i].iov_base = jp[j].jp_name;
585                             jiov[i].iov_len = strlen(jp[j].jp_name) + 1;

It's crashing on memset, because iov_base is null:

(gdb) print jiov[ai]
$1 = {iov_base = 0x0, iov_len = 28}
(gdb) print j
$2 = 1
(gdb) print jp[j]
$3 = {jp_name = 0x800a11040 "ip4.addr", jp_value = 0x0, jp_valuelen = 28, jp_elemlen = 4, jp_ctltype = -1073479675, jp_structtype = 1, jp_flags = 16777216}


>How-To-Repeat:

>Fix:
--- /usr/src/lib/libjail/jail.c.orig    2009-12-10 23:47:06.000000000 +0000
+++ /usr/src/lib/libjail/jail.c 2009-12-10 23:47:39.000000000 +0000
@@ -564,7 +564,8 @@
                if (jp[j].jp_elemlen && !(jp[j].jp_flags & JP_RAWVALUE)) {
                        ai++;
                        jiov[ai].iov_len += jp[j].jp_elemlen * ARRAY_SLOP;
-                       if (jp[j].jp_valuelen >= jiov[ai].iov_len)
+                       if (jp[j].jp_value != NULL && 
+                           jp[j].jp_valuelen >= jiov[ai].iov_len)
                                jiov[ai].iov_len = jp[j].jp_valuelen;
                        else {
                                jp[j].jp_valuelen = jiov[ai].iov_len;


This fixes the crash, and makes jls appear to give the full list of IPs. I'm totally lost trying to follow what this function is doing, so I don't know if this is actually fixing the real bug or just working around the problem. Someone who knows libjail better than I should probably review this.


>Release-Note:
>Audit-Trail:

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/141359: commit references a PR
Date: Sat, 12 Dec 2009 21:59:42 +0000 (UTC)

 Author: jamie
 Date: Sat Dec 12 21:59:30 2009
 New Revision: 200449
 URL: http://svn.freebsd.org/changeset/base/200449
 
 Log:
   Don't free jail parameter values after printing them - jail_param_get
   expects them to be there for the next jail in the list.
   
   PR:		bin/141359
   MFC after:	1 week
 
 Modified:
   head/usr.sbin/jls/jls.c
 
 Modified: head/usr.sbin/jls/jls.c
 ==============================================================================
 --- head/usr.sbin/jls/jls.c	Sat Dec 12 21:51:50 2009	(r200448)
 +++ head/usr.sbin/jls/jls.c	Sat Dec 12 21:59:30 2009	(r200449)
 @@ -425,11 +425,6 @@ print_jail(int pflags, int jflags)
  			if (params[i].jp_flags & JP_USER)
  				free(param_values[i]);
  	}
 -	for (i = 0; i < nparams; i++)
 -		if (!(params[i].jp_flags & JP_RAWVALUE)) {
 -			free(params[i].jp_value);
 -			params[i].jp_value = NULL;
 -		}
  	return (jid);
  }
  
 _______________________________________________
 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: bin/141359: commit references a PR
Date: Sun, 20 Dec 2009 04:45:46 +0000 (UTC)

 Author: jamie
 Date: Sun Dec 20 04:45:32 2009
 New Revision: 200749
 URL: http://svn.freebsd.org/changeset/base/200749
 
 Log:
   MFC r200449:
   
     Don't free jail parameter values after printing them - jail_param_get
     expects them to be there for the next jail in the list.
   
   PR:		bin/141359
 
 Modified:
   stable/8/usr.sbin/jls/jls.c
 Directory Properties:
   stable/8/usr.sbin/jls/   (props changed)
 
 Modified: stable/8/usr.sbin/jls/jls.c
 ==============================================================================
 --- stable/8/usr.sbin/jls/jls.c	Sun Dec 20 02:35:10 2009	(r200748)
 +++ stable/8/usr.sbin/jls/jls.c	Sun Dec 20 04:45:32 2009	(r200749)
 @@ -425,11 +425,6 @@ print_jail(int pflags, int jflags)
  			if (params[i].jp_flags & JP_USER)
  				free(param_values[i]);
  	}
 -	for (i = 0; i < nparams; i++)
 -		if (!(params[i].jp_flags & JP_RAWVALUE)) {
 -			free(params[i].jp_value);
 -			params[i].jp_value = NULL;
 -		}
  	return (jid);
  }
  
 _______________________________________________
 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->closed 
State-Changed-By: jamie 
State-Changed-When: Sun Dec 20 04:50:20 UTC 2009 
State-Changed-Why:  
Fixed by r200449, patch to jls. 

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