All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <error27@gmail.com>
To: sujuan.chen@mediatek.com
Cc: linux-mediatek@lists.infradead.org,
	Masami Ichikawa <masami.ichikawa@miraclelinux.com>,
	cip-dev <cip-dev@lists.cip-project.org>
Subject: [bug report] net: ethernet: mtk_wed: introduce wed mcu support
Date: Wed, 1 Feb 2023 16:37:14 +0300	[thread overview]
Message-ID: <Y9prChfI3ExTpK2o@kili> (raw)

Hello Sujuan Chen,

The patch cc514101a97e: "net: ethernet: mtk_wed: introduce wed mcu
support" from Nov 5, 2022, leads to the following Smatch static
checker warning:

	drivers/net/ethernet/mediatek/mtk_wed_mcu.c:82 mtk_wed_update_rx_stats()
	warn: uncapped user loop index 'i'

drivers/net/ethernet/mediatek/mtk_wed_mcu.c
    64 static void
    65 mtk_wed_update_rx_stats(struct mtk_wed_device *wed, struct sk_buff *skb)
    66 {
    67         u32 count = get_unaligned_le32(skb->data);
    68         struct mtk_wed_wo_rx_stats *stats;
    69         int i;
    70 
    71         if (count * sizeof(*stats) > skb->len - sizeof(u32))
    72                 return;

There are two issues.

Bug 1: There is no check that skb->len >= sizeof(u32) so the
get_unaligned_le32(skb->data); can result in an out of bounds read and
the bounds check on count is not effective.

Bug 2: On a 32bit system the "count * sizeof(*stats)" multiplication can
have an integer overflow bug.  Suggestion:

	if (size_mul(count, sizeof(*stats)) > skb->len - sizeof(u32))
		return;

    73 
    74         stats = (struct mtk_wed_wo_rx_stats *)(skb->data + sizeof(u32));
    75         for (i = 0 ; i < count ; i++)
--> 76                 wed->wlan.update_wo_rx_stats(wed, &stats[i]);
    77 }

regards,
dan carpenter


                 reply	other threads:[~2023-02-01 13:43 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=Y9prChfI3ExTpK2o@kili \
    --to=error27@gmail.com \
    --cc=cip-dev@lists.cip-project.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=masami.ichikawa@miraclelinux.com \
    --cc=sujuan.chen@mediatek.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 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.