diff mbox series

[net-next] net: bcmasp: Prevent array undereflow in bcmasp_netfilt_get_init()

Message ID b3b47b25-01fc-4d9f-a6c3-e037ad4d71d7@moroto.mountain (mailing list archive)
State Accepted
Commit 48d17c517a7af933346bd095e8ccc52b8477b274
Delegated to: Netdev Maintainers
Headers show
Series [net-next] net: bcmasp: Prevent array undereflow in bcmasp_netfilt_get_init() | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1330 this patch: 1330
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang success Errors and warnings before: 1353 this patch: 1353
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 1353 this patch: 1353
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 16 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Dan Carpenter Aug. 7, 2023, 1:01 p.m. UTC
The "loc" value comes from the user and it can be negative leading to an
an array underflow when we check "priv->net_filters[loc].claimed".  Fix
this by changing the type to u32.

Fixes: c5d511c49587 ("net: bcmasp: Add support for wake on net filters")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
Recent code.  Only needed on net-next.

 drivers/net/ethernet/broadcom/asp2/bcmasp.c | 2 +-
 drivers/net/ethernet/broadcom/asp2/bcmasp.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Comments

Florian Fainelli Aug. 7, 2023, 3:15 p.m. UTC | #1
On 8/7/2023 6:01 AM, Dan Carpenter wrote:
> The "loc" value comes from the user and it can be negative leading to an
> an array underflow when we check "priv->net_filters[loc].claimed".  Fix
> this by changing the type to u32.
> 
> Fixes: c5d511c49587 ("net: bcmasp: Add support for wake on net filters")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>

Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
Justin Chen Aug. 7, 2023, 8:54 p.m. UTC | #2
On 8/7/23 6:01 AM, Dan Carpenter wrote:
> The "loc" value comes from the user and it can be negative leading to an
> an array underflow when we check "priv->net_filters[loc].claimed".  Fix
> this by changing the type to u32.
> 
> Fixes: c5d511c49587 ("net: bcmasp: Add support for wake on net filters")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>

Reviewed-by: Justin Chen <justin.chen@broadcom.com>

> ---
> Recent code.  Only needed on net-next.
> 
>   drivers/net/ethernet/broadcom/asp2/bcmasp.c | 2 +-
>   drivers/net/ethernet/broadcom/asp2/bcmasp.h | 2 +-
>   2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp.c b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
> index eb35ced1c8ba..d63d321f3e7b 100644
> --- a/drivers/net/ethernet/broadcom/asp2/bcmasp.c
> +++ b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
> @@ -640,7 +640,7 @@ bool bcmasp_netfilt_check_dup(struct bcmasp_intf *intf,
>    * If no more open filters return NULL
>    */
>   struct bcmasp_net_filter *bcmasp_netfilt_get_init(struct bcmasp_intf *intf,
> -						  int loc, bool wake_filter,
> +						  u32 loc, bool wake_filter,
>   						  bool init)
>   {
>   	struct bcmasp_net_filter *nfilter = NULL;
> diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp.h b/drivers/net/ethernet/broadcom/asp2/bcmasp.h
> index 6bfcaa7f95a8..5b512f7f5e94 100644
> --- a/drivers/net/ethernet/broadcom/asp2/bcmasp.h
> +++ b/drivers/net/ethernet/broadcom/asp2/bcmasp.h
> @@ -566,7 +566,7 @@ void bcmasp_disable_all_filters(struct bcmasp_intf *intf);
>   void bcmasp_core_clock_set_intf(struct bcmasp_intf *intf, bool en);
>   
>   struct bcmasp_net_filter *bcmasp_netfilt_get_init(struct bcmasp_intf *intf,
> -						  int loc, bool wake_filter,
> +						  u32 loc, bool wake_filter,
>   						  bool init);
>   
>   bool bcmasp_netfilt_check_dup(struct bcmasp_intf *intf,
patchwork-bot+netdevbpf@kernel.org Aug. 8, 2023, 10:10 p.m. UTC | #3
Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Mon, 7 Aug 2023 16:01:53 +0300 you wrote:
> The "loc" value comes from the user and it can be negative leading to an
> an array underflow when we check "priv->net_filters[loc].claimed".  Fix
> this by changing the type to u32.
> 
> Fixes: c5d511c49587 ("net: bcmasp: Add support for wake on net filters")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> 
> [...]

Here is the summary with links:
  - [net-next] net: bcmasp: Prevent array undereflow in bcmasp_netfilt_get_init()
    https://git.kernel.org/netdev/net-next/c/48d17c517a7a

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp.c b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
index eb35ced1c8ba..d63d321f3e7b 100644
--- a/drivers/net/ethernet/broadcom/asp2/bcmasp.c
+++ b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
@@ -640,7 +640,7 @@  bool bcmasp_netfilt_check_dup(struct bcmasp_intf *intf,
  * If no more open filters return NULL
  */
 struct bcmasp_net_filter *bcmasp_netfilt_get_init(struct bcmasp_intf *intf,
-						  int loc, bool wake_filter,
+						  u32 loc, bool wake_filter,
 						  bool init)
 {
 	struct bcmasp_net_filter *nfilter = NULL;
diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp.h b/drivers/net/ethernet/broadcom/asp2/bcmasp.h
index 6bfcaa7f95a8..5b512f7f5e94 100644
--- a/drivers/net/ethernet/broadcom/asp2/bcmasp.h
+++ b/drivers/net/ethernet/broadcom/asp2/bcmasp.h
@@ -566,7 +566,7 @@  void bcmasp_disable_all_filters(struct bcmasp_intf *intf);
 void bcmasp_core_clock_set_intf(struct bcmasp_intf *intf, bool en);
 
 struct bcmasp_net_filter *bcmasp_netfilt_get_init(struct bcmasp_intf *intf,
-						  int loc, bool wake_filter,
+						  u32 loc, bool wake_filter,
 						  bool init);
 
 bool bcmasp_netfilt_check_dup(struct bcmasp_intf *intf,