Kernel TLS

Bjørn Mork bjorn at mork.no
Sat Nov 30 05:10:50 EST 2019


"Valdis Klētnieks" <valdis.kletnieks at vt.edu> writes:

> On Sat, 30 Nov 2019 09:13:35 +0100, Bjrn Mork said:
>
>> include/linux/errno.h is kernel internal only.  The UAPI header is
>> uapi/linux/errno.h, which is an alias for uapi/asm/errno.h.  There is no
>> 524 in include/uapi/asm-generic/errno.h or
>> include/uapi/asm-generic/errno-base.h
>>
>> The codes in include/linux/errno.h should be translated for userspace.
>> This does look like a bug in the kernel tls code.
>
> Hmm... git grep ENOTSUPP has 1,516 hits.  I haven't checked if it
> gets translated in one place, or if it gets done in a kazillion places.

Definitely more than one, but probably less than a kazillion.

I believe the userspace wrappers usually translates errors from the
lower levels to something conforming to the documented userspace API.

My version of setsockopt(2) says

RETURN VALUE
       On success, zero is returned for the standard options.   On
       error, -1 is returned, and errno is set appropriately.

       Netfilter allows the programmer to define custom socket op‐
       tions with associated handlers; for such options,  the  re‐
       turn value on success is the value returned by the handler.

ERRORS
       EBADF     The  argument sockfd is not a valid file descrip‐
                 tor.

       EFAULT    The address pointed to by  optval  is  not  in  a
                 valid  part  of  the  process address space.  For
                 getsockopt(), this error may also be returned  if
                 optlen  is not in a valid part of the process ad‐
                 dress space.

       EINVAL    optlen invalid in setsockopt().   In  some  cases
                 this error can also occur for an invalid value in
                 optval (e.g., for  the  IP_ADD_MEMBERSHIP  option
                 described in ip(7)).

       ENOPROTOOPT
                 The option is unknown at the level indicated.

       ENOTSOCK  The  file  descriptor  sockfd does not refer to a
                 socket.


If you look at e.g. udp_lib_setsockopt() you'll see that it conforms
strictly to this.  I don't know why do_tcp_setsockopt() doesn't.



Bjørn



More information about the Kernelnewbies mailing list