From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, kuba@kernel.org, edumazet@google.com,
pabeni@redhat.com, horms@kernel.org,
Willem de Bruijn <willemb@google.com>
Subject: [PATCH net-next 1/3] net: ensure SCM_TXTIME delivery time is no older than system boot
Date: Wed, 3 Jun 2026 15:01:28 -0400 [thread overview]
Message-ID: <20260603190243.2789335-2-willemdebruijn.kernel@gmail.com> (raw)
In-Reply-To: <20260603190243.2789335-1-willemdebruijn.kernel@gmail.com>
From: Willem de Bruijn <willemb@google.com>
Limit input to sane values to avoid having to add tests later in the
kernel hot path, e.g., in FQ.
SCM_TXTIME timestamps are converted to signed ktime_t when assigned to
skb->tstamp. Avoid having negative values overflow into large positive
ones when again used as u64, e.g., in FQ time_to_send.
For CLOCK_MONOTONIC, only allow positive values.
For CLOCK_REALTIME and CLOCK_TAI, allow equivalent values, i.e., no
older than the boot of the machine.
skb->tstamp zero is a special case signaling feature off. This is not
converted between clockids.
Handle the special case where the realtime clock is set so small that
real - mono is negative, however unlikely in practice.
Ideally we would also set a sane upper bound, but that would require
reading the clock, which is an expensive operation. Continue to defer
that validation to users of the data. FQ already does this.
Bound rather than return error on older timestamps. This is the
existing policy e.g., in FQ.
Fixes: 80b14dee2bea ("net: Add a new socket option for a future transmit time.")
Signed-off-by: Willem de Bruijn <willemb@google.com>
---
net/core/sock.c | 32 +++++++++++++++++++++++++++++++-
1 file changed, 31 insertions(+), 1 deletion(-)
diff --git a/net/core/sock.c b/net/core/sock.c
index f362e3ce1efb..dff48ef49a8c 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -3041,12 +3041,42 @@ int __sock_cmsg_send(struct sock *sk, struct cmsghdr *cmsg,
sockc->tsflags |= tsflags;
break;
case SCM_TXTIME:
+ {
+ ktime_t tmin;
+ u64 txtime;
+
if (!sock_flag(sk, SOCK_TXTIME))
return -EINVAL;
if (cmsg->cmsg_len != CMSG_LEN(sizeof(u64)))
return -EINVAL;
- sockc->transmit_time = get_unaligned((u64 *)CMSG_DATA(cmsg));
+
+ txtime = get_unaligned((u64 *)CMSG_DATA(cmsg));
+
+ /* Allow sending without a delivery time: zero special case */
+ if (!txtime) {
+ sockc->transmit_time = 0;
+ break;
+ }
+
+ switch (sk->sk_clockid) {
+ case CLOCK_MONOTONIC:
+ tmin = 1;
+ break;
+ case CLOCK_REALTIME:
+ tmin = max(ktime_mono_to_real(0), 1);
+ break;
+ case CLOCK_TAI:
+ tmin = max(ktime_mono_to_any(0, TK_OFFS_TAI), 1);
+ break;
+ default:
+ tmin = 1;
+ WARN_ON_ONCE(1);
+ break;
+ };
+
+ sockc->transmit_time = max_t(ktime_t, txtime, tmin);
break;
+ }
case SCM_TS_OPT_ID:
if (sk_is_tcp(sk))
return -EINVAL;
--
2.54.0.1032.g2f8565e1d1-goog
next prev parent reply other threads:[~2026-06-03 19:02 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-03 19:01 [PATCH net-next 0/3] SO_TXTIME improvements Willem de Bruijn
2026-06-03 19:01 ` Willem de Bruijn [this message]
2026-06-03 22:11 ` [PATCH net-next 1/3] net: ensure SCM_TXTIME delivery time is no older than system boot Jakub Kicinski
2026-06-03 19:01 ` [PATCH net-next 2/3] net_sched: sch_fq: convert skb->tstamp if not monotonic Willem de Bruijn
2026-06-03 22:22 ` Jakub Kicinski
2026-06-03 22:59 ` Willem de Bruijn
2026-06-03 23:27 ` Jakub Kicinski
2026-06-03 19:01 ` [PATCH net-next 3/3] selftests: drv-net: extend so_txtime with FQ with other clocks Willem de Bruijn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260603190243.2789335-2-willemdebruijn.kernel@gmail.com \
--to=willemdebruijn.kernel@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=willemb@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox