RE: netlink getsockopt() sets only one byte?

From: David Laight
Date: Wed Apr 19 2023 - 11:44:28 EST


From: Brad Spencer <bspencer@xxxxxxxxxxxxxx>
> Sent: 18 April 2023 18:38
>
> Calling getsockopt() on a netlink socket with SOL_NETLINK options that
> use type int only sets the first byte of the int value but returns an
> optlen equal to sizeof(int), at least on x86_64.
>
>
> The detailed description:
>
> It looks like netlink_getsockopt() calls put_user() with a char*
> pointer, and I think that causes it to copy only one byte from the val
> result, despite len being sizeof(int).
>
> Is this the expected behaviour? The returned size is 4, after all,
> and other int-sized socket options (outside of netlink) like
> SO_REUSEADDR set all bytes of the int.

It will be horribly broken on anything big-endian.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)