net/mlx5: prevent an integer underflow in mlx5_perout_configure()
Subsystems (5)
PATCH 1/1 net/mlx5: prevent an integer underflow in mlx5_perout_configure()
The value of "sec" comes from the user. Negative values will lead to shift wrapping inside the perout_conf_real_time() function and triggger a UBSan warning.
Add a check and return -EINVAL to prevent that from happening.
---
Saeed, I think this goes through your git tree and you will send a pull request to the networking?
From static analysis. Not tested.
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +1 -1
@@ -516,7 +516,7 @@ static int mlx5_perout_configure(struct ptp_clock_info *ptp, nsec = rq->perout.start.nsec; sec = rq->perout.start.sec; -if (rt_mode && sec >U32_MAX ) +if (rt_mode && (sec <0 || sec >U32_MAX ))return -EINVAL ; time_stamp = rt_mode ? perout_conf_real_time(sec, nsec) :
Signature · 1 line
2.30.0
Quoted 8 lines · Dan Carpenter
The value of "sec" comes from the user. Negative values will lead to shift wrapping inside the
perout_conf_real_time()function and triggger a UBSan warning.Add a check and return
-EINVALto prevent that from happening.Fixes 432119de33d9 ("net/mlx5: Add cyc2time HW translation mode support")Signed-off-by Dan Carpenter <[email protected]>
Quoted 9 lines
---
Saeed, I think this goes through your git tree and you will send a pull request to the networking?From static analysis. Not tested.
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Thanks,
Quoted 22 lines · Dan Carpenter
The value of "sec" comes from the user. Negative values will lead to shift wrapping inside the
perout_conf_real_time()function and triggger a UBSan warning.Add a check and return
-EINVALto prevent that from happening.Fixes 432119de33d9 ("net/mlx5: Add cyc2time HW translation mode support")Signed-off-by Dan Carpenter <[email protected]>---
Saeed, I think this goes through your git tree and you will send a pull request to the networking?From static analysis. Not tested.
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +0
-0
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c static int mlx5_perout_configure(struct ptp_clock_info *ptp, · line 519
Quoted 4 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +0
-1@@ -516,7 +516,7 @@ static int mlx5_perout_configure(struct ptp_clock_info *ptp, nsec = rq->perout.start.nsec; sec = rq->perout.start.sec; -if (rt_mode && sec >U32_MAX )
This if clause was set to reject perout time start sec bigger than U32_MAX, as rt mode specifically doesn't support it.
A user negative values protection should be generic for all netdev drivers, inside the caller ioctl func, and not part of any driver code.
Quoted 5 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +1
-0+if (rt_mode && (sec <0 || sec >U32_MAX ))return -EINVAL ; time_stamp = rt_mode ? perout_conf_real_time(sec, nsec) :
Quoted 32 lines · Eran Ben Elisha
Quoted 22 lines · Dan Carpenter
The value of "sec" comes from the user. Negative values will lead to shift wrapping inside the
perout_conf_real_time()function and triggger a UBSan warning.Add a check and return
-EINVALto prevent that from happening.Fixes 432119de33d9 ("net/mlx5: Add cyc2time HW translation mode support")Signed-off-by Dan Carpenter <[email protected]>---
Saeed, I think this goes through your git tree and you will send a pull request to the networking?From static analysis. Not tested.
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +0
-0drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c static int mlx5_perout_configure(struct ptp_clock_info *ptp, · line 518
Quoted 3 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +0
-1@@ -516,7 +516,7 @@ static int mlx5_perout_configure(struct ptp_clock_info *ptp, nsec = rq->perout.start.nsec; sec = rq->perout.start.sec; -if (rt_mode && sec >U32_MAX )This if clause was set to reject perout time start sec bigger than
U32_MAX, as rt mode specifically doesn't support it.
Quoted 3 lines
A user negative values protection should be generic for all netdev drivers, inside the caller ioctl func, and not part of any driver code.
I'm not a networking expert... :/ It's easier for me to see that this code will trigger a syzbot splat vs saying that there is no valid use case for negative seconds any driver.
What you're saying sounds reasonable enough to me, but I don't know enough about networking to comment one way or the other. Maybe the other drivers have a use for negative seconds?
regards,
dan carpenter
Quoted 4 lines
Quoted 4 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +1
-0+if (rt_mode && (sec <0 || sec >U32_MAX ))return -EINVAL ; time_stamp = rt_mode ? perout_conf_real_time(sec, nsec) :