Skip to content

Commit 6aae4ae

Browse files
tiensungngboonkhai
authored andcommitted
firmware: stratix10-svc: Potential buffer overflow fix
Fixed a potential buffer overflow in the data_claim thread. Potentially a miss-behaving ATF firmware could cause a buffer overflow if unchecked. Hence, we are adding checks before every write to the buffer. Signed-off-by: Ang Tien Sung <[email protected]>
1 parent 54c0a77 commit 6aae4ae

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

drivers/firmware/stratix10-svc.c

+14-12
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#define FPGA_CONFIG_POLL_COUNT_FAST 50
5050
#define FPGA_CONFIG_POLL_COUNT_SLOW 58
5151
#define BYTE_TO_WORD_SIZE 4
52+
#define SVC_BUFFER_RECLAIM_SIZE 4
5253

5354
/* stratix10 service layer clients */
5455
#define STRATIX10_RSU "stratix10-rsu"
@@ -218,7 +219,7 @@ static void svc_thread_cmd_data_claim(struct stratix10_svc_controller *ctrl,
218219
{
219220
struct arm_smccc_res res;
220221
unsigned long timeout;
221-
void *buf_claim_addr[4] = {NULL};
222+
void *buf_claim_addr[SVC_BUFFER_RECLAIM_SIZE] = {NULL};
222223
int buf_claim_count = 0;
223224

224225
reinit_completion(&ctrl->complete_status);
@@ -243,23 +244,24 @@ static void svc_thread_cmd_data_claim(struct stratix10_svc_controller *ctrl,
243244
break;
244245
}
245246

246-
if (buf_claim_count >= 4) {
247-
/* Maximum buffer to reclaim */
247+
if (buf_claim_count >= SVC_BUFFER_RECLAIM_SIZE) {
248+
/* Expecting no more than defined size */
248249
pr_err("%s Buffer re-claim error", __func__);
249250
break;
250251
}
251252

252-
buf_claim_addr[buf_claim_count++]
253-
= svc_pa_to_va(res.a1);
254-
if (res.a2) {
255-
buf_claim_addr[buf_claim_count++]
256-
= svc_pa_to_va(res.a2);
257-
}
258-
if (res.a3) {
259-
buf_claim_addr[buf_claim_count++]
260-
= svc_pa_to_va(res.a3);
253+
buf_claim_addr[buf_claim_count] = svc_pa_to_va(res.a1);
254+
buf_claim_count++;
255+
256+
if (res.a2 && buf_claim_count < SVC_BUFFER_RECLAIM_SIZE) {
257+
buf_claim_addr[buf_claim_count] = svc_pa_to_va(res.a2);
258+
buf_claim_count++;
261259
}
262260

261+
if (res.a3 && buf_claim_count < SVC_BUFFER_RECLAIM_SIZE) {
262+
buf_claim_addr[buf_claim_count] = svc_pa_to_va(res.a3);
263+
buf_claim_count++;
264+
}
263265
}
264266
} while (res.a0 == INTEL_SIP_SMC_STATUS_OK ||
265267
res.a0 == INTEL_SIP_SMC_STATUS_BUSY ||

0 commit comments

Comments
 (0)