Skip to content

Commit 83e007a

Browse files
Carlo Caionekhilman
authored andcommitted
firmware: meson-sm: Check for buffer output size
After the data is read by the secure monitor driver it is being copied in the output buffer checking only the size of the bounce buffer but not the size of the output buffer. Fix this in the secure monitor driver slightly changing the API. Fix also the efuse driver that it is the only driver using this API to not break bisectability. Signed-off-by: Carlo Caione <carlo@endlessm.com> Acked-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org> # for nvmem Acked-by: Mark Rutland <mark.rutland@arm.com> Signed-off-by: Kevin Hilman <khilman@baylibre.com>
1 parent c1ae3cf commit 83e007a

3 files changed

Lines changed: 10 additions & 6 deletions

File tree

‎drivers/firmware/meson/meson_sm.c‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ EXPORT_SYMBOL(meson_sm_call);
127127
* meson_sm_call_read - retrieve data from secure-monitor
128128
*
129129
* @buffer: Buffer to store the retrieved data
130+
* @bsize: Size of the buffer
130131
* @cmd_index: Index of the SMC32 function ID
131132
* @arg0: SMC32 Argument 0
132133
* @arg1: SMC32 Argument 1
@@ -136,8 +137,8 @@ EXPORT_SYMBOL(meson_sm_call);
136137
*
137138
* Return: size of read data on success, a negative value on error
138139
*/
139-
int meson_sm_call_read(void *buffer, unsigned int cmd_index, u32 arg0,
140-
u32 arg1, u32 arg2, u32 arg3, u32 arg4)
140+
int meson_sm_call_read(void *buffer, unsigned int bsize, unsigned int cmd_index,
141+
u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4)
141142
{
142143
u32 size;
143144

@@ -147,10 +148,13 @@ int meson_sm_call_read(void *buffer, unsigned int cmd_index, u32 arg0,
147148
if (!fw.chip->cmd_shmem_out_base)
148149
return -EINVAL;
149150

151+
if (bsize > fw.chip->shmem_size)
152+
return -EINVAL;
153+
150154
if (meson_sm_call(cmd_index, &size, arg0, arg1, arg2, arg3, arg4) < 0)
151155
return -EINVAL;
152156

153-
if (!size || size > fw.chip->shmem_size)
157+
if (!size || size > bsize)
154158
return -EINVAL;
155159

156160
if (buffer)

‎drivers/nvmem/meson-efuse.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static int meson_efuse_read(void *context, unsigned int offset,
2727
u8 *buf = val;
2828
int ret;
2929

30-
ret = meson_sm_call_read(buf, SM_EFUSE_READ, offset,
30+
ret = meson_sm_call_read(buf, bytes, SM_EFUSE_READ, offset,
3131
bytes, 0, 0, 0);
3232
if (ret < 0)
3333
return ret;

‎include/linux/firmware/meson/meson_sm.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ int meson_sm_call(unsigned int cmd_index, u32 *ret, u32 arg0, u32 arg1,
2525
u32 arg2, u32 arg3, u32 arg4);
2626
int meson_sm_call_write(void *buffer, unsigned int b_size, unsigned int cmd_index,
2727
u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4);
28-
int meson_sm_call_read(void *buffer, unsigned int cmd_index, u32 arg0, u32 arg1,
29-
u32 arg2, u32 arg3, u32 arg4);
28+
int meson_sm_call_read(void *buffer, unsigned int bsize, unsigned int cmd_index,
29+
u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4);
3030

3131
#endif /* _MESON_SM_FW_H_ */

0 commit comments

Comments
 (0)