Closed Bug 430193 Opened 17 years ago Closed 1 year ago

Audit comi18n.cpp for string buffer abuse

Categories

(Thunderbird :: Security, defect)

x86
All
defect
Not set
critical

Tracking

(Not tracked)

RESOLVED WORKSFORME

People

(Reporter: bugmil.ebirol, Unassigned)

References

Details

(Keywords: sec-audit, Whiteboard: [sg:audit])

intlmime_encode_b, and and intlmime_encode_q functions in comi18n.cpp should be re-factored to prevent buffer overflows.
Flags: wanted-thunderbird3?
Flags: wanted-thunderbird3.0a2?
Thanks to David Bienvenu for pointing this out in #413874 >In comi18n.cpp, we protect overflowing the output buffer everywhere but here, >right? Those functions are internal to libmime. > > if (method == 'B') > enclen = intlmime_encode_b((const unsigned char *)ibuf, >strlen(ibuf), o); > else > enclen = intlmime_encode_q((const unsigned char *)ibuf, >strlen(ibuf), o);
OS: Mac OS X → All
It looks like the output buffer was allocated assuming worst-case expansion in apply_rfc2047_encoding() -- at least I think so. Confusing enough it's definitely worth an audit but for now I don't think this is actually exploitable. Watch out for integer overflows, too. "in+srclen" might wrap around, although in this case that should result in in > end so we'd skip the loop.
Whiteboard: [sg:investigate]
My comment from bug 432469: I looked throught the patch in bug 413874 and it seems to me that buffer overflow is still possible even when using PL_strncpyz(). An example: http://bonsai.mozilla.org/cvsblame.cgi?file=/mozilla/mailnews/mime/src/comi18n.cpp&rev=1.133&root=/cvsroot&mark=349,352-353#348 'obufsize' is declared as PRInt32. The buffer size parameter of PL_strncpyz() is declared PRUint32. Suppose the buffer is near full such that PL_strncpyz() cannot write the full length of 'encodedword_head'. We still do "obufsize -= encodedword_headlen" causing 'obufsize' to become negative. The next PL_strncpyz() to 'o' will be a buffer overflow. Briefly looking through the patch, I think all the places that updates the remaining buffer length needs to use strlen() to find out how much was actually copied. Also, I looked at the code for PL_strncpyz(): http://bonsai.mozilla.org/cvsblame.cgi?file=/mozilla/nsprpub/lib/libc/src/strcpy.c&rev=3.8&root=/cvsroot&mark=74-75#69 Silently accepting NULL src/dest hides programming errors. I'd like a fatal assert there in debug builds.
Blocks: 413874
Whiteboard: [sg:investigate] → [sg:critical?]
Do we need to spin off separate bugs from comment 4 and comment 5? Or is there progress being made in fixing those areas of code?
Assignee: bugmil.ebirol → nobody
Component: General → Security
QA Contact: general → thunderbird
dmose: this should probably block tb3, cc'ing you in case you aren't looking at the "wanted" flags.
Flags: wanted-thunderbird3.0a2? → blocking-thunderbird3?
Flags: blocking-thunderbird3? → blocking-thunderbird3+
Bug is already marked blocking-thunderbird3+.
Flags: wanted-thunderbird3?
Mats, can you respond to comment 6? Do we need spin-off bugs filed? What needs to be done to close the books on this bug?
taking to investigate c#4
Assignee: nobody → bienvenu
Target Milestone: --- → Thunderbird 3.0rc1
I believe that since we pre-allocate the buffer to a worst-case size for the expansions, this shouldn't be exploitable, so I'm clearing this from the blocking list. It's still worth leaving this open to really fix the code, though.
Flags: blocking-thunderbird3+
Whiteboard: [sg:critical?] → [sg:audit]
(In reply to David :Bienvenu from comment #11) > I believe that since we pre-allocate the buffer to a worst-case size for the > expansions, this shouldn't be exploitable If this isn't exploitable can we open this bug up?
yes, opening up.
Group: core-security
Keywords: sec-audit
Assignee: mozilla → nobody
Target Milestone: Thunderbird 3.0rc1 → ---

The functions in question do not exist anymore. https://searchfox.org/comm-central/source/mailnews/mime/src/comi18n.cpp

Status: NEW → RESOLVED
Closed: 1 year ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.