comparison src/core/ngx_resolver.h @ 6351:497d0cff8ace

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.
author Roman Arutyunyan <arut@nginx.com>
date Tue, 26 Jan 2016 16:46:59 +0300
parents 7316c57e4fe7
children 69977457e1a6
comparison
equal deleted inserted replaced
6350:a5767988c022 6351:497d0cff8ace
159 ngx_msec_t timeout; 159 ngx_msec_t timeout;
160 160
161 ngx_uint_t quick; /* unsigned quick:1; */ 161 ngx_uint_t quick; /* unsigned quick:1; */
162 ngx_uint_t recursion; 162 ngx_uint_t recursion;
163 ngx_event_t *event; 163 ngx_event_t *event;
164
165 ngx_resolver_node_t *node;
164 }; 166 };
165 167
166 168
167 ngx_resolver_t *ngx_resolver_create(ngx_conf_t *cf, ngx_str_t *names, 169 ngx_resolver_t *ngx_resolver_create(ngx_conf_t *cf, ngx_str_t *names,
168 ngx_uint_t n); 170 ngx_uint_t n);