From nobody@FreeBSD.org  Fri Jul 13 06:29:51 2007
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id B27E516A402
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 13 Jul 2007 06:29:51 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [69.147.83.33])
	by mx1.freebsd.org (Postfix) with ESMTP id 8A6DF13C48D
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 13 Jul 2007 06:29:51 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id l6D6TpVS097071
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 13 Jul 2007 06:29:51 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id l6D6Tprf097070;
	Fri, 13 Jul 2007 06:29:51 GMT
	(envelope-from nobody)
Message-Id: <200707130629.l6D6Tprf097070@www.freebsd.org>
Date: Fri, 13 Jul 2007 06:29:51 GMT
From: Garrett Cooper <yaneurabeya@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Possibly security risk in pkg_add(1) -- doesn't add packages properly from stdin
X-Send-Pr-Version: www-3.0

>Number:         114548
>Category:       bin
>Synopsis:       Possibly security risk in pkg_add(1) -- doesn't add packages properly from stdin
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jul 13 06:30:04 GMT 2007
>Closed-Date:    Mon Jun 09 23:48:07 UTC 2008
>Last-Modified:  Sun Feb 03 22:27:31 UTC 2013
>Originator:     Garrett Cooper
>Release:        7.0-CURRENT i386
>Organization:
FreeBSD SoC'ers
>Environment:
FreeBSD tanaka 7.0-CURRENT FreeBSD 7.0-CURRENT #2: Wed Jun 08:39:04 PDT 2007     root@tanaka:/usr/obj/usr/src/sys/TANAKA   i386
>Description:
I've been hacking the pkg_install code for my SoC project, and have
inserted a number of debug statements in my code to determine why the
number of calls in the code I produced quadrupled over the amount in
the plist_cmd section. I inserted a debug statement to determine what
commands are being parsed and noticed that many of my other debug
statements are being interpreted as commands!

Looking through the code a bit I believe I've found the issue... it's
dealing with an assumption that the packing list comes from stdin, when
not provided in add/perform.c's pkg_do(..) function. I haven't determined
with absolution if this is the root cause of the issue, but I'm over 80%
certain that it is.

This concerns me because if it is in fact the problem then a malicious
developer could re-craft the package tools to do something that the
original developers didn't intend.

I am looking into solving the problem by using libarchive with a revised
input format instead of stdin.
>How-To-Repeat:
1. Compile a copy of my latest perforce check-in to pkg_install. 
2. Uncomment the following line in lib/plist.c (should be around 312): 

        printf("COMMAND STRING: %s\nCMD: %s\nCP: %s\nSP: %s\n", s, cmd, cp, sp); 
3. Run '/usr/bin/time -o out.log pkg_add -vf {package} |& tee out.log'
   in tcsh (in order to capture all output).
4. Examine out.log for entries like:

COMMAND STRING: add_plist) Difference: 0.00000223500000000000 secs
CMD: add_plist)
CP:
SP: Difference: 0.00000223500000000000 secs

There will be a large number of duplicate entries like this that are full
of debug data. The debug statements are being interpreted as possible
commands, but thankfully their status gets returned as PLIST_FAIL because
they don't match any of the available commands. However, if the messages
were crafted differently it would be a potential problem.
>Fix:
Theories and suggestions discussed.

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: linimon 
State-Changed-When: Mon Jun 9 23:47:24 UTC 2008 
State-Changed-Why:  
Closed at submitter's request. 

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