Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: Implement missing getsockopt(SO_TIMESTAMPING_NEW)

Commit 9718475e6908 ("socket: Add SO_TIMESTAMPING_NEW") added the new
socket option SO_TIMESTAMPING_NEW. Setting the option is handled in
sk_setsockopt(), querying it was not handled in sk_getsockopt(), though.

Following remarks on an earlier submission of this patch, keep the old
behavior of getsockopt(SO_TIMESTAMPING_OLD) which returns the active
flags even if they actually have been set through SO_TIMESTAMPING_NEW.

The new getsockopt(SO_TIMESTAMPING_NEW) is stricter, returning flags
only if they have been set through the same option.

Fixes: 9718475e6908 ("socket: Add SO_TIMESTAMPING_NEW")
Link: https://lore.kernel.org/lkml/20230703175048.151683-1-jthinz@mailbox.tu-berlin.de/
Link: https://lore.kernel.org/netdev/0d7cddc9-03fa-43db-a579-14f3e822615b@app.fastmail.com/
Signed-off-by: Jörn-Thorben Hinz <jthinz@mailbox.tu-berlin.de>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Jörn-Thorben Hinz and committed by
David S. Miller
7f6ca95d 9bf2e916

+9 -2
+9 -2
net/core/sock.c
··· 1711 1711 break; 1712 1712 1713 1713 case SO_TIMESTAMPING_OLD: 1714 + case SO_TIMESTAMPING_NEW: 1714 1715 lv = sizeof(v.timestamping); 1715 - v.timestamping.flags = READ_ONCE(sk->sk_tsflags); 1716 - v.timestamping.bind_phc = READ_ONCE(sk->sk_bind_phc); 1716 + /* For the later-added case SO_TIMESTAMPING_NEW: Be strict about only 1717 + * returning the flags when they were set through the same option. 1718 + * Don't change the beviour for the old case SO_TIMESTAMPING_OLD. 1719 + */ 1720 + if (optname == SO_TIMESTAMPING_OLD || sock_flag(sk, SOCK_TSTAMP_NEW)) { 1721 + v.timestamping.flags = READ_ONCE(sk->sk_tsflags); 1722 + v.timestamping.bind_phc = READ_ONCE(sk->sk_bind_phc); 1723 + } 1717 1724 break; 1718 1725 1719 1726 case SO_RCVTIMEO_OLD: