<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "http://bugs.gentoo.org/bugzilla.dtd">

<bugzilla version="2.22.7"
          urlbase="http://bugs.gentoo.org/"
          maintainer="bugzilla@gentoo.org"
>

    <bug>
          <bug_id>46998</bug_id>
          
          <creation_ts>2004-04-06 14:33 0000</creation_ts>
          <short_desc>&lt;=app-arch/sharutils-4.2.1-r8 - Multiple command line vulnerabilities.</short_desc>
          <delta_ts>2004-05-20 14:15:58 0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>Gentoo Security</product>
          <component>GLSA Errors</component>
          <version>unspecified</version>
          <rep_platform>All</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <keywords>SECURITY</keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>ruth@gentoo.org</reporter>
          <assigned_to>security@gentoo.org</assigned_to>
          <cc>arch-maintainers@gentoo.org</cc>
    
    <cc>base-system@gentoo.org</cc>

      

      
          <flag name="Assigned_To"
                status="?"
                setter="koon@gentoo.org"
              requestee="koon@gentoo.org"
          />
          <long_desc isprivate="0">
            <who>ruth@gentoo.org</who>
            <bug_when>2004-04-06 14:33:44 0000</bug_when>
            <thetext>from bugtraq@securityfocus.com:


...
Details
########

A stack-based buffer overflow vulnerability exists in
the popular &apos;shar&apos; utility packaged in the GNU
sharutils distribution, due to lack of bounds checking
when handling the &apos;-o&apos; command-line option.

During the command-line argument parsing routine, when
the &apos;-o&apos; flag is encountered, &apos;shar&apos; performs a
&apos;strcpy()&apos; call to blindly copy the user-supplied
argument after &apos;-o&apos; without bounds checking, into a
fixed length buffer, output_base_name, which has only
50 allocated to it.
...
Solution
#########

I contacted the vendor, GNU, and received no response
within 4 1/2 days.

Although this issue isn&apos;t to be considered a serious
security threat, there are instances where this can be
exploited by a would-be attacker to execute code, such
as in the circumstances suggested above (cgi script,
sXid program, etc).  Therefore, it would be considered
good practice to apply the fix regardless of whether
your system is likely to be compromised as a result of
the issue.

I have written a simple patch below to fix the buffer
overflow bug:


--- shar-bof.patch ---

--- shar.1.c    2004-04-06 16:26:55.000000000 +0100
+++ shar.c      2004-04-06 16:32:32.000000000 +0100
@@ -1905,7 +1905,7 @@
        break;

       case &apos;o&apos;:
-       strcpy (output_base_name, optarg);
+       strncpy (output_base_name, optarg,
sizeof(output_base_name));
        if (!strchr (output_base_name, &apos;%&apos;))
          strcat (output_base_name, &quot;.%02d&quot;);
        part_number = 0;
--- EOF ---
...

above text is a snippet from the bugtraq maillist.
Apply the patch, and rebuild:

---
bash# patch &lt; shar-bof.patch &amp;&amp; make &amp;&amp; make install



so long
rootshell


 

Reproducible: Always
Steps to Reproduce:
1.
2.
3.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>vapier@gentoo.org</who>
            <bug_when>2004-04-06 14:56:02 0000</bug_when>
            <thetext>sharutils-4.2.1-r8 has this patch

i dont think we need a GLSA as this doesnt seem to have any exploitable-ness to it ...</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>koon@gentoo.org</who>
            <bug_when>2004-04-07 08:48:29 0000</bug_when>
            <thetext>4.2.1-r8 must be stable before we get into GLSA process.
