From owner-freebsd-bugs@FreeBSD.ORG Fri Jul 13 06:30:05 2007 Return-Path: X-Original-To: freebsd-bugs@hub.freebsd.org Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 5D0BC16A404 for ; Fri, 13 Jul 2007 06:30:05 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [69.147.83.40]) by mx1.freebsd.org (Postfix) with ESMTP id 3BB7013C4A6 for ; Fri, 13 Jul 2007 06:30:05 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.1/8.14.1) with ESMTP id l6D6U4sd014761 for ; Fri, 13 Jul 2007 06:30:04 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.1/8.14.1/Submit) id l6D6U4O9014759; Fri, 13 Jul 2007 06:30:04 GMT (envelope-from gnats) Resent-Date: Fri, 13 Jul 2007 06:30:04 GMT Resent-Message-Id: <200707130630.l6D6U4O9014759@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Garrett Cooper Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id B27E516A402 for ; 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 ; 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 ; 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 To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.0 Cc: Subject: bin/114548: Possibly security risk in pkg_add(1) -- doesn't add packages properly from stdin X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Jul 2007 06:30:05 -0000 >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: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Fri Jul 13 06:30:04 GMT 2007 >Closed-Date: >Last-Modified: >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: >Unformatted: