mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
mailbox: ti-msgmgr: Read exact number of trailing message bytes
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: aace66b170 ("mailbox: Introduce TI message manager driver")
Signed-off-by: Beleswar Padhi <b-padhi@ti.com>
Acked-by: Andrew Davis <afd@ti.com>
Signed-off-by: Jassi Brar <jassisinghbrar@gmail.com>
This commit is contained in:
parent
bbf7f0d616
commit
645ae2edd5
|
|
@ -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;
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/* Ensure all unused data is 0 */
|
||||
data_trail &= 0xFFFFFFFF >> (8 * (sizeof(u32) - trail_bytes));
|
||||
memcpy(&data_trail, word_data, trail_bytes);
|
||||
writel(data_trail, data_reg);
|
||||
data_reg += sizeof(u32);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user