netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH AUTOSEL 5.4 01/10] devlink: remove reload failed checks in params get/set callbacks
@ 2023-09-08 18:20 Sasha Levin
  2023-09-08 18:20 ` [PATCH AUTOSEL 5.4 07/10] alx: fix OOB-read compiler warning Sasha Levin
  2023-09-08 21:11 ` [PATCH AUTOSEL 5.4 01/10] devlink: remove reload failed checks in params get/set callbacks Jacob Keller
  0 siblings, 2 replies; 3+ messages in thread
From: Sasha Levin @ 2023-09-08 18:20 UTC (permalink / raw)
  To: linux-kernel, stable
  Cc: Jiri Pirko, Ido Schimmel, Jakub Kicinski, David S . Miller,
	Sasha Levin, edumazet, pabeni, jiri, jacob.e.keller,
	michal.wilczynski, shayd, netdev

From: Jiri Pirko <jiri@nvidia.com>

[ Upstream commit 633d76ad01ad0321a1ace3e5cc4fed06753d7ac4 ]

The checks in question were introduced by:
commit 6b4db2e528f6 ("devlink: Fix use-after-free after a failed reload").
That fixed an issue of reload with mlxsw driver.

Back then, that was a valid fix, because there was a limitation
in place that prevented drivers from registering/unregistering params
when devlink instance was registered.

It was possible to do the fix differently by changing drivers to
register/unregister params in appropriate places making sure the ops
operate only on memory which is allocated and initialized. But that,
as a dependency, would require to remove the limitation mentioned above.

Eventually, this limitation was lifted by:
commit 1d18bb1a4ddd ("devlink: allow registering parameters after the instance")

Also, the alternative fix (which also fixed another issue) was done by:
commit 74cbc3c03c82 ("mlxsw: spectrum_acl_tcam: Move devlink param to TCAM code").

Therefore, the checks are no longer relevant. Each driver should make
sure to have the params registered only when the memory the ops
are working with is allocated and initialized.

So remove the checks.

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Reviewed-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 net/core/devlink.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/core/devlink.c b/net/core/devlink.c
index b4dabe5d89f72..5bd6330ab4275 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -2953,7 +2953,7 @@ static int devlink_param_get(struct devlink *devlink,
 			     const struct devlink_param *param,
 			     struct devlink_param_gset_ctx *ctx)
 {
-	if (!param->get || devlink->reload_failed)
+	if (!param->get)
 		return -EOPNOTSUPP;
 	return param->get(devlink, param->id, ctx);
 }
@@ -2962,7 +2962,7 @@ static int devlink_param_set(struct devlink *devlink,
 			     const struct devlink_param *param,
 			     struct devlink_param_gset_ctx *ctx)
 {
-	if (!param->set || devlink->reload_failed)
+	if (!param->set)
 		return -EOPNOTSUPP;
 	return param->set(devlink, param->id, ctx);
 }
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH AUTOSEL 5.4 07/10] alx: fix OOB-read compiler warning
  2023-09-08 18:20 [PATCH AUTOSEL 5.4 01/10] devlink: remove reload failed checks in params get/set callbacks Sasha Levin
@ 2023-09-08 18:20 ` Sasha Levin
  2023-09-08 21:11 ` [PATCH AUTOSEL 5.4 01/10] devlink: remove reload failed checks in params get/set callbacks Jacob Keller
  1 sibling, 0 replies; 3+ messages in thread
From: Sasha Levin @ 2023-09-08 18:20 UTC (permalink / raw)
  To: linux-kernel, stable
  Cc: GONG, Ruiqi, GONG, Simon Horman, Paolo Abeni, Sasha Levin,
	chris.snook, davem, edumazet, kuba, netdev

From: "GONG, Ruiqi" <gongruiqi1@huawei.com>

[ Upstream commit 3a198c95c95da10ad844cbeade2fe40bdf14c411 ]

The following message shows up when compiling with W=1:

In function ‘fortify_memcpy_chk’,
    inlined from ‘alx_get_ethtool_stats’ at drivers/net/ethernet/atheros/alx/ethtool.c:297:2:
./include/linux/fortify-string.h:592:4: error: call to ‘__read_overflow2_field’
declared with attribute warning: detected read beyond size of field (2nd parameter);
maybe use struct_group()? [-Werror=attribute-warning]
  592 |    __read_overflow2_field(q_size_field, size);
      |    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In order to get alx stats altogether, alx_get_ethtool_stats() reads
beyond hw->stats.rx_ok. Fix this warning by directly copying hw->stats,
and refactor the unnecessarily complicated BUILD_BUG_ON btw.

