[erlang-questions] unix domain sockets with abstract namespace: can't use all 108 bytes

Richard A. O'Keefe ok@REDACTED
Thu Apr 27 02:46:53 CEST 2017


> On 26/04/2017, at 8:55 PM, Raimo Niskanen <raimo+erlang-questions@REDACTED> wrote:
> 
> Ok.  That is not as loose as I thought.
> 
> I can not find (in Posix) any clue to which address_len you shall use with
> a sockaddr_un structure.  Is it the size of the whole structure, or is it
> the size of the structure ending with the terminating 0 in the path?

The bind() description says that
"address_len Specifies the length of the sockaddr structure
 pointed to by the address argument."
It does not say the *size* of the structure but the *length* of the structure.
Unfortunately, I can find no definition of "length of a structure".  Sigh.

> There is an example:
>    http://pubs.opengroup.org/onlinepubs/9699919799/ ->
>       bind - bind a name to a socket
> that uses the size of the structure, ignoring the path length in .sun_path.
> That would speak for that the Linux use is creative but not violating Posix
> since the path is 0 terminated and the address size is large enough.

The Linux extension puts a NUL byte at the front of the path, thus
unambiguously providing the path "".  Bytes after that are not part
of the required path name.  It is *deeply* regrettable that the Linux
extenders did not do the clean thing and add a new address family.

I feel that I have to say this: if you look at the TOP500 list, 498 out
of the top 500 supercomputers in the world run "Linux".  (The other 2
run "Unix".)  While I enjoy exegesis of POSIX, at some point reality
must be acknowledged...

Solaris documentation is clear that you should use
bind(s, (struct sockaddr *) &addr,
		strlen(addr.sun_path) + sizeof (addr.sun_family))

Poking around in the OpenSolaris kernel source code, the function
copyin_name() suggests to me that any value between that and the
full size of the structure should work.

> So it seems it is not a violation of Posix to use a su->sun_path that starts
> with a 0 combined with an address_len of sizeof(*su).

It may not be, but the path is still "" and thus a run-time error.

Turning errors into extensions is common enough, so this leaves the situation
where we found it, really.  POSIX systems *shouldn't* do this, but Linux *does*.
> 
>>> Therefore the Linux way to use the address type contradicts the BSD:s and I
>>> guess Solaris.
>> 
>> And POSIX.  And HP-UX and AIX, as far as I can tell, and to the degree that
>> anyone cares.
> 
> I am sorry, since I am not a native english speaker; what does "and to the
> degree that anyone cares" mean in this context?

What I meant in that paragraph was "I have checked the AIX and HP-UX manuals
and they certainly do not mention the Linux extension and can be read as
consistent with POSIX and the BSDs, so Erlang code using this Linux feature
would not port to AIX or HP-UX, but does that have any practical significance?
Does anyone *care* about Erlang on AIX or HP-UX?"




More information about the erlang-questions mailing list