* [PATCH mellanox-tree] net/mlx5: prevent an integer underflow in mlx5_perout_configure()
@ 2021-02-19 9:57 Dan Carpenter
2021-02-21 6:11 ` Leon Romanovsky
2021-03-01 10:12 ` Eran Ben Elisha
0 siblings, 2 replies; 4+ messages in thread
From: Dan Carpenter @ 2021-02-19 9:57 UTC (permalink / raw)
To: Saeed Mahameed, Aya Levin
Cc: Leon Romanovsky, Eran Ben Elisha, Moshe Shemesh, Ariel Levkovich,
Pavel Machek (CIP),
netdev, linux-rdma, kernel-janitors
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.
Fixes: 432119de33d9 ("net/mlx5: Add cyc2time HW translation mode support")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
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(-)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c b/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
index b0e129d0f6d8..286824ca62b5 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
@@ -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) :
--
2.30.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH mellanox-tree] net/mlx5: prevent an integer underflow in mlx5_perout_configure()
2021-02-19 9:57 [PATCH mellanox-tree] net/mlx5: prevent an integer underflow in mlx5_perout_configure() Dan Carpenter
@ 2021-02-21 6:11 ` Leon Romanovsky
2021-03-01 10:12 ` Eran Ben Elisha
1 sibling, 0 replies; 4+ messages in thread
From: Leon Romanovsky @ 2021-02-21 6:11 UTC (permalink / raw)
To: Dan Carpenter
Cc: Saeed Mahameed, Aya Levin, Eran Ben Elisha, Moshe Shemesh,
Ariel Levkovich, Pavel Machek (CIP),
netdev, linux-rdma, kernel-janitors
On Fri, Feb 19, 2021 at 12:57:52PM +0300, Dan Carpenter wrote:
> 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.
>
> Fixes: 432119de33d9 ("net/mlx5: Add cyc2time HW translation mode support")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> 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,
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH mellanox-tree] net/mlx5: prevent an integer underflow in mlx5_perout_configure()
2021-02-19 9:57 [PATCH mellanox-tree] net/mlx5: prevent an integer underflow in mlx5_perout_configure() Dan Carpenter
2021-02-21 6:11 ` Leon Romanovsky
@ 2021-03-01 10:12 ` Eran Ben Elisha
2021-03-01 10:36 ` Dan Carpenter
1 sibling, 1 reply; 4+ messages in thread
From: Eran Ben Elisha @ 2021-03-01 10:12 UTC (permalink / raw)
To: Dan Carpenter, Saeed Mahameed, Aya Levin
Cc: Leon Romanovsky, Eran Ben Elisha, Moshe Shemesh, Ariel Levkovich,
Pavel Machek (CIP),
netdev, linux-rdma, kernel-janitors
On 2/19/2021 11:57 AM, Dan Carpenter wrote:
> 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.
>
> Fixes: 432119de33d9 ("net/mlx5: Add cyc2time HW translation mode support")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> 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(-)
>
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c b/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
> index b0e129d0f6d8..286824ca62b5 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
> @@ -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.
> + if (rt_mode && (sec < 0 || sec > U32_MAX))
> return -EINVAL;
>
> time_stamp = rt_mode ? perout_conf_real_time(sec, nsec) :
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH mellanox-tree] net/mlx5: prevent an integer underflow in mlx5_perout_configure()
2021-03-01 10:12 ` Eran Ben Elisha
@ 2021-03-01 10:36 ` Dan Carpenter
0 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2021-03-01 10:36 UTC (permalink / raw)
To: Eran Ben Elisha
Cc: Saeed Mahameed, Aya Levin, Leon Romanovsky, Eran Ben Elisha,
Moshe Shemesh, Ariel Levkovich, Pavel Machek (CIP),
netdev, linux-rdma, kernel-janitors
On Mon, Mar 01, 2021 at 12:12:34PM +0200, Eran Ben Elisha wrote:
>
>
> On 2/19/2021 11:57 AM, Dan Carpenter wrote:
> > 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.
> >
> > Fixes: 432119de33d9 ("net/mlx5: Add cyc2time HW translation mode support")
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > ---
> > 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(-)
> >
> > diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c b/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
> > index b0e129d0f6d8..286824ca62b5 100644
> > --- a/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
> > +++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
> > @@ -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.
>
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
> > + if (rt_mode && (sec < 0 || sec > U32_MAX))
> > return -EINVAL;
> > time_stamp = rt_mode ? perout_conf_real_time(sec, nsec) :
> >
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-03-01 10:39 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-19 9:57 [PATCH mellanox-tree] net/mlx5: prevent an integer underflow in mlx5_perout_configure() Dan Carpenter
2021-02-21 6:11 ` Leon Romanovsky
2021-03-01 10:12 ` Eran Ben Elisha
2021-03-01 10:36 ` Dan Carpenter
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.