From patchwork Mon Jun 21 16:16:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 464520 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:102:0:0:0:0 with SMTP id x2csp2738034jao; Mon, 21 Jun 2021 09:16:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwTdxUo6L8p+LSj6UtH6V/tzik2OOkyFY0/7eABxHyXr7S87g9jGEqT1aqJGZU9pLsQK28v X-Received: by 2002:a17:907:1611:: with SMTP id hb17mr12383981ejc.450.1624292197296; Mon, 21 Jun 2021 09:16:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624292197; cv=none; d=google.com; s=arc-20160816; b=MuJq6SJmwcqla4SgzMK1bSMZrR08COZqAXmi8PQcvguDqpQROWFqBAAVq5hFoN1RXJ 9b7Q3vuUcZRJhewEq/STmgXMRdEAnSoGk68wdy9zoSyDjOkIuGZO5LY8q3H8G8zPQxqE N4o0QVvDw4JikyfAz17nxEuo5Opc5TJCIebVCtXAH/vCMszIrMtM2cThZM5SY3sFmJMp eqPN/LFOiUbFWwuOSy8cWhWkPBQ+b08Jq7BsaddheRzbWVoXgDxvtIM1HDCAPwiFdWRS 8LYNMujixQpe4gzgVTMunCPwKMioyYrYoZ8aO4B2GIqqw3jFejTHoY8NxnZ2lhYBP0cj wrZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=LL5t3H80yxVqcOP2FCE0oHwI5menyXESZwHRdH8Og6c=; b=wesW70vvOIPz1HXmRo1FHDlw4HjTDoufERgdNFfF8v8x6fBdVd/Cv2MEeEj/iV5Isy 7vOR4vQTiPhUvQdcbCZFlTarHLEfBwUY5dX0MTJ+AZ91uObDiX2/N1X8s+c8PQaYYpzv LsrCfdr9IQ1lqeBvb0+d+DRq+YuINWbbGsAGQgc96yFi1ihq9tfRxOn4g+JcC09fwmkL wqs/+8Do3FuYj+YMPRWXLsRZBe50EwOHC9kpXwwkA2cHNN6PLoAZNMs5jyj+YgYvQsPk UmWQ5Lrmu6tmLDjnZzn8RcibFHKVbZYudwDGa9b7q4VUSjatQxOs4qZHWAzeiYcSqjRI Qh3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dxFfFblI; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g2si12616428edb.593.2021.06.21.09.16.37; Mon, 21 Jun 2021 09:16:37 -0700 (PDT) Received-SPF: pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dxFfFblI; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230290AbhFUQSt (ORCPT + 12 others); Mon, 21 Jun 2021 12:18:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230056AbhFUQSs (ORCPT ); Mon, 21 Jun 2021 12:18:48 -0400 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2080C061574 for ; Mon, 21 Jun 2021 09:16:34 -0700 (PDT) Received: by mail-pg1-x52c.google.com with SMTP id v7so14576440pgl.2 for ; Mon, 21 Jun 2021 09:16:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LL5t3H80yxVqcOP2FCE0oHwI5menyXESZwHRdH8Og6c=; b=dxFfFblIQ6U/Rla6caaO+KOyc4wsi6jn+qr1Embb7mlr3z+aaC9Kjnh0DPT9prslHT lxcfdQII69wpZqDMOk05ocxRuVS8dZSflAY5zXeFtNCcms4dWQuzw3I8CGe+XhLnBt1t NgK1KWB4p2/FqR9f05xWn7MF3atfzMzY4Tny6EmlPXuSThWtfSphb4IaXZt7Ff3Jr5ke pdfOtEd1flvVDonA6tbtEa4IU+w3KqWZguSuTpyPyXKZgV7zeURCL1dyzkXeofWCkpiD 8ota8+jOf52NXwsWNPBnssKu5XqoBaLTOjd9WUjBW6IeDi/59VKhwluD1RFftzCzz1M4 BsAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LL5t3H80yxVqcOP2FCE0oHwI5menyXESZwHRdH8Og6c=; b=uPkALHnDiGEUxPgBqx87s1cSTFF6TQcR8V7Ibc6ESfura9PwxlJ6RmfaMl+v+2mDY+ jCWBXPgD0jt7VCSqposy2OCh1VrgJZ7DZwhchW11e16/mno+dmPk781wx71tqqJl0yVk sSf2FK99jd4VzO6hC0JVtzjODJRScoragekQCN8VO1qMu0r2qoHgU9AcUeSgQ5fHirQ3 7MI/6+N3ccxAqXVfSsjWmidgKfGNWU6mFUOMEBo3qNgLd4B9HA2P9VSHUixwNSdfBb6o vGg+jMq2NkllLiqBbeDtfHTWrWdXyMs69WdPDqr0d5ejeGfLehk0I4z3ka24L3jcYtsj s3Cg== X-Gm-Message-State: AOAM530z/V6VjDWz6VryjCB2U3aB8CfjbSl2PhZq38QSX+5YpJd8VM8N ykRVkjYADV23ONjtFKNqdmYv X-Received: by 2002:a63:5553:: with SMTP id f19mr24178169pgm.419.1624292194215; Mon, 21 Jun 2021 09:16:34 -0700 (PDT) Received: from localhost.localdomain ([120.138.13.116]) by smtp.gmail.com with ESMTPSA id k88sm10734730pjk.15.2021.06.21.09.16.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Jun 2021 09:16:33 -0700 (PDT) From: Manivannan Sadhasivam To: gregkh@linuxfoundation.org Cc: hemantk@codeaurora.org, bbhatt@codeaurora.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, loic.poulain@linaro.org, stable@vger.kernel.org, Manivannan Sadhasivam , Jeffrey Hugo Subject: [PATCH 1/8] bus: mhi: core: Validate channel ID when processing command completions Date: Mon, 21 Jun 2021 21:46:09 +0530 Message-Id: <20210621161616.77524-2-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210621161616.77524-1-manivannan.sadhasivam@linaro.org> References: <20210621161616.77524-1-manivannan.sadhasivam@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Bhaumik Bhatt MHI reads the channel ID from the event ring element sent by the device which can be any value between 0 and 255. In order to prevent any out of bound accesses, add a check against the maximum number of channels supported by the controller and those channels not configured yet so as to skip processing of that event ring element. Cc: stable@vger.kernel.org Fixes: 1d3173a3bae7 ("bus: mhi: core: Add support for processing events from client device") Signed-off-by: Bhaumik Bhatt Reviewed-by: Hemant Kumar Reviewed-by: Manivannan Sadhasivam Reviewed-by: Jeffrey Hugo Link: https://lore.kernel.org/r/1619481538-4435-1-git-send-email-bbhatt@codeaurora.org Signed-off-by: Manivannan Sadhasivam --- drivers/bus/mhi/core/main.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) -- 2.25.1 diff --git a/drivers/bus/mhi/core/main.c b/drivers/bus/mhi/core/main.c index 22acde118bc3..ed07421c4870 100644 --- a/drivers/bus/mhi/core/main.c +++ b/drivers/bus/mhi/core/main.c @@ -773,11 +773,16 @@ static void mhi_process_cmd_completion(struct mhi_controller *mhi_cntrl, cmd_pkt = mhi_to_virtual(mhi_ring, ptr); chan = MHI_TRE_GET_CMD_CHID(cmd_pkt); - mhi_chan = &mhi_cntrl->mhi_chan[chan]; - write_lock_bh(&mhi_chan->lock); - mhi_chan->ccs = MHI_TRE_GET_EV_CODE(tre); - complete(&mhi_chan->completion); - write_unlock_bh(&mhi_chan->lock); + WARN_ON(chan >= mhi_cntrl->max_chan); + + if (chan < mhi_cntrl->max_chan && + mhi_cntrl->mhi_chan[chan].configured) { + mhi_chan = &mhi_cntrl->mhi_chan[chan]; + write_lock_bh(&mhi_chan->lock); + mhi_chan->ccs = MHI_TRE_GET_EV_CODE(tre); + complete(&mhi_chan->completion); + write_unlock_bh(&mhi_chan->lock); + } mhi_del_ring_element(mhi_cntrl, mhi_ring); }