Resetting component to Security.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>vapier@gentoo.org</who>
            <bug_when>2004-04-07 15:46:08 0000</bug_when>
            <thetext>i tested on x86 / sparc / hppa so those are stable now</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>agriffis@gentoo.org</who>
            <bug_when>2004-04-07 18:55:10 0000</bug_when>
            <thetext>alpha and ia64 are stable</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>kumba@gentoo.org</who>
            <bug_when>2004-04-07 21:31:25 0000</bug_when>
            <thetext>Stable on mips.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>solar@gentoo.org</who>
            <bug_when>2004-04-08 02:35:06 0000</bug_when>
            <thetext>sharutils-4.2.1-r8 bug update. Currently in cvs portage tree as.
KEYWORDS=&quot;x86 ~amd64 ~ppc sparc alpha hppa ia64 ~ppc64 s390 mips&quot;

Adding amd64 &amp; ppc to this bug.

I would think this would fall under the &quot;good practice&quot; vs GLSA and thus 
the &apos;Severity&apos; could be lowered from critical to normal. Users can
usually walk all over themselves from the command line.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>avenj@gentoo.org</who>
            <bug_when>2004-04-08 07:36:51 0000</bug_when>
            <thetext>Marked stable on amd64</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>solar@gentoo.org</who>
            <bug_when>2004-04-09 07:22:14 0000</bug_when>
            <thetext>While adding another patch to the sharutils bug that Florian had sent us
in mail, I noticed that the code lacked bounds checking a few lines
below in the same -o option.

--- 1907,1912 ----
        case &apos;o&apos;:
        strcpy (output_base_name, optarg);
+       memset(output_base_name, &apos;\0&apos;, sizeof(output_base_name));
+       strncpy (output_base_name, optarg, sizeof(output_base_name)-1);
        if (!strchr (output_base_name, &apos;%&apos;))
          strcat (output_base_name, &quot;.%02d&quot;);

As we can see we can fill the string up to sizeof(blah)-1 but what if 
the string contains a format identifier? It will overflow right again.
Not only will it overflow but we have the full makings here of a format
string vuln. Check it out..

