Skip to content

Commit 5cf2a57

Browse files
jhovoldgregkh
authored andcommitted
misc: fastrpc: fix memory corruption on open
commit d245f43 upstream. The probe session-duplication overflow check incremented the session count also when there were no more available sessions so that memory beyond the fixed-size slab-allocated session array could be corrupted in fastrpc_session_alloc() on open(). Fixes: f6f9279 ("misc: fastrpc: Add Qualcomm fastrpc basic driver model") Cc: stable@vger.kernel.org # 5.1 Signed-off-by: Johan Hovold <johan+linaro@kernel.org> Link: https://lore.kernel.org/r/20220829080531.29681-3-johan+linaro@kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c99bc90 commit 5cf2a57

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

drivers/misc/fastrpc.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,7 +1553,7 @@ static int fastrpc_cb_probe(struct platform_device *pdev)
15531553
spin_unlock_irqrestore(&cctx->lock, flags);
15541554
return -ENOSPC;
15551555
}
1556-
sess = &cctx->session[cctx->sesscount];
1556+
sess = &cctx->session[cctx->sesscount++];
15571557
sess->used = false;
15581558
sess->valid = true;
15591559
sess->dev = dev;
@@ -1566,13 +1566,12 @@ static int fastrpc_cb_probe(struct platform_device *pdev)
15661566
struct fastrpc_session_ctx *dup_sess;
15671567

15681568
for (i = 1; i < sessions; i++) {
1569-
if (cctx->sesscount++ >= FASTRPC_MAX_SESSIONS)
1569+
if (cctx->sesscount >= FASTRPC_MAX_SESSIONS)
15701570
break;
1571-
dup_sess = &cctx->session[cctx->sesscount];
1571+
dup_sess = &cctx->session[cctx->sesscount++];
15721572
memcpy(dup_sess, sess, sizeof(*dup_sess));
15731573
}
15741574
}
1575-
cctx->sesscount++;
15761575
spin_unlock_irqrestore(&cctx->lock, flags);
15771576
rc = dma_set_mask(dev, DMA_BIT_MASK(32));
15781577
if (rc) {

0 commit comments

Comments
 (0)