Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 75604 - x11-terms/aterm, x11-terms/xterm: possible vulnerabilities
Summary: x11-terms/aterm, x11-terms/xterm: possible vulnerabilities
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Security
Classification: Unclassified
Component: Auditing (show other bugs)
Hardware: All All
: High normal (vote)
Assignee: Gentoo Security
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-12-24 19:47 UTC by Tavis Ormandy (RETIRED)
Modified: 2005-02-15 09:07 UTC (History)
2 users (show)

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


Attachments
xterm patch (xterm-mem_lock-security.diff,437 bytes, patch)
2004-12-24 19:48 UTC, Tavis Ormandy (RETIRED)
Details | Diff
aterm patch (aterm-scrolling_race_condition-security.diff,455 bytes, patch)
2004-12-24 19:48 UTC, Tavis Ormandy (RETIRED)
Details | Diff
xterm patch (fixed typo) (xterm-mem_lock-security.diff,437 bytes, patch)
2004-12-25 02:47 UTC, Tavis Ormandy (RETIRED)
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tavis Ormandy (RETIRED) gentoo-dev 2004-12-24 19:47:51 UTC
I though it might be interesting to see if it could be possible to execute code via escape codes sent to a victims terminal, by getting them to view a file with cat or less -r, or via some other application (mua[1], or tail'ing syslog messages, for example) that doesn't filter escape sequences (see [1] for lots of examples if you're interested).

H.D. Moore discovered some interesting oddities in his paper[2] , although he was more interested in abusing legitimate functions, I'm interested in finding bugs that might lead to a compromise.

I briefly checked aterm, xterm and Eterm. 

Eterm's developer has obviously been working hard since H.D. Moore's criticism, I couldn't spot any way to do anything strange with the latest version, and it was easily the most resilient, I couldnt get it to dump core or stop responding, which is trivially easy with the others I tested.

I had a little more success with xterm, getting it to hang is fairly trivial, but one thing that jumped out at me was you could bypass the margin sanity checks by using some of the more obscure escape sequences, for example:

$ printf "%b" \\x9B\\xBB\\x32\\x72\\x0A\\x1B\\x5B\\x32\\x34\\x3B\\x31\\x48\\x1B\\xEC\\x0A\\x8D

* use set scrolling region to set bottom margin to 0
* move the cursor to row 23 (tput cup 23)
* use HP_MEM_LOCK to set the top margin to the current position
* use Reverse Index (tput ri) to trigger a line insert
* using various positions or sequence variations you can overflow an integer and control a malloc/realloc.
* I know the general rule is if a malloc() uses a user-specified argument it's gameover security-wise, perhaps someone on the security team with a little more expertise can take a look, i think it might be promising.

Regardless, it's an easy fix, and probably worth the one line of code to add a sanity check to the HP_MEM_UNLOCK case, closing the loop.

I also spotted an oddity in aterm, a race condition that results in a double free(), I don't know whether this is exploitable or not, but I suspect it might be in the right (unlikely, but perhaps possible) conditions. Basically, if a child process exits during a scroll operation, aterm is sometimes interrupted while rearranging the elements of an array (the text buffers that an attacker can send), which can result in a double free() (you can start aterm with a huge buffer to improve the chances of beating the race condition if you want to experiment, aterm -sl 5000, for example).

Again, someone from the security team might like to take a look, but I think it's worth being proactive and applying these patches rather than waiting for a PoC :)

Patches attached, feel free to disregard if appropriate :)

[1] http://www.digitaldefense.net/labs/papers/Termulation.txt
Comment 1 Tavis Ormandy (RETIRED) gentoo-dev 2004-12-24 19:48:23 UTC
Created attachment 46846 [details, diff]
xterm patch
Comment 2 Tavis Ormandy (RETIRED) gentoo-dev 2004-12-24 19:48:41 UTC
Created attachment 46847 [details, diff]
aterm patch
Comment 3 Tavis Ormandy (RETIRED) gentoo-dev 2004-12-25 02:47:12 UTC
Created attachment 46857 [details, diff]
xterm patch (fixed typo)
Comment 4 Dan Margolis (RETIRED) gentoo-dev 2004-12-27 15:16:54 UTC
I can't really do anything about this right now, because I'm away from my Gentoo box and sorta half on vacation. Unfortunately, the rest of the Audit team is similarly disposed. 

The patches *look* semi-reasonable, but perhaps the xterm and aterm source could both be reviewed a bit more by one of us in the future. 

In the meantime, I'm going to CC X11 and aterm's maintainer and hope that they'd be willing to check out these patches (or, perhaps someone else on the security team could do us the favor). If nobody else deals with this soon, I'll be able to get to it in about two weeks. 

Thanks, Tavis
Comment 5 Seemant Kulleen (RETIRED) gentoo-dev 2004-12-28 08:18:02 UTC
Adding Thomas Dickey so that we can get his opinion on this stuff.
Comment 6 Thomas Dickey 2004-12-28 09:33:11 UTC
I'll add it to my to-do list (am expecting to work on xterm on
Thursday).  Perhaps a list of the "trivially easy" issues would
be useful.
Comment 7 Tavis Ormandy (RETIRED) gentoo-dev 2005-01-09 11:35:20 UTC
Hi Thomas, although causing a hang seemed easy during my testing I didnt make a note of how I accomplished it and unfortunately cannot seem to reproduce it! Please disregard that comment and I'll make a proper report if I can get a testcase.

Incidentally, I hope you accept this report in the "many eyes" spirit it was intended and not whining, I think I could have worded the report a little better :)
Comment 8 Thomas Dickey 2005-01-09 12:17:23 UTC
Thanks anyway - I'm interested in fixing things like that,
of course.

I'm working right now on issues related to the margins.
That's really part of a larger problem (as you may see by
adding -Wconversion to the compiler warnings).  Patch #198
will have a lot fewer of those, and make some additional
checks.
Comment 9 Thomas Dickey 2005-01-16 06:14:08 UTC
see http://invisible-island.net/xterm/xterm.log.html#xterm_198
Comment 10 Donnie Berkholz (RETIRED) gentoo-dev 2005-01-21 00:31:59 UTC
Added xterm-199, which fixes this. Thanks Thomas.
Comment 11 Dan Margolis (RETIRED) gentoo-dev 2005-02-05 07:31:06 UTC
OK, if someone could fix aterm, I'll CC the archs and try to get them marked stable. 

I suppose we could investigate the exploitability more, but realistically, I won't have time. Security Team, care to vote on issuing a GLSA for these matters (once they're cleared up)>
Comment 12 Michal Januszewski (RETIRED) gentoo-dev 2005-02-06 11:45:05 UTC
I had a look at the aterm code. Please correct me if I'm wrong, but from what I can see in the scroll_text() function, the elements in the buffer are shifted by <count> elements, not by 1. Therefore, your patch would only prevent the double free in case count == 1.
Comment 13 Michal Januszewski (RETIRED) gentoo-dev 2005-02-06 13:39:57 UTC
Fixed in aterm-0.4.2-r12 and aterm-1.00_beta2.
Comment 14 Tavis Ormandy (RETIRED) gentoo-dev 2005-02-07 07:20:22 UTC
Thanks Michal, as I mentioned on irc you were right about the scroll count :)
Comment 15 Tavis Ormandy (RETIRED) gentoo-dev 2005-02-15 09:07:53 UTC
thanks everyone, resolving.