[PATCH] Unix domain sockets in abstract namespace

Maxim Dounin mdounin at mdounin.ru
Wed Sep 19 13:56:09 UTC 2012


Hello!

On Wed, Sep 12, 2012 at 11:46:52AM +0200, Dirk Feytons wrote:

> Hi,
> 
> I was playing around with ngx_lua and its socket API, which is built
> on top of nginx functionality. The API supports unix domain sockets
> but not in the abstract namespace, at least not officially. When I
> tried specifying an abstract address I found it didn't work. I tracked
> it down to two calls to ngx_cpystrn() in
> core/ngx_inet.c:ngx_parse_unix_domain_url(). That function gets
> confused by the leading '\0' in an abstract namespace address.

This is because the abstract namespace is actually linux extension 
to unix domain sockets, "The abstract socket namespace is a 
nonportable Linux extension" (from [1]).

Strictly speaking, it's not something even permitted by POSIX as 
socket path ends with first null byte as per POSIX.

> Changing it to ngx_memcpy() fixes this and then everything works.
> 
> I attached a patch agains nginx 1.2.3. The fix seems trivial but this
> is my first look into the nginx internals so I don't know whether
> there are unwanted side effects from this change. Feedback welcome.

I suspect there may be some, in particular during logging of 
errors and probably while parsing untrusted urls.

[1] http://www.kernel.org/doc/man-pages/online/pages/man7/unix.7.html

Maxim Dounin



More information about the nginx-devel mailing list