Skip to content

Commit 8b08dbb

Browse files
ta72thierryreding
authored andcommitted
firmware: tegra: Add return code checks and increase debugfs size
Add checking of the BPMP-FW return code values for MRQ_DEBUGFS calls. Also, development versions of the firmware may have debugfs with a directory structure larger than 256 KiB. Hence increase the size of the memory buffer to accommodate those firmware revisions. And finally, ensure that no access outside of allocated memory buffer happens in case BPMP-FW returns an invalid response size (nbytes) from mrq_debugfs_dumpdir() call. Signed-off-by: Timo Alho <[email protected]> Signed-off-by: Jon Hunter <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
1 parent b3a9e3b commit 8b08dbb

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

drivers/firmware/tegra/bpmp-debugfs.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ static int mrq_debugfs_read(struct tegra_bpmp *bpmp,
127127
err = tegra_bpmp_transfer(bpmp, &msg);
128128
if (err < 0)
129129
return err;
130+
else if (msg.rx.ret < 0)
131+
return -EINVAL;
130132

131133
*nbytes = (size_t)resp.fop.nbytes;
132134

@@ -184,6 +186,8 @@ static int mrq_debugfs_dumpdir(struct tegra_bpmp *bpmp, dma_addr_t addr,
184186
err = tegra_bpmp_transfer(bpmp, &msg);
185187
if (err < 0)
186188
return err;
189+
else if (msg.rx.ret < 0)
190+
return -EINVAL;
187191

188192
*nbytes = (size_t)resp.dumpdir.nbytes;
189193

@@ -374,7 +378,7 @@ int tegra_bpmp_init_debugfs(struct tegra_bpmp *bpmp)
374378
{
375379
dma_addr_t phys;
376380
void *virt;
377-
const size_t sz = SZ_256K;
381+
const size_t sz = SZ_512K;
378382
size_t nbytes;
379383
int ret;
380384
struct dentry *root;
@@ -394,8 +398,12 @@ int tegra_bpmp_init_debugfs(struct tegra_bpmp *bpmp)
394398
}
395399

396400
ret = mrq_debugfs_dumpdir(bpmp, phys, sz, &nbytes);
397-
if (ret < 0)
401+
if (ret < 0) {
402+
goto free;
403+
} else if (nbytes > sz) {
404+
ret = -EINVAL;
398405
goto free;
406+
}
399407

400408
ret = create_debugfs_mirror(bpmp, virt, nbytes, root);
401409
free:

0 commit comments

Comments
 (0)