Commit de8e8c9
committed
Fix ALPN resolver being collected while OpenSSL still holds it
`SSLContext.alpn_set_resolver` hands the resolver to OpenSSL as ALPN
select callback data. OpenSSL keeps a raw pointer to it and reads it live
from the `SSL_CTX` on every server handshake. Nothing on the Pony side
kept the Pony `SSLContext` alive once the caller dropped it: a session
held only the raw `SSL_CTX` pointer, which keeps the C context alive
through a refcount but is invisible to the garbage collector. So the
context, and the resolver it holds, could be collected while a session
made from it was still handshaking, and a peer connecting would drive a
server handshake into freed memory.
A session now holds its `SSLContext`. The context holds the current
resolver, so one live session keeps both alive, and the same fix covers
setting the resolver after a session exists and replacing it. To hold the
context, a session needs a sendable reference to it, and it has to be
`val` rather than `tag` because the garbage collector does not trace a
`tag`'s fields, so `client` and `server` take a `val` receiver. That also
makes reconfiguring a context after making sessions from it impossible to
write. `alpn_set_resolver` and the `ALPNProtocolResolver` interface take
`val` for the same sharing reason.
Closes #69
Closes #831 parent 06a6527 commit de8e8c9
7 files changed
Lines changed: 416 additions & 55 deletions
File tree
- .release-notes
- examples/ssl-client-server-example
- ssl/net
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| 20 | + | |
| 21 | + | |
19 | 22 | | |
20 | 23 | | |
21 | 24 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| |||
0 commit comments