mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sean Anderson <sean.anderson@seco.com>
To: Aleksandr Mishin <amishin@t-argos.ru>,
	Igal Liberman <igal.liberman@freescale.com>
Cc: Madalin Bucur <madalin.bucur@nxp.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	lvc-project@linuxtesting.org
Subject: Re: [PATCH v2] fsl/fman: Validate cell-index value obtained from Device Tree
Date: Tue, 2 Jul 2024 10:50:43 -0400	[thread overview]
Message-ID: <e0b8c69a-3cc0-4034-b3f7-d8bdcc480c4d@seco.com> (raw)
In-Reply-To: <20240702140124.19096-1-amishin@t-argos.ru>

On 7/2/24 10:01, Aleksandr Mishin wrote:
> [You don't often get email from amishin@t-argos.ru. Learn why this is important at https://cas5-0-urlprotect.trendmicro.com:443/wis/clicktime/v1/query?url=https%3a%2f%2faka.ms%2fLearnAboutSenderIdentification&umid=ca782a5b-a3fd-4738-b50c-ffbd8e52e50f&auth=d807158c60b7d2502abde8a2fc01f40662980862-ac0deac714bbe85d389fd2711a17d0113034b3ca ]
>
> Cell-index value is obtained from Device Tree and then used to calculate
> the index for accessing arrays port_mfl[], mac_mfl[] and intr_mng[].
> In case of broken DT due to any error cell-index can contain any value
> and it is possible to go beyond the array boundaries which can lead
> at least to memory corruption.
> Validate cell-index value obtained from Device Tree.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Fixes: 414fd46e7762 ("fsl/fman: Add FMan support")
> Signed-off-by: Aleksandr Mishin <amishin@t-argos.ru>
> ---
> v1->v2: Move check to mac.c to avoid allmodconfig build errors and reference leaks
>
>  drivers/net/ethernet/freescale/fman/fman.c | 1 -
>  drivers/net/ethernet/freescale/fman/fman.h | 3 +++
>  drivers/net/ethernet/freescale/fman/mac.c  | 4 ++++
>  3 files changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/freescale/fman/fman.c b/drivers/net/ethernet/freescale/fman/fman.c
> index d96028f01770..fb416d60dcd7 100644
> --- a/drivers/net/ethernet/freescale/fman/fman.c
> +++ b/drivers/net/ethernet/freescale/fman/fman.c
> @@ -24,7 +24,6 @@
>
>  /* General defines */
>  #define FMAN_LIODN_TBL                 64      /* size of LIODN table */
> -#define MAX_NUM_OF_MACS                        10
>  #define FM_NUM_OF_FMAN_CTRL_EVENT_REGS 4
>  #define BASE_RX_PORTID                 0x08
>  #define BASE_TX_PORTID                 0x28
> diff --git a/drivers/net/ethernet/freescale/fman/fman.h b/drivers/net/ethernet/freescale/fman/fman.h
> index 2ea575a46675..74eb62eba0d7 100644
> --- a/drivers/net/ethernet/freescale/fman/fman.h
> +++ b/drivers/net/ethernet/freescale/fman/fman.h
> @@ -74,6 +74,9 @@
>  #define BM_MAX_NUM_OF_POOLS            64 /* Buffers pools */
>  #define FMAN_PORT_MAX_EXT_POOLS_NUM    8  /* External BM pools per Rx port */
>
> +/* General defines */
> +#define MAX_NUM_OF_MACS                        10
> +
>  struct fman; /* FMan data */
>
>  /* Enum for defining port types */
> diff --git a/drivers/net/ethernet/freescale/fman/mac.c b/drivers/net/ethernet/freescale/fman/mac.c
> index 9767586b4eb3..ac9ad5e67b44 100644
> --- a/drivers/net/ethernet/freescale/fman/mac.c
> +++ b/drivers/net/ethernet/freescale/fman/mac.c
> @@ -247,6 +247,10 @@ static int mac_probe(struct platform_device *_of_dev)
>                 dev_err(dev, "failed to read cell-index for %pOF\n", mac_node);
>                 return -EINVAL;
>         }
> +       if (val >= MAX_NUM_OF_MACS) {
> +               dev_err(dev, "cell-index value is too big for %pOF\n", mac_node);
> +               return -EINVAL;
> +       }
>         priv->cell_index = (u8)val;
>
>         /* Get the MAC address */
> --
> 2.30.2
>

Reviewed-by: Sean Anderson <sean.anderson@seco.com>

[StudioX, SECO SpA]<https://www.seco.com/applications/studiox>

      reply	other threads:[~2024-07-02 14:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-02  9:50 [PATCH] " Aleksandr Mishin
2024-07-02 13:36 ` Simon Horman
2024-07-02 17:44   ` Jakub Kicinski
2024-07-02 14:01 ` [PATCH v2] " Aleksandr Mishin
2024-07-02 14:50   ` Sean Anderson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e0b8c69a-3cc0-4034-b3f7-d8bdcc480c4d@seco.com \
    --to=sean.anderson@seco.com \
    --cc=amishin@t-argos.ru \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=igal.liberman@freescale.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lvc-project@linuxtesting.org \
    --cc=madalin.bucur@nxp.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®