]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
net: Implement missing getsockopt(SO_TIMESTAMPING_NEW)
authorJörn-Thorben Hinz <jthinz@mailbox.tu-berlin.de>
Thu, 21 Dec 2023 23:19:01 +0000 (00:19 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 15 Jan 2024 17:51:13 +0000 (18:51 +0100)
[ Upstream commit 7f6ca95d16b96567ce4cf458a2790ff17fa620c3 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/core/sock.c

index 662cd6d54ac70e2b8ef3153d6619db1c50d607b5..ef29106af6046243e6165e9b9170b7abcb3fc9e2 100644 (file)
@@ -1534,9 +1534,16 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
                break;
 
        case SO_TIMESTAMPING_OLD:
+       case SO_TIMESTAMPING_NEW:
                lv = sizeof(v.timestamping);
-               v.timestamping.flags = sk->sk_tsflags;
-               v.timestamping.bind_phc = sk->sk_bind_phc;
+               /* For the later-added case SO_TIMESTAMPING_NEW: Be strict about only
+                * returning the flags when they were set through the same option.
+                * Don't change the beviour for the old case SO_TIMESTAMPING_OLD.
+                */
+               if (optname == SO_TIMESTAMPING_OLD || sock_flag(sk, SOCK_TSTAMP_NEW)) {
+                       v.timestamping.flags = sk->sk_tsflags;
+                       v.timestamping.bind_phc = sk->sk_bind_phc;
+               }
                break;
 
        case SO_RCVTIMEO_OLD: