Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 113741 - app-crypt/mit-krb5: memory corruption
Summary: app-crypt/mit-krb5: memory corruption
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Security
Classification: Unclassified
Component: Vulnerabilities (show other bugs)
Hardware: All Linux
: High minor
Assignee: Gentoo Security
URL:
Whiteboard: B3? [noglsa]
Keywords:
Depends on:
Blocks:
 
Reported: 2005-11-27 13:28 UTC by Fredrik Tolf
Modified: 2006-11-11 19:27 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
Fix for the bug (kerb-fcc-deref.patch.1,448 bytes, patch)
2005-12-02 17:53 UTC, Fredrik Tolf
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Fredrik Tolf 2005-11-27 13:28:56 UTC
In the latest Gentoo release of mit-krb5, ksu doesn't clean up its created
credentials cache upon exit, leaving them in /tmp indefinitely (until tmpwatch
runs). When I ran strace on a running ksu process, this is what happens:

# cat -A strace/ksu 
waitpid(22104, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], WSTOPPED) = 22104$
--- SIGCHLD (Child exited) @ 0 (0) ---$
setresuid32(-1, 0, -1)                  = 0$
setresuid32(-1, 0, -1)                  = 0$
stat64("M- ^C^B^A^I^A", 0xbfe761bc)            = -1 ENOENT (No such file or
directory)$
exit_group(0)                           = ?$

I used cat -A to make sure that the control characters in the stat call are
showing. That's an obvious sign of memory corruption, if you ask me. Since ksu
is a SUID root program and it corrupts memory, I'm kind of worried that this
might turn out to be an exploitable bug.

It seems that this problem is limited to Gentoo, since I haven't ever seen it
happen on other distros (including Fedora Core 4 and Ubuntu 5.10). It also
happens on all my Gentoo machines (I have three of them running the latest
mit-krb5 release so far), so it's not just a isolated event.
Comment 1 Thierry Carrez (RETIRED) gentoo-dev 2005-11-27 13:52:28 UTC
Auditors, please confirm...
Comment 2 Fredrik Tolf 2005-12-02 17:47:53 UTC
I took the time to debug this, and I found that this was indeed a bug, and that
it was also linked to another bug I had.

The bug was in src/lib/krb5/ccache/cc_file.c, in the dereference() function,
where there is a line like this:
    for (fccsp = &fccs; *fccsp == NULL; fccsp = &(*fccsp)->next)

Obviously, the loop condition shouldn't be "*fccsp == NULL", but "*fccsp !=
NULL". This leads to that the library frees the wrong ccache occasionally
(recurringly in ksu). Therefore, it is a matter of premature freeing of memory,
which may or may not be exploitible.

In any case, the bug is fixed in Kerberos 1.4.3, which, however, hasn't been
released in Gentoo.

If there are no plans to release 1.4.3 in Gentoo anytime soon, I think this bug
should at least be patched, since it not only is a potential security problem,
but also causes a number of other problems:
 * When using ksu, more and more ccache files will gather in /tmp.
 * When using ksu, the source ccache file isn't closed and might remain read
locked, which will cause processes that want to write lock the ccache to sleep
until ksu exits.
 * Might cause programs to segfault. I find it quite strange that lots of
programs haven't already segfaulted left and right, considering that this bug is
freeing the wrong memory. I guess most only keep one ccache file open at a time.
Comment 3 Fredrik Tolf 2005-12-02 17:52:06 UTC
I also realize now that since the source ccache file isn't being closed, it can
lead to the following situation:

User A ksus to user B. User A doesn't fully trust user B, so he runs kdestroy to
make sure that user B can't get hold of his TGT. However, unknowingly to user A,
ksu never closed the source ccache fd, which means that his shell, running as
user B, inherited that fd. User B can now ptrace the shell process and make it
read user A's TGT. User B can now impersonate user A.

This might not be a very common situation, but it isn't exactly impossible either.
Comment 4 Fredrik Tolf 2005-12-02 17:53:59 UTC
Created attachment 73966 [details, diff]
Fix for the bug