solar@simple sharutils $ shar -o `perl -e &apos;print &quot;%p&quot; x 54&apos;`
solar@simple sharutils $ ls
solar@simple sharutils $ shar -o `perl -e &apos;print &quot;%p&quot; x 54&apos;`
shar: No input files
Try `shar --help&apos; for more information.
solar@simple sharutils $ ls
0x10x2e80f0200x30356230x5e2e60c80x2e8e1dd70x30x5e2e62a40xe25c7dd0xe25ecc00xe25eff00xe25f1e00xe25f2120x5e2e62580xe258dcd0xe25f1e00x250x320xe25ecc0(nil)0x2e82dd500x2e8253f00x2e80fb200x30x2e80fda80x2e80eff8

# fun with all the format identifiers...
shar -o `perl -e &apos;print &quot;%d&quot; x 54&apos;`
shar -o `perl -e &apos;print &quot;%s&quot; x 54&apos;`

It&apos;s safe to say this is not fixed and new patch should be created.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>solar@gentoo.org</who>
            <bug_when>2004-04-13 13:26:10 0000</bug_when>
            <thetext>I&apos;m reviewing this patch shortly.

http://marc.theaimsgroup.com/?l=bugtraq&amp;m=108164583423126&amp;w=2</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>solar@gentoo.org</who>
            <bug_when>2004-04-13 14:43:23 0000</bug_when>
            <thetext>Ok patch works for the -o format string problem.  But while looking over
other areas of code in sharutils I found what looks like more undesired 
voodoo.. Actually quite a bit of it.

This thing needs either a complete rewrite or a full audit in my
opinion. Neither of which I intend to do.. (Volunteers Welcome)

I also can&apos;t make heads/tails of who to exactly mail upstream about all 
this.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>klieber@gentoo.org</who>
            <bug_when>2004-04-20 04:43:43 0000</bug_when>
            <thetext>OK, the only semi-relevant email address I can find is bug-gnu-utils@prep.ai.mit.edu, which is listed in the README included with the sharutils sources.  

I contacted them and asked them to look at our bug here and provide some sort of response.  (and hopefully a patch)
</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>klieber@gentoo.org</who>
            <bug_when>2004-04-20 04:52:03 0000</bug_when>
            <thetext>OK, Google proved its worth once more.  The current active address for bug-gnu-utils seems to be bug-gnu-utils@gnu.org.  Looking at the archives[1] for the mailing list, it appears there are two semi-active maintainers of sharutils; Karl Eichwalder &lt;keichwa@gmx.net&gt; and Paul Eggert &lt;eggert@twinsun.com&gt;.

Solar -- since you&apos;re most familiar with the issues you&apos;ve found in sharutils (outside of the -o issue) would you mind emailing these folks and asking for their input?  

[1]http://mail.gnu.org/archive/html/bug-gnu-utils/</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>solar@gentoo.org</who>
            <bug_when>2004-04-23 01:01:31 0000</bug_when>
            <thetext>mail sent.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>solar@gentoo.org</who>
            <bug_when>2004-05-15 09:38:26 0000</bug_when>
            <thetext>Created an attachment (id=31485)
command line handling

From:	Karl Eichwalder &lt;ke@gnu.franken.de
To:	solar@gentoo.org
Cc:	eggert@twinsun.com
Subject:	Re: &lt;=app-arch/sharutils-4.2.1-r8 - Multiple command line
vulnerabilities.
Date:	Sat, 15 May 2004 11:19:19 +0200

Thanks for the info; I&apos;m going to add tht appended patch supplied by
Suse Linux.  My sharutils CVS is here:
http://developer.berlios.de/projects/sharutils/ - if one of you wants
to become a &quot;developer&quot; or a &quot;project admin&quot; please drop me a line.

2004-05-15  Karl Eichwalder  &lt;ke@gnu.franken.de&gt;

	* shar.c (open_output): Fix command line handling; reported by Ned
	Ludd: http://bugs.gentoo.org/show_bug.cgi?id=46998
	Use patch supplied by Michael Schr</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>solar@gentoo.org</who>
            <bug_when>2004-05-15 09:38:26 0000</bug_when>
            <thetext>Created an attachment (id=31485)
command line handling

From:	Karl Eichwalder &lt;ke@gnu.franken.de
To:	solar@gentoo.org
Cc:	eggert@twinsun.com
Subject:	Re: &lt;=app-arch/sharutils-4.2.1-r8 - Multiple command line
vulnerabilities.
Date:	Sat, 15 May 2004 11:19:19 +0200

Thanks for the info; I&apos;m going to add tht appended patch supplied by
Suse Linux.  My sharutils CVS is here:
http://developer.berlios.de/projects/sharutils/ - if one of you wants
to become a &quot;developer&quot; or a &quot;project admin&quot; please drop me a line.

2004-05-15  Karl Eichwalder  &lt;ke@gnu.franken.de&gt;

	* shar.c (open_output): Fix command line handling; reported by Ned
	Ludd: http://bugs.gentoo.org/show_bug.cgi?id=46998
	Use patch supplied by Michael Schröder: http://bugzilla.suse.de
	[#39122, password protected].
</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>solar@gentoo.org</who>
            <bug_when>2004-05-15 09:55:03 0000</bug_when>
            <thetext>Updated existing patch in portage tree but revision bumped to force updates.

sharutils-4.2.1-r9.ebuild:
KEYWORDS=&quot;~x86 ~amd64 ~ppc ~sparc ~alpha ~hppa ~ia64 ~ppc64 ~s390 ~mips&quot;</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>koon@gentoo.org</who>
            <bug_when>2004-05-15 10:59:14 0000</bug_when>
            <thetext>arch-maintainers : please mark stable on all arches (except arm)</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>gustavoz@gentoo.org</who>
            <bug_when>2004-05-15 11:27:50 0000</bug_when>
            <thetext>Marked stable on sparc.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>gmsoft@gentoo.org</who>
            <bug_when>2004-05-15 13:12:31 0000</bug_when>
            <thetext>Marked stable on hppa.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>kumba@gentoo.org</who>
            <bug_when>2004-05-15 13:18:03 0000</bug_when>
            <thetext>Marked stable on mips.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>avenj@gentoo.org</who>
            <bug_when>2004-05-15 13:27:08 0000</bug_when>
            <thetext>Stable on amd64 and x86</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>kloeri@gentoo.org</who>
            <bug_when>2004-05-15 13:54:49 0000</bug_when>
            <thetext>Stable on alpha.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>lu_zero@gentoo.org</who>
            <bug_when>2004-05-15 18:51:16 0000</bug_when>
            <thetext>Stable on ppc</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>koon@gentoo.org</who>
            <bug_when>2004-05-16 03:15:45 0000</bug_when>
            <thetext>Ready for a GLSA draft</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>solar@gentoo.org</who>
            <bug_when>2004-05-16 10:08:17 0000</bug_when>
            <thetext>Send a GLSA if you want. 
But please note that further auditing should be done on sharutils.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>koon@gentoo.org</who>
            <bug_when>2004-05-16 10:10:30 0000</bug_when>
            <thetext>GLSA drafted for the case we need it...</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>koon@gentoo.org</who>
            <bug_when>2004-05-20 14:15:58 0000</bug_when>
            <thetext>Not really exploitable so closed without GLSA.</thetext>
          </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>31485</attachid>
            <date>2004-05-15 09:38 0000</date>
            <desc>command line handling</desc>
            <filename>attachment.diff</filename>
            <type>text/plain</type>
            <data encoding="base64">SW5kZXg6IHNyYy9zaGFyLmMKPT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PQpSQ1MgZmlsZTogL2hvbWUva2UvY3Zzcm9vdC9z
aGFydXRpbHMvc3JjL3NoYXIuYyx2CnJldHJpZXZpbmcgcmV2aXNpb24gMS4yMgpkaWZmIC11IC1y
MS4yMiBzaGFyLmMKLS0tIHNyYy9zaGFyLmMJMiBEZWMgMjAwMiAyMDo1MjoxMCAtMDAwMAkxLjIy
CisrKyBzcmMvc2hhci5jCTE1IE1heSAyMDA0IDA5OjEzOjE2IC0wMDAwCkBAIC0yNTUsMTEgKzI1
NSwxMSBAQAogLyogUG9zaXRpb24gZm9yIGZpcnN0IGZpbGUgaW4gdGhlIHNoYXIgZmlsZS4gICov
CiBzdGF0aWMgb2ZmX3QgZmlyc3RfZmlsZV9wb3NpdGlvbjsKIAotLyogQmFzZSBmb3Igb3V0cHV0
IGZpbGVuYW1lLiAgRklYTUU6IE5vIGZpeCBsaW1pdCBpbiBHTlUuLi4gKi8KLXN0YXRpYyBjaGFy
IG91dHB1dF9iYXNlX25hbWVbNTBdOworLyogQmFzZSBmb3Igb3V0cHV0IGZpbGVuYW1lLiAgKi8K
K3N0YXRpYyBjaGFyICpvdXRwdXRfYmFzZV9uYW1lOwogCi0vKiBBY3R1YWwgb3V0cHV0IGZpbGVu
YW1lLiAgRklYTUU6IE5vIGZpeCBsaW1pdCBpbiBHTlUuLi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7CisgICAgICAgIGlmICghb3V0cHV0X2Jhc2VfbmFtZSkKKwkg
IHsKKwkgICAgZnByaW50ZiAoc3RkZXJyLCBfKCJpbGxlZ2FsIG91dHB1dCBwcmVmaXhcbiIpKTsK
KwkgICAgZXhpdCAoRVhJVF9GQUlMVVJFKTsKKwkgIH0KIAlwYXJ0X251bWJlciA9IDA7CiAJb3Bl
bl9vdXRwdXQgKCk7CiAJYnJlYWs7Cg==
</data>        

          </attachment>
    </bug>

</bugzilla>