Skip to content

Commit f5fda67

Browse files
Dan Carpenterthierryreding
authored andcommitted
gpu: host1x: fix an integer overflow check
Tegra is a 32 bit arch. On 32 bit systems then size_t is 32 bits so "total" will never be higher than UINT_MAX because of integer overflows. We need cast to u64 first before doing the math. Also the addition earlier: unsigned int num_unpins = num_cmdbufs + num_relocs; That can overflow as well, but I think it's still safe because we check both "num_cmdbufs" and "num_relocs" again in this test. Signed-off-by: Dan Carpenter <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
1 parent ccaddfe commit f5fda67

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

drivers/gpu/host1x/job.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ struct host1x_job *host1x_job_alloc(struct host1x_channel *ch,
4242

4343
/* Check that we're not going to overflow */
4444
total = sizeof(struct host1x_job) +
45-
num_relocs * sizeof(struct host1x_reloc) +
46-
num_unpins * sizeof(struct host1x_job_unpin_data) +
47-
num_waitchks * sizeof(struct host1x_waitchk) +
48-
num_cmdbufs * sizeof(struct host1x_job_gather) +
49-
num_unpins * sizeof(dma_addr_t) +
50-
num_unpins * sizeof(u32 *);
45+
(u64)num_relocs * sizeof(struct host1x_reloc) +
46+
(u64)num_unpins * sizeof(struct host1x_job_unpin_data) +
47+
(u64)num_waitchks * sizeof(struct host1x_waitchk) +
48+
(u64)num_cmdbufs * sizeof(struct host1x_job_gather) +
49+
(u64)num_unpins * sizeof(dma_addr_t) +
50+
(u64)num_unpins * sizeof(u32 *);
5151
if (total > ULONG_MAX)
5252
return NULL;
5353

0 commit comments

Comments
 (0)