Closed
Bug 718554
Opened 13 years ago
Closed 13 years ago
SSL_ForceHandshake returns wrong positive results after sending pending data
Categories
(NSS :: Libraries, defect, P1)
Tracking
(Not tracked)
RESOLVED
FIXED
3.13.2
People
(Reporter: briansmith, Assigned: briansmith)
References
Details
(Keywords: regression)
Attachments
(2 files)
|
7.25 KB,
patch
|
rrelyea
:
review+
|
Details | Diff | Splinter Review |
|
871 bytes,
patch
|
rrelyea
:
review+
wtc
:
superreview+
|
Details | Diff | Splinter Review |
This bug was caused by the patch for bug 676729.
See http://bonsai.mozilla.org/cvsblame.cgi?file=mozilla/security/nss/lib/ssl/sslsecur.c&rev=1.53&root=/cvsroot#382
The call to ssl_SendSavedWriteData sets rv to a positive number (the number of bytes sent) when ssl_SendSavedWriteData succeeds. However, the code that handles the result of ssl3_GatherCompleteHandshake assumes that rv == SECFailure going into the block, and so fails to set rv = SECFailure when ssl3_GatherCompleteHandshake returns a negative result. ssl3_GatherCompleteHandshake often returns -1/PR_WOULD_BLOCK_ERROR.
Further, since SSL_ForceHandshake returns SECStatus, it should never return a value other than SECSuccess, SECFailure, or SECWouldBlock; we agreed in another bug that SSL_ForceHandshake would never return SECWouldBlock.
Things that would have prevented this bug:
1. We should not initialize rv = SECFailure at the start of the function, because this masks a "variable was not initialized" warnings from the compiler that would have caught this bug.
2. We should have an automated test for this scenerio. (This bug was found in a new automated test I writing for bug 542832.)
3. We should use a block-scoped variable to store the result of ssl_SendSavedWriteData, like the gatherResult block-scoped variable that stores the result of ssl3_GatherCompleteHandshake.
4. The type of that local variable should be int, not SECStatus. SECStatus is an enum type, so we should not assign values to SECStatus variables other than SECFailure, SECWouldBlock, and SECSuccess. (A C compiler will not enforce this and most C compilers do not even have the option to warn about it; only C++ compilers issue diagnostics about this.)
| Assignee | ||
Updated•13 years ago
|
Assignee: nobody → bsmith
| Assignee | ||
Comment 1•13 years ago
|
||
Attachment #589112 -
Flags: superreview?(wtc)
Attachment #589112 -
Flags: review?(rrelyea)
| Assignee | ||
Comment 2•13 years ago
|
||
Without this patch, it is possible that SSL_ForceHandshake could return a SECSuccess (0) or a positive number such that a test for failure "!= SECFailure" or "< 0" would give the wrong result. In particular, I think SECSuccess could be returned if the EOF is reached on the connection; I think this condition may be under the control of an active MiTM. I am not sure to what extent this could be exploited. The internal (to libssl) state machine for the connection is not corrupted; only the application's understanding of the completion status of the handshake is affected. This could affect NPN connection coalescing, perhaps.
Attachment #589114 -
Flags: superreview?(wtc)
Attachment #589114 -
Flags: review?(rrelyea)
Comment 3•13 years ago
|
||
Comment on attachment 589114 [details] [diff] [review]
Fix [v1]
r=wtc. Thanks for the analysis and the fix.
Attachment #589114 -
Flags: superreview?(wtc) → superreview+
Comment 4•13 years ago
|
||
I extended bsmith's great analysis of the bug's risk in comment 2.
The call to ssl_SendSavedWriteData returns either -1 or a positive
number because the underlying write or send system call should return
-1 with EAGAIN/EWOULDBLOCK rather than returning 0 when it cannot
send anything from ss->pendingBuf.
So this bug won't affect a caller that tests for a successful
handshake completion by comparing the return value of SSL_ForceHandshake
with SECSuccess (0).
If the EOF is reached on the connection, the bug should cause
SSL_ForceHandshake to return a positive integer rather than
SECSuccess.
Status: NEW → ASSIGNED
Comment 5•13 years ago
|
||
I checked in the patch "Fix [v1]" on the NSS trunk (NSS 3.13.2).
Checking in sslsecur.c;
/cvsroot/mozilla/security/nss/lib/ssl/sslsecur.c,v <-- sslsecur.c
new revision: 1.54; previous revision: 1.53
done
Status: ASSIGNED → RESOLVED
Closed: 13 years ago
Priority: -- → P1
Resolution: --- → FIXED
Version: trunk → 3.13.2
Comment 6•13 years ago
|
||
Comment on attachment 589114 [details] [diff] [review]
Fix [v1]
r+ rrelyea
Attachment #589114 -
Flags: review?(rrelyea) → review+
Comment 7•13 years ago
|
||
Comment on attachment 589112 [details] [diff] [review]
Testcase
r+ assuming update to base loopback code.
bob
Attachment #589112 -
Flags: review?(rrelyea) → review+
| Assignee | ||
Updated•11 years ago
|
Attachment #589112 -
Flags: superreview?(wtc)
You need to log in
before you can comment on or make changes to this bug.
Description
•