From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Cc: jianqiang wang <wjq.sec@gmail.com>
Subject: [PATCH 5/5] net: smc911x: do not read past the receive buffer
Date: Mon, 27 May 2024 09:29:15 +0200 [thread overview]
Message-ID: <20240527072915.3229221-5-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20240527072915.3229221-1-s.hauer@pengutronix.de>
The hardware may report a packet longer than our receive buffer. Instead
of reading past the read buffer, discard too long packets.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/net/smc911x.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/net/smc911x.c b/drivers/net/smc911x.c
index 767d51761b..19117c0af2 100644
--- a/drivers/net/smc911x.c
+++ b/drivers/net/smc911x.c
@@ -460,8 +460,13 @@ static int smc911x_eth_rx(struct eth_device *edev)
smc911x_reg_write(priv, RX_CFG, 0);
tmplen = (pktlen + 2 + 3) / 4;
- while(tmplen--)
- *data++ = smc911x_reg_read(priv, RX_DATA_FIFO);
+ if (tmplen <= PKTSIZE / sizeof(u32)) {
+ while (tmplen--)
+ *data++ = smc911x_reg_read(priv, RX_DATA_FIFO);
+ } else {
+ while (tmplen--)
+ smc911x_reg_read(priv, RX_DATA_FIFO);
+ }
if(status & RX_STS_ES)
dev_err(&edev->dev, "dropped bad packet. Status: 0x%08x\n",
--
2.39.2
prev parent reply other threads:[~2024-05-27 7:29 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-27 7:29 [PATCH 1/5] net: cs8900: simplify buffer read loop Sascha Hauer
2024-05-27 7:29 ` [PATCH 2/5] net: cs8900: do not read past the receive buffer Sascha Hauer
2024-05-27 8:58 ` Jules Maselbas
2024-05-27 9:34 ` Sascha Hauer
2024-05-27 7:29 ` [PATCH 3/5] net: ks8851_mll: " Sascha Hauer
2024-05-27 7:29 ` [PATCH 4/5] net: liteeth: " Sascha Hauer
2024-05-27 7:29 ` Sascha Hauer [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=20240527072915.3229221-5-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=wjq.sec@gmail.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