From 71028d20eba6af8fc2559684a0b4f8856abb8204 Mon Sep 17 00:00:00 2001 From: Vamsi Krishna Gattupalli Date: Mon, 13 Jun 2022 10:36:04 -0700 Subject: [PATCH] msm: adsprpc: Validate the CID Validating the CID is a valid channel number. Change-Id: Ia30c084801795882a24462fe0b9b4200a7084228 Acked-by: Ranjith Goud Namala Signed-off-by: Vamsi Krishna Gattupalli --- drivers/char/adsprpc.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/char/adsprpc.c b/drivers/char/adsprpc.c index 5fdd69044425..3a2a4164b4e4 100644 --- a/drivers/char/adsprpc.c +++ b/drivers/char/adsprpc.c @@ -118,6 +118,9 @@ #define GET_TABLE_IDX_FROM_CTXID(ctxid) \ ((ctxid & FASTRPC_CTX_TABLE_IDX_MASK) >> FASTRPC_CTX_TABLE_IDX_POS) +#define VALID_FASTRPC_CID(cid) \ + (cid >= ADSP_DOMAIN_ID && cid < NUM_CHANNELS) + /* Reserve few entries in context table for critical kernel and static RPC * calls to avoid user invocations from exhausting all entries. */ @@ -2066,7 +2069,11 @@ static int context_alloc(struct fastrpc_file *fl, uint32_t kernel, if (err) goto bail; } - + VERIFY(err, VALID_FASTRPC_CID(cid)); + if (err) { + err = -ECHRNG; + goto bail; + } chan = &me->channel[cid]; spin_lock_irqsave(&chan->ctxlock, irq_flags);