non-root: Don't dump socket option SO_MARK if 0

Restoring SO_MARK requires root or CAP_NET_ADMIN. If the value
is 0 we will avoid dumping it so that we don't need to do a
privileged call on restore.

Signed-off-by: Younes Manton <ymanton@ca.ibm.com>
This commit is contained in:
Younes Manton 2022-11-21 11:14:20 -08:00 committed by Andrei Vagin
parent 2180e03b90
commit 5a19c34322

View file

@ -647,8 +647,13 @@ int dump_socket_opts(int sk, SkOptsEntry *soe)
ret |= dump_opt(sk, SOL_SOCKET, SO_PRIORITY, &soe->so_priority);
soe->has_so_rcvlowat = true;
ret |= dump_opt(sk, SOL_SOCKET, SO_RCVLOWAT, &soe->so_rcvlowat);
soe->has_so_mark = true;
/*
* Restoring SO_MARK requires root or CAP_NET_ADMIN. Avoid saving it
* in unprivileged mode if still has its default value.
*/
ret |= dump_opt(sk, SOL_SOCKET, SO_MARK, &soe->so_mark);
if (soe->so_mark != 0)
soe->has_so_mark = true;
ret |= dump_opt(sk, SOL_SOCKET, SO_SNDTIMEO, &tv);
soe->so_snd_tmo_sec = tv.tv_sec;