From: Beleswar Padhi <b-padhi@ti.com>
To: <jassisinghbrar@gmail.com>, <nm@ti.com>, <afd@ti.com>, <u-kumar1@ti.com>
Cc: <linux-kernel@vger.kernel.org>, <b-padhi@ti.com>, <vigneshr@ti.com>
Subject: [PATCH v3 2/2] mailbox: ti-msgmgr: Read exact number of trailing message bytes
Date: Thu, 1 Oct 2026 01:31:58 +0530 [thread overview]
Message-ID: <20260930200158.174118-3-b-padhi@ti.com> (raw)
In-Reply-To: <20260930200158.174118-1-b-padhi@ti.com>
ti_msgmgr_send_data() copies the message to the data registers in u32
units. This has been harmless so far because the clients (TI-SCI)
always passed its preallocated message buffer, which is sized to the
maximum message size (60 or 64 bytes, a multiple of 4), so the extra
bytes read were still within the buffer. But, with a later TI-SCI
update, the message size can be varying now and not guaranteed to be a
multiple of 4, which would trigger KASAN out-of-bounds reports.
Therefore, memcpy() only the trailing bytes into a zeroed u32 before
writing it to the register. This is at most 3 bytes, so the overhead
is negligible.
Fixes: aace66b170ce ("mailbox: Introduce TI message manager driver")
Signed-off-by: Beleswar Padhi <b-padhi@ti.com>
---
v3: Changelog:
1. Added Fixes tag in commit msg.
Link to v2:
https://lore.kernel.org/all/20260930143810.2419010-3-b-padhi@ti.com/
v2: Changelog:
1. Use memcpy() to construct the trailing word to handle host
endianness. (Sashiko bot)
Link to v1:
https://lore.kernel.org/all/20260929200159.4033010-3-b-padhi@ti.com/
drivers/mailbox/ti-msgmgr.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/drivers/mailbox/ti-msgmgr.c b/drivers/mailbox/ti-msgmgr.c
index 425d5f9d9d0e3..e04b7f721ac8e 100644
--- a/drivers/mailbox/ti-msgmgr.c
+++ b/drivers/mailbox/ti-msgmgr.c
@@ -20,6 +20,7 @@
#include <linux/platform_device.h>
#include <linux/property.h>
#include <linux/soc/ti/ti-msgmgr.h>
+#include <linux/string.h>
#define Q_DATA_OFFSET(proxy, queue, reg) \
((0x10000 * (proxy)) + (0x80 * (queue)) + ((reg) * 4))
@@ -425,10 +426,15 @@ static int ti_msgmgr_send_data(struct mbox_chan *chan, void *data)
trail_bytes = message->len % sizeof(u32);
if (trail_bytes) {
- u32 data_trail = *word_data;
-
- /* Ensure all unused data is 0 */
- data_trail &= 0xFFFFFFFF >> (8 * (sizeof(u32) - trail_bytes));
+ /*
+ * Copy only the trailing bytes instead of reading a full u32,
+ * as the message buffer may end right after them and a u32
+ * read would go past the end of it. This also leaves all
+ * unused data as 0.
+ */
+ u32 data_trail = 0;
+
+ memcpy(&data_trail, word_data, trail_bytes);
writel(data_trail, data_reg);
data_reg += sizeof(u32);
}
--
2.34.1
next prev parent reply other threads:[~2026-09-30 20:03 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-30 20:01 [PATCH v3 0/2] mailbox: ti-msgmgr: Fixes for polled rx and trailing bytes Beleswar Padhi
2026-09-30 20:01 ` [PATCH v3 1/2] mailbox: ti-msgmgr: Do not report rx poll timeout as a send failure Beleswar Padhi
2026-09-30 20:01 ` Beleswar Padhi [this message]
2026-09-30 20:04 ` [PATCH v3 0/2] mailbox: ti-msgmgr: Fixes for polled rx and trailing bytes Andrew Davis
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=20260930200158.174118-3-b-padhi@ti.com \
--to=b-padhi@ti.com \
--cc=afd@ti.com \
--cc=jassisinghbrar@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=nm@ti.com \
--cc=u-kumar1@ti.com \
--cc=vigneshr@ti.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®