Bug List: (This bug is not in your last search results)   Show last search results      Search page      Enter new bug
Bug#: 245765
Alias:
Product:
Component:
Status: RESOLVED
Resolution: FIXED
Assigned To: Gentoo Security <security@gentoo.org>
Hardware:
OS:
Version:
Priority:
Severity:
Reporter: Stefan Behte <craig@gentoo.org>
Add CC:
CC:
Remove selected CCs
URL:
Summary:
Status Whiteboard:
Keywords:
Flags: Requestee:
 
 
  ()

Filename Description Type Creator Created Size Actions
Create a New Attachment (proposed patch, testcase, etc.) View All

Bug 245765 depends on: Show dependency tree
Bug 245765 blocks: 235770

Additional Comments: (this is where you put emerge --info)


Not eligible to see or edit group visibility for this bug.






View Bug Activity   |   Format For Printing   |   XML   |   Clone This Bug


Description:   Opened: 2008-11-05 22:14 0000
CVE-2008-4957 (http://nvd.nist.gov/nvd.cfm?cvename=CVE-2008-4957):
  find_flags in gccxml 0.9.0 allows local users to overwrite arbitrary
  files via a symlink attack on a /tmp/*.cxx temporary file.

------- Comment #1 From Stefan Behte 2008-11-05 22:15:15 0000 -------
DEBIAN: http://bugs.debian.org/496391
FILES: find_flags
CODE: http://dev.gentoo.org/~rbu/security/debiantemp/gccxml

------- Comment #2 From Mark Loeser 2008-11-12 01:06:06 0000 -------
Would it be sufficient to just remove the .cxx at the end?  It generates the
tempfile name from the following:

TESTFILE="find_flags_temp$GCCXML_PID"

------- Comment #3 From Stefan Behte 2008-11-12 10:58:31 0000 -------
No, that would make it even worse. I'll have look into it later.

------- Comment #4 From Stefan Behte 2008-11-12 19:55:09 0000 -------
Mark, you could still symlink a .cxx-less file to /etc/passwd.
Instead, I'd check if the file belongs to us, and if so, it's safe to use it
(if an attacker can create that file with our user account, we're already
owned...)

touch /tmp/$TESTFILE.cxx
if [ ! -O /tmp/$TESTFILE.cxx ]
then
        echo "Something nasty is happening here. Quitting."
        exit -1
fi

I don't know if there is a patch upstream (yet).

------- Comment #5 From Stefan Behte 2008-11-12 20:34:09 0000 -------
No patch in CVS.
There are more symlink issues, also see bug:
http://www.gccxml.org/Bug/view.php?id=8083

------- Comment #6 From Christian Hoffmann 2008-11-12 22:33:53 0000 -------
(In reply to comment #4)
> Mark, you could still symlink a .cxx-less file to /etc/passwd.
> Instead, I'd check if the file belongs to us, and if so, it's safe to use it
> (if an attacker can create that file with our user account, we're already
> owned...)
> 
> touch /tmp/$TESTFILE.cxx
> if [ ! -O /tmp/$TESTFILE.cxx ]
> then
>         echo "Something nasty is happening here. Quitting."
>         exit -1
> fi
I'm not entirely sure whether this is race condition safe, so I'd rather play
safe and use mktemp (or maybe mktemp -d and place all temp files in there).

------- Comment #7 From Stefan Behte 2008-11-12 22:42:26 0000 -------
It's not a race condition; if the file belongs to you, you're not entering the
if statement, if the file does not belong to you, the code snippet will exit;
the touching does not change ownership.

Still, mktemp is surely the right way to go.

------- Comment #8 From Christian Hoffmann 2008-11-12 22:57:19 0000 -------
(In reply to comment #7)
> It's not a race condition;
Right, found that out now as well, but ...

> if the file belongs to you, you're not entering the
> if statement
This assumption seems to be false...
> if the file does not belong to you, the code snippet will exit;
But it will always be owned by the user, except for the case where there is an
ordinary file (i.e. not a symlink) which is more than user-writable.
Uninteresting case, though.

My testings:

# somebody who is not me creates a symlink before the program is run
$ sudo ln -s foo bar
$ ls -la
lrwxrwxrwx  1 root      root         3 2008-11-12 23:47 bar -> foo

# program is run and uses your "checking code", i.e. calling touch
$ touch bar
$ ls -la
lrwxrwxrwx  1 root      root         3 2008-11-12 23:47 bar -> foo
-rw-r--r--  1 christian christian    0 2008-11-12 23:47 foo

$ [[ -O bar ]] && echo "Yes, file is owned by me (err... wait.. it isn't....)"
Yes, file is owned by me (err... wait.. it isn't....)

As you can see, both touch and -O do dereference symlinks. Checking for
symlinks first would introduce a race condition though... so... I don't see any
simple solution besides mktemp.

BTW: As there is no patch, this is rather [upstream] than [ebuild], imo.

------- Comment #9 From Stefan Behte 2008-11-13 21:33:03 0000 -------
Epic fail for me.
OF COURSE the file is owned by the current user, as the "evil user" links to it
so that the current user will destroy it. My test case was crap, we would need
an additional statement to check for symlinking; no need to discuss this
further as we both already agreed before that using mktemp is the way to go. As
said before in our IRC conversation, I was awfully tired, too. Sorry. :(

------- Comment #10 From Stefan Behte 2008-11-30 16:28:42 0000 -------
cpp: *ping*

------- Comment #11 From Mark Loeser 2008-11-30 19:58:41 0000 -------
(In reply to comment #10)
> cpp: *ping*
> 

I'm waiting for upstream and a solution: 
http://www.gccxml.org/Bug/view.php?id=8083

------- Comment #12 From Stefan Behte 2009-01-05 22:50:25 0000 -------
They've got a fix now, changing status whiteboard to [ebuild].

------- Comment #13 From Mark Loeser 2009-05-16 23:05:05 0000 -------
Sorry, this took so long.

I just added gccxml-0.9.0_pre20090516 to the tree, which has the fix and other
goodies.

------- Comment #14 From Robert Buchholz 2009-05-17 18:27:12 0000 -------
It seems gccxml_find_flags has been obsoleted (since it is missing from the
latest source file). The MIPS script is not fixed, as stated in the upstream
report. Is it being used on our mips architecture?

Arches, please test and mark stable:
=dev-cpp/gccxml-0.9.0_pre20090516
Target keywords : "amd64 arm ia64 ppc s390 sh x86"

------- Comment #15 From Christian Faulhammer 2009-05-18 15:08:04 0000 -------
x86 stable

------- Comment #16 From Brent Baude 2009-05-18 20:24:51 0000 -------
ppc done

------- Comment #17 From Tobias Heinlein 2009-05-22 10:10:16 0000 -------
amd64 stable

------- Comment #18 From Tobias Heinlein 2009-05-22 10:45:06 0000 -------
All supported arches done, entering [glsa?]. I vote YES.

------- Comment #19 From Raúl Porcel 2009-05-25 13:49:25 0000 -------
arm/ia64/s390/sh stable

------- Comment #20 From Robert Buchholz 2009-05-25 20:29:48 0000 -------
mips / cpp herd, can you please give some feedback regarding comment 14.  Is
the MIPSpro/find_flags being used on mips?

------- Comment #21 From Robert Buchholz 2009-05-25 20:38:56 0000 -------
YES as well, filed request

------- Comment #22 From Alex Legler 2009-09-09 13:35:36 0000 -------
GLSA 200909-11

Bug List: (This bug is not in your last search results)   Show last search results      Search page      Enter new bug