* [PATCH v1 net] net/sched: taprio: enforce minimum value for picos_per_byte
@ 2025-07-24 18:13 Takamitsu Iwai
2025-07-24 18:58 ` Vinicius Costa Gomes
0 siblings, 1 reply; 3+ messages in thread
From: Takamitsu Iwai @ 2025-07-24 18:13 UTC (permalink / raw)
To: Vinicius Costa Gomes, Jamal Hadi Salim, Cong Wang, Jiri Pirko
Cc: netdev, Kuniyuki Iwashima, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, Vladimir Oltean,
takamitz, Takamitsu Iwai, syzbot+398e1ee4ca2cac05fddb
Syzbot reported a WARNING in taprio_get_start_time().
When link speed is 470589 or greater, q->picos_per_byte becomes too
small, causing length_to_duration(q, ETH_ZLEN) to return zero.
This zero value leads to validation failures in fill_sched_entry() and
parse_taprio_schedule(), allowing arbitrary values to be assigned to
entry->interval and cycle_time. As a result, sched->cycle can become zero.
Since SPEED_800000 is the largest defined speed in
include/uapi/linux/ethtool.h, this issue can occur in realistic scenarios.
To ensure length_to_duration() returns a non-zero value for minimum-sized
Ethernet frames (ETH_ZLEN = 60), picos_per_byte must be at least 17
(60 * 17 > PSEC_PER_NSEC which is 1000).
This patch enforces a minimum value of 17 for picos_per_byte when the
calculated value would be lower.
Fixes: 68ce6688a5ba ("net: sched: taprio: Fix potential integer overflow in taprio_set_picos_per_byte")
Reported-by: syzbot+398e1ee4ca2cac05fddb@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=398e1ee4ca2cac05fddb
Signed-off-by: Takamitsu Iwai <takamitz@amazon.co.jp>
---
net/sched/sch_taprio.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/net/sched/sch_taprio.c b/net/sched/sch_taprio.c
index 2b14c81a87e5..bcfdb9446657 100644
--- a/net/sched/sch_taprio.c
+++ b/net/sched/sch_taprio.c
@@ -43,6 +43,12 @@ static struct static_key_false taprio_have_working_mqprio;
#define TAPRIO_SUPPORTED_FLAGS \
(TCA_TAPRIO_ATTR_FLAG_TXTIME_ASSIST | TCA_TAPRIO_ATTR_FLAG_FULL_OFFLOAD)
#define TAPRIO_FLAGS_INVALID U32_MAX
+/* Minimum value for picos_per_byte to ensure non-zero duration
+ * for minimum-sized Ethernet frames (ETH_ZLEN = 60).
+ * 60 * 17 > PSEC_PER_NSEC (1000)
+ */
+#define TAPRIO_PICOS_PER_BYTE_MIN 17
+
struct sched_entry {
/* Durations between this GCL entry and the GCL entry where the
@@ -1299,7 +1305,7 @@ static void taprio_set_picos_per_byte(struct net_device *dev,
speed = ecmd.base.speed;
skip:
- picos_per_byte = (USEC_PER_SEC * 8) / speed;
+ picos_per_byte = max((USEC_PER_SEC * 8) / speed, TAPRIO_PICOS_PER_BYTE_MIN);
atomic64_set(&q->picos_per_byte, picos_per_byte);
netdev_dbg(dev, "taprio: set %s's picos_per_byte to: %lld, linkspeed: %d\n",
--
2.39.5 (Apple Git-154)
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH v1 net] net/sched: taprio: enforce minimum value for picos_per_byte
2025-07-24 18:13 [PATCH v1 net] net/sched: taprio: enforce minimum value for picos_per_byte Takamitsu Iwai
@ 2025-07-24 18:58 ` Vinicius Costa Gomes
2025-07-25 5:21 ` Takamitsu Iwai
0 siblings, 1 reply; 3+ messages in thread
From: Vinicius Costa Gomes @ 2025-07-24 18:58 UTC (permalink / raw)
To: Takamitsu Iwai, Jamal Hadi Salim, Cong Wang, Jiri Pirko
Cc: netdev, Kuniyuki Iwashima, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, Vladimir Oltean,
takamitz, Takamitsu Iwai, syzbot+398e1ee4ca2cac05fddb
Takamitsu Iwai <takamitz@amazon.co.jp> writes:
> Syzbot reported a WARNING in taprio_get_start_time().
>
> When link speed is 470589 or greater, q->picos_per_byte becomes too
> small, causing length_to_duration(q, ETH_ZLEN) to return zero.
>
When I chose the unit picoseconds, I remember thinking "nobody would
consider using taprio with over 400Gbs" :-)
> This zero value leads to validation failures in fill_sched_entry() and
> parse_taprio_schedule(), allowing arbitrary values to be assigned to
> entry->interval and cycle_time. As a result, sched->cycle can become zero.
>
> Since SPEED_800000 is the largest defined speed in
> include/uapi/linux/ethtool.h, this issue can occur in realistic scenarios.
>
> To ensure length_to_duration() returns a non-zero value for minimum-sized
> Ethernet frames (ETH_ZLEN = 60), picos_per_byte must be at least 17
> (60 * 17 > PSEC_PER_NSEC which is 1000).
>
> This patch enforces a minimum value of 17 for picos_per_byte when the
> calculated value would be lower.
>
> Fixes: 68ce6688a5ba ("net: sched: taprio: Fix potential integer overflow in taprio_set_picos_per_byte")
> Reported-by: syzbot+398e1ee4ca2cac05fddb@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=398e1ee4ca2cac05fddb
> Signed-off-by: Takamitsu Iwai <takamitz@amazon.co.jp>
> ---
> net/sched/sch_taprio.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/net/sched/sch_taprio.c b/net/sched/sch_taprio.c
> index 2b14c81a87e5..bcfdb9446657 100644
> --- a/net/sched/sch_taprio.c
> +++ b/net/sched/sch_taprio.c
> @@ -43,6 +43,12 @@ static struct static_key_false taprio_have_working_mqprio;
> #define TAPRIO_SUPPORTED_FLAGS \
> (TCA_TAPRIO_ATTR_FLAG_TXTIME_ASSIST | TCA_TAPRIO_ATTR_FLAG_FULL_OFFLOAD)
> #define TAPRIO_FLAGS_INVALID U32_MAX
> +/* Minimum value for picos_per_byte to ensure non-zero duration
> + * for minimum-sized Ethernet frames (ETH_ZLEN = 60).
> + * 60 * 17 > PSEC_PER_NSEC (1000)
> + */
> +#define TAPRIO_PICOS_PER_BYTE_MIN 17
> +
>
> struct sched_entry {
> /* Durations between this GCL entry and the GCL entry where the
> @@ -1299,7 +1305,7 @@ static void taprio_set_picos_per_byte(struct net_device *dev,
> speed = ecmd.base.speed;
>
> skip:
> - picos_per_byte = (USEC_PER_SEC * 8) / speed;
> + picos_per_byte = max((USEC_PER_SEC * 8) / speed,
> TAPRIO_PICOS_PER_BYTE_MIN);
Thinking if it's worth displaying an error to the user here? something
like "Linkspeed %d is greater than what can be tracked, schedule may be
inacurate". I am worried that at this point, taprio won't be able to
obey the configured schedule and the user should know about that.
If we see people complaining about it in the real world, we can change
the units, or do something else.
>
> atomic64_set(&q->picos_per_byte, picos_per_byte);
> netdev_dbg(dev, "taprio: set %s's picos_per_byte to: %lld, linkspeed: %d\n",
> --
> 2.39.5 (Apple Git-154)
>
Cheers,
--
Vinicius
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: Re: [PATCH v1 net] net/sched: taprio: enforce minimum value for picos_per_byte
2025-07-24 18:58 ` Vinicius Costa Gomes
@ 2025-07-25 5:21 ` Takamitsu Iwai
0 siblings, 0 replies; 3+ messages in thread
From: Takamitsu Iwai @ 2025-07-25 5:21 UTC (permalink / raw)
To: vinicius.gomes
Cc: davem, edumazet, horms, jhs, jiri, kuba, kuniyu, netdev, olteanv,
pabeni, syzbot+398e1ee4ca2cac05fddb, takamitz, takamitz,
xiyou.wangcong
On 2025/07/25, 3:58, "Vinicius Costa Gomes" <vinicius.gomes@intel.com <mailto:vinicius.gomes@intel.com>> wrote:
> Takamitsu Iwai <takamitz@amazon.co.jp <mailto:takamitz@amazon.co.jp>> writes:
> > @@ -1299,7 +1305,7 @@ static void taprio_set_picos_per_byte(struct net_device *dev,
> > speed = ecmd.base.speed;
> >
> > skip:
> > - picos_per_byte = (USEC_PER_SEC * 8) / speed;
> > + picos_per_byte = max((USEC_PER_SEC * 8) / speed,
> > TAPRIO_PICOS_PER_BYTE_MIN);
>
>
> Thinking if it's worth displaying an error to the user here? something
> like "Linkspeed %d is greater than what can be tracked, schedule may be
> inacurate". I am worried that at this point, taprio won't be able to
> obey the configured schedule and the user should know about that.
>
>
> If we see people complaining about it in the real world, we can change
> the units, or do something else.
Thank you for your feedback on this patch.
I agree with adding message about this here. I'll revise the patch to add
a pr_warn() message when the calculated picos_per_byte would be below the
minimum threshold.
Thanks.
Takamitsu
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-07-25 5:22 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-24 18:13 [PATCH v1 net] net/sched: taprio: enforce minimum value for picos_per_byte Takamitsu Iwai
2025-07-24 18:58 ` Vinicius Costa Gomes
2025-07-25 5:21 ` Takamitsu Iwai
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.