From: Pengpeng Hou <pengpeng@iscas.ac.cn>
To: Elad Nachman <enachman@marvell.com>
Cc: Pengpeng Hou <pengpeng@iscas.ac.cn>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"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
Subject: [PATCH] net: prestera: avoid overreading a short firmware tail
Date: Sun, 30 Aug 2026 22:24:03 +0800 [thread overview]
Message-ID: <20260830142404.37663-1-pengpeng@iscas.ac.cn> (raw)
prestera_ldr_send() writes the firmware in 32-bit words even when the final
chunk is not four-byte aligned. The last iteration then reads a full u32
from a one-to-three-byte tail.
Reserve the aligned ring space, use unaligned-safe full-word loads, and
zero-pad a partial final word without reading beyond the firmware image.
Fixes: 4c2703dfd7fa ("net: marvell: prestera: Add PCI interface support")
Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn>
---
drivers/net/ethernet/marvell/prestera/prestera_pci.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/drivers/net/ethernet/marvell/prestera/prestera_pci.c b/drivers/net/ethernet/marvell/prestera/prestera_pci.c
index 1ad0e62a8433b..9b3d6e5a81d1c 100644
--- a/drivers/net/ethernet/marvell/prestera/prestera_pci.c
+++ b/drivers/net/ethernet/marvell/prestera/prestera_pci.c
@@ -589,17 +589,26 @@ static u8 __iomem *prestera_ldr_wr_ptr(struct prestera_fw *fw)
static int prestera_ldr_send(struct prestera_fw *fw, const u8 *buf, size_t len)
{
+ size_t write_len = ALIGN(len, sizeof(u32));
+ size_t i;
int err;
- int i;
- err = prestera_ldr_wait_buf(fw, len);
+ err = prestera_ldr_wait_buf(fw, write_len);
if (err) {
dev_err(fw->dev.dev, "failed wait for sending firmware\n");
return err;
}
- for (i = 0; i < len; i += 4) {
- writel_relaxed(*(u32 *)(buf + i), prestera_ldr_wr_ptr(fw));
+ for (i = 0; i + sizeof(u32) <= len; i += sizeof(u32)) {
+ writel_relaxed(get_unaligned((u32 *)(buf + i)),
+ prestera_ldr_wr_ptr(fw));
+ prestera_ldr_wr_idx_move(fw, 4);
+ }
+ if (i < len) {
+ u32 last = 0;
+
+ memcpy(&last, buf + i, len - i);
+ writel_relaxed(last, prestera_ldr_wr_ptr(fw));
prestera_ldr_wr_idx_move(fw, 4);
}
base-commit: 08dbfad3f5040f5bdb6c529da20d6d4e81fefd72
--
2.50.1
next reply other threads:[~2026-08-30 14:24 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-30 14:24 Pengpeng Hou [this message]
2026-08-30 14:28 ` [PATCH] net: prestera: avoid overreading a short firmware tail Andrew Lunn
2026-09-02 13:06 ` kernel test robot
2026-09-03 14:01 ` kernel test robot
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=20260830142404.37663-1-pengpeng@iscas.ac.cn \
--to=pengpeng@iscas.ac.cn \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=enachman@marvell.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--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