Closed
Bug 335535
Opened 19 years ago
Closed 19 years ago
potential int overflow in jsstr.c tagify().
Categories
(Core :: JavaScript Engine, defect)
Tracking
()
RESOLVED
FIXED
People
(Reporter: guninski, Assigned: brendan)
Details
(Keywords: fixed1.8.0.4, fixed1.8.1, Whiteboard: [sg:critical?])
Attachments
(2 files)
707 bytes,
text/html
|
Details | |
963 bytes,
patch
|
mrbkap
:
review+
dveditz
:
approval1.8.0.4+
|
Details | Diff | Splinter Review |
potential int overflow in jsstr.c tagify().
there is potential int overflow in jsstr.c tagify().
could only made it crash on a really perverted config: x86_64 linux with a
lot of virtual memory AND *32 bit compiled firefox*.
if it is possible to make a js string with length of 2^30-C with C small, this
may be exploitable in other configurations (personally can't make C less than
kilobytes on 32 bit linux yet).
testcase for 32 bit firefox for x64_64 linux to follow.
http://bonsai.mozilla.org/cvsblame.cgi?file=mozilla/js/src/jsstr.c&rev=3.125&mark=2162,2183,2187,2189#2162
in tagify:
2183 parlen = JSSTRING_LENGTH(param);
2187 taglen += JSSTRING_LENGTH(str) + 2 + endlen + 1; /* 'str</end>' */
2189 tagbuf = (jschar *) JS_malloc(cx, (taglen + 1) * sizeof(jschar));
so if str == param and JSTRING_LENGTH == 2^30-1
(2^30-1+2^30-1+C)*sizeof(jschar) will overflow 2^32-1
Reporter | ||
Comment 1•19 years ago
|
||
int overflow for x86_64 with 32 bit firefox
Reporter | ||
Updated•19 years ago
|
Component: General → JavaScript Engine
Product: Firefox → Core
Updated•19 years ago
|
Assignee: nobody → mrbkap
Whiteboard: [sg:critical?]
Assignee | ||
Comment 2•19 years ago
|
||
Don't see how earlier sums could exceed 2^32-1, so all we need is a length test.
BTW, I extracted this by hand from a jsstr.c with other changes, so line numbers are off -- patch(1) will cope.
/be
Attachment #219918 -
Flags: review?(mrbkap)
Reporter | ||
Comment 3•19 years ago
|
||
(In reply to comment #2)
> Created an attachment (id=219918) [edit]
> fix
>
> Don't see how earlier sums could exceed 2^32-1, so all we need is a length
> test.
>
brendan, let me explain that i crashed in the explained scenario.
according to you how much is:
2*2^30*sizeof(jschar)+C
C is small.
Reporter | ||
Comment 4•19 years ago
|
||
ooops, i flamed lamely.
my Comment #3 is buggy, so don't take it seriously.
i apologize.
Updated•19 years ago
|
Attachment #219918 -
Flags: review?(mrbkap) → review+
Updated•19 years ago
|
Assignee: mrbkap → brendan
Comment 5•19 years ago
|
||
Fix checked into trunk.
Status: NEW → RESOLVED
Closed: 19 years ago
Resolution: --- → FIXED
Updated•19 years ago
|
Flags: blocking1.8.0.3?
Comment 6•19 years ago
|
||
Comment on attachment 219918 [details] [diff] [review]
fix
I think we want this on the branches.
Attachment #219918 -
Flags: approval1.8.0.3?
Updated•19 years ago
|
Flags: blocking1.8.0.3? → blocking1.8.0.4?
Updated•19 years ago
|
Attachment #219918 -
Flags: approval1.8.0.3? → approval1.8.0.4?
Updated•19 years ago
|
Flags: blocking1.8.0.4? → blocking1.8.0.4+
Reporter | ||
Comment 7•19 years ago
|
||
i suspect that strings/objects with byte size near 2GB may cause other int troubles on 32 bit systems.
what about patching JS_malloc/JS_realloc this way:
JS_PUBLIC_API(void *)
JS_malloc(JSContext *cx, size_t nbytes)
{
void *p;
JS_ASSERT(nbytes != 0);
if (nbytes == 0)
nbytes = 1;
+ if (nbytes > 50*1024*1024) return NULL;
the limit may be configurable and having in mind there is already check for 0 the performance hit probably will be small.
Comment 8•19 years ago
|
||
Comment on attachment 219918 [details] [diff] [review]
fix
approved for 1.8.0 branch, a=dveditz for drivers
Attachment #219918 -
Flags: approval1.8.0.4? → approval1.8.0.4+
Updated•19 years ago
|
Whiteboard: [sg:critical?] → [sg:critical?] needs branch landing
Updated•19 years ago
|
Whiteboard: [sg:critical?] needs branch landing → [sg:critical?]
Comment 11•19 years ago
|
||
I don't know how to write this test for 32bit machines so that it doesn't run out of memory before finishing constructing the r string.
Flags: in-testsuite-
Reporter | ||
Comment 12•19 years ago
|
||
(In reply to comment #11)
> I don't know how to write this test for 32bit machines so that it doesn't run
> out of memory before finishing constructing the r string.
>
i tried a lot of testcases with large strings, but with no luck on 32 bit machines. not sure about the reason for failure. the testcase should be very close to this one imho.
similar "issues" are Bug 336409 and Bug 336410
Updated•19 years ago
|
Flags: blocking1.7.14?
Flags: blocking-aviary1.0.9?
Updated•19 years ago
|
Group: security
You need to log in
before you can comment on or make changes to this bug.
Description
•