Signed-off-by: GONG, Ruiqi <gongruiqi1@huawei.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://lore.kernel.org/r/20230821013218.1614265-1-gongruiqi@huaweicloud.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/net/ethernet/atheros/alx/ethtool.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/atheros/alx/ethtool.c b/drivers/net/ethernet/atheros/alx/ethtool.c
index 2f4eabf652e80..51e5aa2c74b34 100644
--- a/drivers/net/ethernet/atheros/alx/ethtool.c
+++ b/drivers/net/ethernet/atheros/alx/ethtool.c
@@ -281,9 +281,8 @@ static void alx_get_ethtool_stats(struct net_device *netdev,
 	spin_lock(&alx->stats_lock);
 
 	alx_update_hw_stats(hw);
-	BUILD_BUG_ON(sizeof(hw->stats) - offsetof(struct alx_hw_stats, rx_ok) <
-		     ALX_NUM_STATS * sizeof(u64));
-	memcpy(data, &hw->stats.rx_ok, ALX_NUM_STATS * sizeof(u64));
+	BUILD_BUG_ON(sizeof(hw->stats) != ALX_NUM_STATS * sizeof(u64));
+	memcpy(data, &hw->stats, sizeof(hw->stats));
 
 	spin_unlock(&alx->stats_lock);
 }
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH AUTOSEL 5.4 01/10] devlink: remove reload failed checks in params get/set callbacks
  2023-09-08 18:20 [PATCH AUTOSEL 5.4 01/10] devlink: remove reload failed checks in params get/set callbacks Sasha Levin
  2023-09-08 18:20 ` [PATCH AUTOSEL 5.4 07/10] alx: fix OOB-read compiler warning Sasha Levin
@ 2023-09-08 21:11 ` Jacob Keller
  1 sibling, 0 replies; 3+ messages in thread
From: Jacob Keller @ 2023-09-08 21:11 UTC (permalink / raw)
  To: Sasha Levin, linux-kernel, stable
  Cc: Jiri Pirko, Ido Schimmel, Jakub Kicinski, David S . Miller,
	edumazet, pabeni, jiri, michal.wilczynski, shayd, netdev



On 9/8/2023 11:20 AM, Sasha Levin wrote:
> From: Jiri Pirko <jiri@nvidia.com>
> 
> [ Upstream commit 633d76ad01ad0321a1ace3e5cc4fed06753d7ac4 ]
> 
> The checks in question were introduced by:
> commit 6b4db2e528f6 ("devlink: Fix use-after-free after a failed reload").
> That fixed an issue of reload with mlxsw driver.
> 
> Back then, that was a valid fix, because there was a limitation
> in place that prevented drivers from registering/unregistering params
> when devlink instance was registered.
> 
> It was possible to do the fix differently by changing drivers to
> register/unregister params in appropriate places making sure the ops
> operate only on memory which is allocated and initialized. But that,
> as a dependency, would require to remove the limitation mentioned above.
> 
> Eventually, this limitation was lifted by:
> commit 1d18bb1a4ddd ("devlink: allow registering parameters after the instance")
> 
> Also, the alternative fix (which also fixed another issue) was done by:
> commit 74cbc3c03c82 ("mlxsw: spectrum_acl_tcam: Move devlink param to TCAM code").
> 
> Therefore, the checks are no longer relevant. Each driver should make
> sure to have the params registered only when the memory the ops
> are working with is allocated and initialized.
> 
> So remove the checks.
> 


Hmmmm. Based on the description above this feels a bit odd to backport.
Are we sure that its safe to remove this limitation on older kernels?

Both mentioned commits are in v6.3 so they're not in any of the stable
trees by default.

Indeed grep over stable/linux-5.4.y shows nothing for either commit.

Thus, I am not convinced this is safe to backport. I didn't double check
every single stable branch but given that the mentioned dependencies are
in 6.3 and don't appear to have been fixes, it seems problematic for all
including 5.4, 5.10, 5.15, and 6.1. No driver in those trees is going to
be registering parameters early so I don't see the benefit of the patch.

Thus, it is my view this shouldn't be backported, at least not without
porting the relevant dependencies as well.

Thanks,
Jake

> Signed-off-by: Jiri Pirko <jiri@nvidia.com>
> Reviewed-by: Ido Schimmel <idosch@nvidia.com>
> Reviewed-by: Jakub Kicinski <kuba@kernel.org>
> Signed-off-by: David S. Miller <davem@davemloft.net>
> Signed-off-by: Sasha Levin <sashal@kernel.org>
> ---
>  net/core/devlink.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/net/core/devlink.c b/net/core/devlink.c
> index b4dabe5d89f72..5bd6330ab4275 100644
> --- a/net/core/devlink.c
> +++ b/net/core/devlink.c
> @@ -2953,7 +2953,7 @@ static int devlink_param_get(struct devlink *devlink,
>  			     const struct devlink_param *param,
>  			     struct devlink_param_gset_ctx *ctx)
>  {
> -	if (!param->get || devlink->reload_failed)
> +	if (!param->get)
>  		return -EOPNOTSUPP;
>  	return param->get(devlink, param->id, ctx);
>  }
> @@ -2962,7 +2962,7 @@ static int devlink_param_set(struct devlink *devlink,
>  			     const struct devlink_param *param,
>  			     struct devlink_param_gset_ctx *ctx)
>  {
> -	if (!param->set || devlink->reload_failed)
> +	if (!param->set)
>  		return -EOPNOTSUPP;
>  	return param->set(devlink, param->id, ctx);
>  }

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-09-08 21:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-08 18:20 [PATCH AUTOSEL 5.4 01/10] devlink: remove reload failed checks in params get/set callbacks Sasha Levin
2023-09-08 18:20 ` [PATCH AUTOSEL 5.4 07/10] alx: fix OOB-read compiler warning Sasha Levin
2023-09-08 21:11 ` [PATCH AUTOSEL 5.4 01/10] devlink: remove reload failed checks in params get/set callbacks Jacob Keller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).