diff options
author | Roman Arutyunyan <arut@nginx.com> | 2016-01-26 16:46:59 +0300 |
---|---|---|
committer | Roman Arutyunyan <arut@nginx.com> | 2016-01-26 16:46:59 +0300 |
commit | a3d42258d97ebd0b638c20976654d3edfbaf943f (patch) | |
tree | a30c3a29a99426ee6ce03523f4c1967671286f5c /src/core/ngx_resolver.h | |
parent | b1a110e3a457d98f0eaffb0cb0e646df9178024f (diff) |
Resolver: fixed use-after-free memory accesses with CNAME.
When several requests were waiting for a response, then after getting
a CNAME response only the last request's context had the name updated.
Contexts of other requests had the wrong name. This name was used by
ngx_resolve_name_done() to find the node to remove the request context
from. When the name was wrong, the request could not be properly
cancelled, its context was freed but stayed linked to the node's waiting
list. This happened e.g. when the first request was aborted or timed
out before the resolving completed. When it completed, this triggered
a use-after-free memory access by calling ctx->handler of already freed
request context. The bug manifests itself by
"could not cancel <name> resolving" alerts in error_log.
When a request was responded with a CNAME, the request context kept
the pointer to the original node's rn->u.cname. If the original node
expired before the resolving timed out or completed with an error,
this would trigger a use-after-free memory access via ctx->name in
ctx->handler().
The fix is to keep ctx->name unmodified. The name from context
is no longer used by ngx_resolve_name_done(). Instead, we now keep
the pointer to resolver node to which this request is linked.
Keeping the original name intact also improves logging.
Diffstat (limited to 'src/core/ngx_resolver.h')
-rw-r--r-- | src/core/ngx_resolver.h | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/src/core/ngx_resolver.h b/src/core/ngx_resolver.h index 22f249595..07fa25785 100644 --- a/src/core/ngx_resolver.h +++ b/src/core/ngx_resolver.h @@ -161,6 +161,8 @@ struct ngx_resolver_ctx_s { ngx_uint_t quick; /* unsigned quick:1; */ ngx_uint_t recursion; ngx_event_t *event; + + ngx_resolver_node_t *node; }; |