Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1090988pxj; Fri, 21 May 2021 06:20:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxdpR8sAB0KK1C2B1mGkKTy01nUJOry0j5spts7Yp5eOJBuSST1f6tdq2FWPDsIqxqUOt0/ X-Received: by 2002:a17:906:c7d2:: with SMTP id dc18mr10594012ejb.188.1621603205519; Fri, 21 May 2021 06:20:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621603205; cv=none; d=google.com; s=arc-20160816; b=BVtmDEoqd6AUF6gW/R2jAaulBY99MCQor42lgpUcLEu2gZGJGCWZ510pviSOZARa1s 0mDgoGuVRjoVf5ChYeuiE7pyjfZjlKf2PTRlfdO4u/byE13nYDMwIGK5vuyl+7h7jML0 8JnOLL89iykqD/xWwljUycdo2ZFd/68K6h4KAPnUXPUyqUT2NCE+0YyYfErUtbtyBbAG v7A+SpSYazkYqvFgQBXgX7T9qY1QKppiayeM1mk5LSvk2N8YDDozBtEbeQoP4i7n/kUB xQf7PnYa6u6BH+L75JBl+SJV8tFJ77guLGMVpx38S/2Vpn0b3pWuxbp0CETX3Ma2oI8I Kobw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=mW12kEiFDXUzKpJQ9iGDUhkb4BPoBQjXV0agUdZDaRo=; b=owLAT/xCqPxdzJMJd9OEp9sZqUFTxqx0FpvTvCiqF+oh39yoj46DSXqsEDC2KbuJ3Y 67XaWsEwSGQd8yiOh1PR18Gnstik00/nHT1Pz7DDhQMWYZ8gChTYiH6XNR30VW9LJgiM +DcNwLXEK4MZztBsiyQpsvryGXS3qll1t89vbsyUSqojw2TX8FLsFpnUffyEDTEenF4+ gN3BB4ZV9tNlSZ1xoyeTlCYP4m5qHY5ehjOuBrvETQFlMr7goEQWkPlU+lZNZQ7uoQYL ED3FupvWOc04fQvrepGGjKlrQGZB+yqOCW+/XUAMO3fH00O92+6weqa8PwJX/P4oPpUM we5w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (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 bt12si5491030ejb.669.2021.05.21.06.19.41; Fri, 21 May 2021 06:20:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233581AbhEUNS4 (ORCPT + 99 others); Fri, 21 May 2021 09:18:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:41544 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231601AbhEUNSu (ORCPT ); Fri, 21 May 2021 09:18:50 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id F021861244; Fri, 21 May 2021 13:17:23 +0000 (UTC) Date: Fri, 21 May 2021 18:47:19 +0530 From: Manivannan Sadhasivam To: Bhaumik Bhatt Cc: linux-arm-msm@vger.kernel.org, hemantk@codeaurora.org, jhugo@codeaurora.org, linux-kernel@vger.kernel.org, loic.poulain@linaro.org Subject: Re: [PATCH] bus: mhi: core: Validate channel ID when processing command completions Message-ID: <20210521131719.GH70095@thinkpad> References: <1619481538-4435-1-git-send-email-bbhatt@codeaurora.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1619481538-4435-1-git-send-email-bbhatt@codeaurora.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 26, 2021 at 04:58:58PM -0700, Bhaumik Bhatt wrote: > 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. > > Fixes: 1d3173a3bae7 ("bus: mhi: core: Add support for processing events from client device") > Signed-off-by: Bhaumik Bhatt Reviewed-by: Manivannan Sadhasivam Thanks, Mani > --- > drivers/bus/mhi/core/main.c | 15 ++++++++++----- > 1 file changed, 10 insertions(+), 5 deletions(-) > > diff --git a/drivers/bus/mhi/core/main.c b/drivers/bus/mhi/core/main.c > index 22acde1..ed07421 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); > } > -- > The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, > a Linux Foundation Collaborative Project >