dmaengine: bestcomm: gen_bd: fix out-of-bounds access in PSC parameter lookup
PATCH v3 1/1 dmaengine: bestcomm: gen_bd: fix out-of-bounds access in PSC parameter lookup
The bcom_psc_params[] array has 6 entries (indices 0-5), but bcom_psc_gen_bd_rx_init() checked against MPC52xx_PSC_MAXNUM which can be 12 when CONFIG_PPC_MPC512x is set, allowing indices 6-11 to pass and read past the array.
A malformed device tree with a large cell-index could therefore trigger an out-of-bounds read. The garbage initiator and ipr values would then be used for MMIO writes via out_8(&bcom_eng->regs->ipr[...], ...), potentially causing out-of-bounds MMIO accesses.
---
v3: reduce bounds check to single function. It's not used anywhere anyway.
v2: fix title
drivers/dma/bestcomm/gen_bd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma/bestcomm/gen_bd.c +1 -1
@@ -321,7 +321,7 @@ static const struct bcom_psc_params bcom_psc_params[] = {struct bcom_task *bcom_psc_gen_bd_rx_init (unsigned psc_num,int queue_len,phys_addr_t fifo,int maxbufsize) { -if (psc_num >= MPC52xx_PSC_MAXNUM) +if (psc_num >=ARRAY_SIZE (bcom_psc_params))return NULL ; return bcom_gen_bd_rx_init(queue_len, fifo,
Signature · 1 line
2.55.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the patch fails to completely resolve the vulnerability. The patch correctly addresses an out-of-bounds array access in bcom_psc_gen_bd_rx_init() by checking psc_num >= ARRAY_SIZE(bcom_psc_params), but leaves the identical vulnerability unpatched in its sibling function bcom_psc_gen_bd_tx_init(). The author explicitly claims in the commit message that the TX bounds check was omitted because the function is 'not used anywhere anyway.' However, bcom_psc_gen_bd_tx_init() is exported and actively used in sound/soc/fsl/mpc5200_dma.c. In mpc5200_audio_dma_create(), tx_init is called unconditionally immediately after rx_init, reusing the exact same unvalidated device tree cell-index. If a malformed cell-index is provided, rx_init gracefully returns NULL, but execution continues to tx_init, where the unprotected out-of-bounds array read still occurs. These garbage values are then used as an index for an MMIO write in bcom_gen_bd_tx_reset(), resulting in a potentially severe out-of-bounds MMIO access. --
commit fe70e15aeccf81a4b8cdfa4a3e93e93a4e989ae4
Author: Rosen Penev <[email protected]>
dmaengine: bestcomm: gen_bd: fix out-of-bounds access in PSC parameter lookup
The bcom_psc_params[] array has 6 entries (indices 0-5), but bcom_psc_gen_bd_rx_init() checked against MPC52xx_PSC_MAXNUM which can be 12 when CONFIG_PPC_MPC512x is set, allowing indices 6-11 to pass and read past the array.
A malformed device tree with a large cell-index could therefore trigger an out-of-bounds read. The garbage initiator and ipr values would then be used for MMIO writes via out_8(&bcom_eng->regs->ipr[...], ...), potentially causing out-of-bounds MMIO accesses.
drivers/dma/bestcomm/gen_bd.c static struct bcom_psc_params { · line 321
Quoted 13 lines
drivers/dma/bestcomm/gen_bd.c +1
-1@@ -315,7 +315,7 @@ static struct bcom_psc_params {struct bcom_task *bcom_psc_gen_bd_rx_init (unsigned psc_num,int queue_len,phys_addr_t fifo,int maxbufsize) { -if (psc_num >= MPC52xx_PSC_MAXNUM) +if (psc_num >=ARRAY_SIZE (bcom_psc_params))return NULL ; return bcom_gen_bd_rx_init(queue_len, fifo,
[Severity: High]
This is a pre-existing issue, but does this patch fail to completely resolve the vulnerability by leaving the identical out-of-bounds access unpatched in the sibling function bcom_psc_gen_bd_tx_init()?
The bcom_psc_params array access in bcom_psc_gen_bd_tx_init() remains completely unprotected by bounds checks:
drivers/dma/bestcomm/gen_bd.c:bcom_psc_gen_bd_tx_init() {
...
return bcom_gen_bd_tx_init(queue_len, fifo,
bcom_psc_params[psc_num].tx_initiator,
bcom_psc_params[psc_num].tx_ipr);
}The patch omits the bounds check in the TX path on the assumption that the function is unused, but the function is exported and actively used here:
sound/soc/fsl/mpc5200_dma.c:mpc5200_audio_dma_create() {
...
psc_dma->playback.bcom_task =
bcom_psc_gen_bd_tx_init(psc_dma->id, 10, fifo);
...
}In mpc5200_audio_dma_create(), tx_init is called unconditionally immediately after rx_init, reusing the exact same unvalidated device tree cell-index. If a malformed cell-index is provided, rx_init gracefully returns NULL, but execution continues to tx_init, where the unprotected out-of-bounds array read still occurs.
These garbage values are then used as an index for an MMIO write in bcom_gen_bd_tx_reset(), resulting in a potentially severe out-of-bounds MMIO access:
drivers/dma/bestcomm/gen_bd.c:bcom_gen_bd_tx_reset() {
...
out_8(&bcom_eng->regs->ipr[priv->initiator], priv->ipr);
...
}Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 23 lines · Rosen Penev
The bcom_psc_params[] array has 6 entries (indices 0-5), but
bcom_psc_gen_bd_rx_init()checked againstMPC52xx_PSC_MAXNUMwhich can be 12 whenCONFIG_PPC_MPC512xis set, allowing indices 6-11 to pass and read past the array.A malformed device tree with a large cell-index could therefore trigger an out-of-bounds read. The garbage initiator and ipr values would then be used for MMIO writes via
out_8(&bcom_eng->regs->ipr[...], ...), potentially causing out-of-bounds MMIO accesses.Assisted-by LLMSigned-off-by Rosen Penev <[email protected]>---
v3: reduce bounds check to single function. It's not used anywhere anyway.
v2: fix titledrivers/dma/bestcomm/gen_bd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/dma/bestcomm/gen_bd.c +0
-0
drivers/dma/bestcomm/gen_bd.c static const struct bcom_psc_params bcom_psc_params[] = { · line 324
Quoted 5 lines
drivers/dma/bestcomm/gen_bd.c +1
-1@@ -321,7 +321,7 @@ static const struct bcom_psc_params bcom_psc_params[] = {struct bcom_task *bcom_psc_gen_bd_rx_init (unsigned psc_num,int queue_len,phys_addr_t fifo,int maxbufsize) { -if (psc_num >= MPC52xx_PSC_MAXNUM) +if (psc_num >=ARRAY_SIZE (bcom_psc_params))
why bcom_psc_gen_bd_tx_init() do't check it
Frank
Quoted 6 lines
drivers/dma/bestcomm/gen_bd.c +0
-1return NULL ; return bcom_gen_bd_rx_init(queue_len, fifo, --2.55.0