[PATCH] Fixing buffer over-read when accepting unix domain sockets

Yichun Zhang (agentzh) agentzh at gmail.com
Wed Jul 10 01:29:30 UTC 2013


I've found a heap buffer over-read issue in the Nginx core via clang's
AddressSanitizer tool when Nginx is accepting a unix domain socket in

At least on Linux, accept and accept4 syscalls always return a socket
length of 2 for unix domain sockets, which makes later accesses to
saun->sun_path in function ngx_sock_ntop invalid (because
sizeof(sa->sa_family) == sizeof(short) == 2).

The patch attached fixes this issue.


--- nginx-1.4.1/src/event/ngx_event_accept.c 2013-05-06 03:26:50.000000000 -0700
+++ nginx-1.4.1-patched/src/event/ngx_event_accept.c 2013-07-09
17:41:42.688468839 -0700
@@ -268,7 +268,7 @@ ngx_event_accept(ngx_event_t *ev)
         wev->own_lock = &c->lock;

-        if (ls->addr_ntop) {
+        if (ls->addr_ntop && socklen > sizeof(c->sockaddr->sa_family)) {
             c->addr_text.data = ngx_pnalloc(c->pool, ls->addr_text_max_len);
             if (c->addr_text.data == NULL) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: nginx-1.4.1-unix_socket_accept_over_read.patch
Type: application/octet-stream
Size: 548 bytes
Desc: not available
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20130709/61dd981a/attachment.obj>

More information about the nginx-devel mailing list