The negative size buffer checks added in
f4c70589c (1.15.7) to the
write filters, ngx_output_chain() and the chain writer did not cover
the send chain callbacks. A buffer malformed after the filters
resulted in a bogus size being passed to a system call or ngx_memcpy().
Now the callbacks report such buffers and reject the chain as the
filters do: an alert with the buffer dump, a debug point, and
NGX_CHAIN_ERROR. ngx_ssl_send_chain() and ngx_wsasend_chain() also
check that a buffer is in memory, as ngx_output_chain_to_iovec() does.
continue;
}
+ if (!ngx_buf_in_memory(in->buf)) {
+ ngx_log_error(NGX_LOG_ALERT, c->log, 0,
+ "bad buf in SSL output chain "
+ "t:%d r:%d f:%d %p %p-%p %p %O-%O",
+ in->buf->temporary,
+ in->buf->recycled,
+ in->buf->in_file,
+ in->buf->start,
+ in->buf->pos,
+ in->buf->last,
+ in->buf->file,
+ in->buf->file_pos,
+ in->buf->file_last);
+
+ ngx_debug_point();
+
+ return NGX_CHAIN_ERROR;
+ }
+
+ if (in->buf->last < in->buf->pos) {
+ ngx_log_error(NGX_LOG_ALERT, c->log, 0,
+ "negative size buf in SSL output chain "
+ "t:%d r:%d f:%d %p %p-%p %p %O-%O",
+ in->buf->temporary,
+ in->buf->recycled,
+ in->buf->in_file,
+ in->buf->start,
+ in->buf->pos,
+ in->buf->last,
+ in->buf->file,
+ in->buf->file_pos,
+ in->buf->file_last);
+
+ ngx_debug_point();
+
+ return NGX_CHAIN_ERROR;
+ }
+
n = ngx_ssl_write(c, in->buf->pos, in->buf->last - in->buf->pos);
if (n == NGX_ERROR) {
break;
}
+ if (!ngx_buf_in_memory(in->buf)) {
+ ngx_log_error(NGX_LOG_ALERT, c->log, 0,
+ "bad buf in SSL output chain "
+ "t:%d r:%d f:%d %p %p-%p %p %O-%O",
+ in->buf->temporary,
+ in->buf->recycled,
+ in->buf->in_file,
+ in->buf->start,
+ in->buf->pos,
+ in->buf->last,
+ in->buf->file,
+ in->buf->file_pos,
+ in->buf->file_last);
+
+ ngx_debug_point();
+
+ return NGX_CHAIN_ERROR;
+ }
+
+ if (in->buf->last < in->buf->pos) {
+ ngx_log_error(NGX_LOG_ALERT, c->log, 0,
+ "negative size buf in SSL output chain "
+ "t:%d r:%d f:%d %p %p-%p %p %O-%O",
+ in->buf->temporary,
+ in->buf->recycled,
+ in->buf->in_file,
+ in->buf->start,
+ in->buf->pos,
+ in->buf->last,
+ in->buf->file,
+ in->buf->file_pos,
+ in->buf->file_last);
+
+ ngx_debug_point();
+
+ return NGX_CHAIN_ERROR;
+ }
+
size = in->buf->last - in->buf->pos;
if (size > buf->end - buf->last) {
continue;
}
+ if (in->buf->last < in->buf->pos) {
+ ngx_log_error(NGX_LOG_ALERT, c->log, 0,
+ "negative size buf in quic write buffer "
+ "t:%d r:%d f:%d %p %p-%p %p %O-%O",
+ in->buf->temporary,
+ in->buf->recycled,
+ in->buf->in_file,
+ in->buf->start,
+ in->buf->pos,
+ in->buf->last,
+ in->buf->file,
+ in->buf->file_pos,
+ in->buf->file_last);
+
+ ngx_debug_point();
+
+ return NGX_CHAIN_ERROR;
+ }
+
if (p == b->last || limit == 0) {
break;
}
if (ngx_buf_in_memory_only(cl->buf)) {
fd = SFV_FD_SELF;
+ if (cl->buf->last < cl->buf->pos) {
+ ngx_log_error(NGX_LOG_ALERT, c->log, 0,
+ "negative size buf in output chain "
+ "t:%d r:%d f:%d %p %p-%p %p %O-%O",
+ cl->buf->temporary,
+ cl->buf->recycled,
+ cl->buf->in_file,
+ cl->buf->start,
+ cl->buf->pos,
+ cl->buf->last,
+ cl->buf->file,
+ cl->buf->file_pos,
+ cl->buf->file_last);
+
+ ngx_debug_point();
+
+ return NGX_CHAIN_ERROR;
+ }
+
size = cl->buf->last - cl->buf->pos;
if (send + size > limit) {
return NGX_CHAIN_ERROR;
}
+ if (in->buf->last < in->buf->pos) {
+ ngx_log_error(NGX_LOG_ALERT, log, 0,
+ "negative size buf in output chain "
+ "t:%d r:%d f:%d %p %p-%p %p %O-%O",
+ in->buf->temporary,
+ in->buf->recycled,
+ in->buf->in_file,
+ in->buf->start,
+ in->buf->pos,
+ in->buf->last,
+ in->buf->file,
+ in->buf->file_pos,
+ in->buf->file_last);
+
+ ngx_debug_point();
+
+ return NGX_CHAIN_ERROR;
+ }
+
size = in->buf->last - in->buf->pos;
if (prev == in->buf->pos) {
return NGX_CHAIN_ERROR;
}
+ if (in->buf->last < in->buf->pos) {
+ ngx_log_error(NGX_LOG_ALERT, log, 0,
+ "negative size buf in output chain "
+ "t:%d r:%d f:%d %p %p-%p %p %O-%O",
+ in->buf->temporary,
+ in->buf->recycled,
+ in->buf->in_file,
+ in->buf->start,
+ in->buf->pos,
+ in->buf->last,
+ in->buf->file,
+ in->buf->file_pos,
+ in->buf->file_last);
+
+ ngx_debug_point();
+
+ return NGX_CHAIN_ERROR;
+ }
+
size = in->buf->last - in->buf->pos;
if (size > limit - total) {
continue;
}
+ if (!ngx_buf_in_memory(cl->buf)) {
+ ngx_log_error(NGX_LOG_ALERT, c->log, 0,
+ "bad buf in output chain "
+ "t:%d r:%d f:%d %p %p-%p %p %O-%O",
+ cl->buf->temporary,
+ cl->buf->recycled,
+ cl->buf->in_file,
+ cl->buf->start,
+ cl->buf->pos,
+ cl->buf->last,
+ cl->buf->file,
+ cl->buf->file_pos,
+ cl->buf->file_last);
+
+ ngx_debug_point();
+
+ return NGX_CHAIN_ERROR;
+ }
+
+ if (cl->buf->last < cl->buf->pos) {
+ ngx_log_error(NGX_LOG_ALERT, c->log, 0,
+ "negative size buf in output chain "
+ "t:%d r:%d f:%d %p %p-%p %p %O-%O",
+ cl->buf->temporary,
+ cl->buf->recycled,
+ cl->buf->in_file,
+ cl->buf->start,
+ cl->buf->pos,
+ cl->buf->last,
+ cl->buf->file,
+ cl->buf->file_pos,
+ cl->buf->file_last);
+
+ ngx_debug_point();
+
+ return NGX_CHAIN_ERROR;
+ }
+
size = cl->buf->last - cl->buf->pos;
if (send + size > limit) {