This patch fixes the bug. Apply with -p1 in the src directory.
Comment 5 rob holland (RETIRED) gentoo-dev 2005-12-18 13:05:59 UTC
fix is good, can't comment on exploitability, my knowledge of the usage isn't good enough.
Comment 6 Sune Kloppenborg Jeppesen (RETIRED) gentoo-dev 2006-01-02 13:16:46 UTC
kerberos please advise.
Comment 7 Seemant Kulleen (RETIRED) gentoo-dev 2006-01-31 10:26:46 UTC
I'd prefer that upstream advised on this issue. Frederick, have you notified upstream of this? If not, I'll be contacting them this afternoon.
Comment 8 Fredrik Tolf 2006-01-31 11:55:41 UTC
Upstream has already fixed this bug in later releases of Kerberos. It's just that while MIT has released Kerberos 1.4.3, Gentoo still only ships 1.4.1. Thus, it is safe to say that upstream is aware of and has acknowledged this as a bug.
Comment 9 Seemant Kulleen (RETIRED) gentoo-dev 2006-02-16 08:35:21 UTC
1.4.3 in portage, marked as ~  when that goes stable, I'll put in a version for ~ which should fix some of the other bugs people are seeing. For the purposes of security, the 1.4.3 ebuild now in should do.
Comment 10 Tavis Ormandy (RETIRED) gentoo-dev 2006-02-16 08:43:14 UTC
seemant has committed app-crypt/mit-krb5-1.4.3 to address this issue, moving in to vulnerabilities for arch stabilisation. 
Comment 11 Thierry Carrez (RETIRED) gentoo-dev 2006-02-16 10:33:23 UTC
Calling arches
Comment 12 Gustavo Zacarias (RETIRED) gentoo-dev 2006-02-16 12:18:50 UTC
sparc stable.
Comment 13 Markus Rothe (RETIRED) gentoo-dev 2006-02-16 12:40:28 UTC
ppc64 stable
Comment 14 René Nussbaumer (RETIRED) gentoo-dev 2006-02-16 13:30:20 UTC
Stable on hppa
Comment 15 Joe Jezak (RETIRED) gentoo-dev 2006-02-17 09:21:31 UTC
Marked ppc stable.
Comment 16 Joshua Jackson (RETIRED) gentoo-dev 2006-02-17 19:24:26 UTC
x86 stable
Comment 17 Bryan Østergaard (RETIRED) gentoo-dev 2006-02-18 04:23:44 UTC
Stable on alpha + ia64.
Comment 18 Joshua Kinard gentoo-dev 2006-02-19 19:06:03 UTC
mips stable.
Comment 19 Simon Stelling (RETIRED) gentoo-dev 2006-02-22 12:43:23 UTC
amd64 finally stable, sorry for the delay
Comment 20 Thierry Carrez (RETIRED) gentoo-dev 2006-02-22 13:17:27 UTC
Ready for GLSA vote
Comment 21 Stefan Cornelius (RETIRED) gentoo-dev 2006-02-23 12:02:38 UTC
Mhhhh, suid root and memory corruption ... i think it's better to have one, so a weak yes.
Comment 22 Thierry Carrez (RETIRED) gentoo-dev 2006-02-23 12:04:03 UTC
If it was sufficiently exploitable upstream would have had an advisory. I vote no.
Comment 23 Tavis Ormandy (RETIRED) gentoo-dev 2006-03-05 11:31:58 UTC
It's been fixed and we dont have any evidence that it is exploitable, so I would say no need to issue a glsa, weak NO.
Comment 24 Fredrik Tolf 2006-03-05 12:15:55 UTC
#23, it is definitely exploitable, as I showed in #3 (I tried it myself). That's a rather weak exploit, admittedly, but an exploit nonetheless.
Comment 25 Thierry Carrez (RETIRED) gentoo-dev 2006-03-06 09:38:44 UTC
Closing, feel free to reopen if you indended to vote yes.