Skip to content

Commit 5ab8106

Browse files
a-denoyellecapflam
authored andcommitted
BUG/MINOR: h3: fix crash on STOP_SENDING receive after GOAWAY emission
After emitting a HTTP/3 GOAWAY frame, opening of streams higher than advertised ID was prevented. h3_attach operation would return success but without allocating H3S stream context for QCS. In addition, the stream would be immediately scheduled for RESET_STREAM emission. Despite the immediate stream close, the current is not sufficient enough and can cause crashes. When of this occurence can be found if STOP_SENDING is the first frame received for a stream. A crash would occur under qcc_recv_stop_sending() after h3_attach invokation, when h3_close() is used which try to access to H3S context. To fix this, change h3_attach API. In case of success, H3S stream context is always allocated, even if the stream will be scheduled for immediate close. This renders the code more reliable. This crash should be extremely rare, as it can only happen after GOAWAY emission, which is only used on soft-stop or reload. This should solve the second crash occurence reported on GH #2607. This must be backported up to 2.8. (cherry picked from commit 8583882) Signed-off-by: Christopher Faulet <[email protected]>
1 parent 75a9d54 commit 5ab8106

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

src/h3.c

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2200,34 +2200,18 @@ static int h3_close(struct qcs *qcs, enum qcc_app_ops_close_side side)
22002200
return 0;
22012201
}
22022202

2203+
/* Allocates HTTP/3 stream context relative to <qcs>. If the operation cannot
2204+
* be performed, an error is returned and <qcs> context is unchanged.
2205+
*
2206+
* Returns 0 on success else non-zero.
2207+
*/
22032208
static int h3_attach(struct qcs *qcs, void *conn_ctx)
22042209
{
22052210
struct h3c *h3c = conn_ctx;
22062211
struct h3s *h3s = NULL;
22072212

22082213
TRACE_ENTER(H3_EV_H3S_NEW, qcs->qcc->conn, qcs);
22092214

2210-
/* RFC 9114 5.2. Connection Shutdown
2211-
*
2212-
* Upon sending
2213-
* a GOAWAY frame, the endpoint SHOULD explicitly cancel (see
2214-
* Sections 4.1.1 and 7.2.3) any requests or pushes that have
2215-
* identifiers greater than or equal to the one indicated, in
2216-
* order to clean up transport state for the affected streams.
2217-
* The endpoint SHOULD continue to do so as more requests or
2218-
* pushes arrive.
2219-
*/
2220-
if (h3c->flags & H3_CF_GOAWAY_SENT && qcs->id >= h3c->id_goaway &&
2221-
quic_stream_is_bidi(qcs->id)) {
2222-
/* Reject request and do not allocate a h3s context.
2223-
* TODO support push uni-stream rejection.
2224-
*/
2225-
TRACE_STATE("reject stream higher than goaway", H3_EV_H3S_NEW, qcs->qcc->conn, qcs);
2226-
qcc_abort_stream_read(qcs);
2227-
qcc_reset_stream(qcs, H3_ERR_REQUEST_REJECTED);
2228-
goto done;
2229-
}
2230-
22312215
h3s = pool_alloc(pool_head_h3s);
22322216
if (!h3s) {
22332217
TRACE_ERROR("h3s allocation failure", H3_EV_H3S_NEW, qcs->qcc->conn, qcs);
@@ -2254,7 +2238,25 @@ static int h3_attach(struct qcs *qcs, void *conn_ctx)
22542238
h3s->type = H3S_T_UNKNOWN;
22552239
}
22562240

2257-
done:
2241+
/* RFC 9114 5.2. Connection Shutdown
2242+
*
2243+
* Upon sending
2244+
* a GOAWAY frame, the endpoint SHOULD explicitly cancel (see
2245+
* Sections 4.1.1 and 7.2.3) any requests or pushes that have
2246+
* identifiers greater than or equal to the one indicated, in
2247+
* order to clean up transport state for the affected streams.
2248+
* The endpoint SHOULD continue to do so as more requests or
2249+
* pushes arrive.
2250+
*/
2251+
if (h3c->flags & H3_CF_GOAWAY_SENT && qcs->id >= h3c->id_goaway &&
2252+
quic_stream_is_bidi(qcs->id)) {
2253+
TRACE_STATE("close stream outside of goaway range", H3_EV_H3S_NEW, qcs->qcc->conn, qcs);
2254+
qcc_abort_stream_read(qcs);
2255+
qcc_reset_stream(qcs, H3_ERR_REQUEST_REJECTED);
2256+
}
2257+
2258+
/* TODO support push uni-stream rejection. */
2259+
22582260
TRACE_LEAVE(H3_EV_H3S_NEW, qcs->qcc->conn, qcs);
22592261
return 0;
22602262

0 commit comments

Comments
 (0)