soc: aspeed: xdma: Fix command buffer overrun
PATCH v2 1/1 soc: aspeed: xdma: Fix command buffer overrun
In the case of an operation requiring two commands, the edge case at the top of the command buffer was not handled, resulting in buffer overrun. Fix this by using a loop to copy the commands into the buffer and increment and modulo after each one.
--- drivers/soc/aspeed/aspeed-xdma.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/soc/aspeed/aspeed-xdma.c +7 -3
@@ -430,15 +430,19 @@ static void aspeed_xdma_start(struct aspeed_xdma *ctx, struct aspeed_xdma_op *op, u32 bmc_addr, struct aspeed_xdma_client *client) { + unsigned int i;unsigned long flags;struct aspeed_xdma_cmd cmds[2 ];unsigned int rc = ctx->chip->set_cmd (ctx, cmds, op, bmc_addr);mutex_lock (&ctx->start_lock); -memcpy (&ctx->cmdq[ctx->cmd_idx], cmds, - rc *sizeof (struct aspeed_xdma_cmd )); - ctx->cmd_idx = (ctx->cmd_idx + rc) %XDMA_NUM_CMDS ; +for (i =0 ; i < rc; ++i) { +memcpy (&ctx->cmdq[ctx->cmd_idx], &cmds[i], +sizeof (struct aspeed_xdma_cmd )); + ctx->cmd_idx = (ctx->cmd_idx +1 ) %XDMA_NUM_CMDS ; + } + ctx->upstream = !!op->direction;spin_lock_irqsave (&ctx->client_lock, flags);
Signature · 1 line
2.24.0
Quoted 21 lines · Eddie James
In the case of an operation requiring two commands, the edge case at the top of the command buffer was not handled, resulting in buffer overrun. Fix this by using a loop to copy the commands into the buffer and increment and modulo after each one.
Signed-off-by Eddie James <[email protected]>--- drivers/soc/aspeed/aspeed-xdma.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)drivers/soc/aspeed/aspeed-xdma.c +1
-0@@ -430,15 +430,19 @@ static void aspeed_xdma_start(struct aspeed_xdma *ctx, struct aspeed_xdma_op *op, u32 bmc_addr, struct aspeed_xdma_client *client) { + unsigned int i;unsigned long flags;struct aspeed_xdma_cmd cmds[2 ];
drivers/soc/aspeed/aspeed-xdma.c static void aspeed_xdma_start(struct aspeed_xdma *ctx, · line 442
Quoted 10 lines
drivers/soc/aspeed/aspeed-xdma.c +3
-3unsigned int rc = ctx->chip->set_cmd (ctx, cmds, op, bmc_addr);mutex_lock (&ctx->start_lock); -memcpy (&ctx->cmdq[ctx->cmd_idx], cmds, - rc *sizeof (struct aspeed_xdma_cmd )); - ctx->cmd_idx = (ctx->cmd_idx + rc) %XDMA_NUM_CMDS ; +for (i =0 ; i < rc; ++i) { +memcpy (&ctx->cmdq[ctx->cmd_idx], &cmds[i], +sizeof (struct aspeed_xdma_cmd ));
Bit of a nit, but it would be more obviously correct to me to do sizeof(ctx->cmdq[ctx->cmd_idx]). However this wasn't something you changed as part of this patch, so maybe it's a future enhancement.
Quoted 10 lines
drivers/soc/aspeed/aspeed-xdma.c +3
-0+ ctx->cmd_idx = (ctx->cmd_idx +1 ) %XDMA_NUM_CMDS ; + } + ctx->upstream = !!op->direction;spin_lock_irqsave (&ctx->client_lock, flags);Signature · 1 line
2.24.0