Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3103128pxj; Sun, 23 May 2021 21:45:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJybrrhbOZSvA0g1jsezIXXimoK6OfZr4mVd3dVf5oTlwzcsCUB5Q6nD66RajR8bUDbyDP0j X-Received: by 2002:a05:6e02:cc4:: with SMTP id c4mr15789103ilj.57.1621831514290; Sun, 23 May 2021 21:45:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621831514; cv=none; d=google.com; s=arc-20160816; b=FGEPC7uXdd7Ig18V9TcqT3eYKI+yoFYk1ThsdZ+GwbKd0iuZDaNbnM5SFeGVUp+qb9 6dSqyiqBx5NTnMZu5YvzmMc4nDhSNjKjNA2reN/a8+5agn6wqCabx07Ct+/E6ICtkkth IK6EjdRgktLD+wz+ZcvGlriVCIFYdrBEKKqzyEtsNJ3AGmO16rcZmoDBiVaO4n3p+krO Tts+lAZnjlHX+/WhqtJQOkLrSIhctdtGeMHW0QCFE55+ezotDmUuQu1Iv2lleE7O7uYt PmL8ftDwnLcAzLPHuUo+LuhUG8X9H/kE3O7a1QJjrN6VEhKq6VV0BsJFUAavxduDnla3 jCKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=GepLbdbjGV1ycrQxG4b8/nNqglHTIxbk99LIKbMgmyo=; b=pfNuqScFp4DQS6bFjRXkOKoX9N9Vvu9mkmkpqrJX3Ru2/sU0oY7Ubm5jwsbctrzbua T/Nv+QJ4gUHKRWktyu2Yi6WYNJ8i8EqNrajzE+6fTH6yYNSnTLVv/7NoJ1X9mb2e5IH6 bSLDnzVT+OglcSEGByyRZu6UOCbdQZf/VohqbnzLco0NFayeDrq+BxFI8ESMKeIQFARj g60fo3y/WLDkiFUHnQATp+W1+G/U3O6EUM4h6k7JRik4ne7he/AKR0PgrKsv0c0ZIqfk J1otZpvxMnQK9y6L2iuqar3E1IDlP3wzE9GG4SF701NiuHCIu3UWotF0GFg8xx1qe3jZ WkLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yhYrdYhn; 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=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 s7si8826338ilu.37.2021.05.23.21.45.00; Sun, 23 May 2021 21:45:14 -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; dkim=pass header.i=@linaro.org header.s=google header.b=yhYrdYhn; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232230AbhEXEoV (ORCPT + 99 others); Mon, 24 May 2021 00:44:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229777AbhEXEoU (ORCPT ); Mon, 24 May 2021 00:44:20 -0400 Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38F41C061756 for ; Sun, 23 May 2021 21:42:35 -0700 (PDT) Received: by mail-pg1-x535.google.com with SMTP id 29so8091176pgu.11 for ; Sun, 23 May 2021 21:42:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=GepLbdbjGV1ycrQxG4b8/nNqglHTIxbk99LIKbMgmyo=; b=yhYrdYhnm0R+E61X42D7AGR+Sn9ZLDUjATInjVeOzIy1OIlEKI5mxocf8sp+tjhPqt SmeYnRzewjpLCRV8G8ASk3pvBTlJjVY24JQZGCSY4Nl4DEMEUsUq5J6w7ZCLNQtWjOfO eUGrVlSX3iWsljx06w2vVLQ8f5rhogVMAqBYbvAMs5YEc/P7SfqaLILmsQW8kiT9g//a zL7aL+M8wxeMAVvslGOll8lWsM9Cx5/YZDdHjoVIGIQdj5ybU9yp99ZWP0TFouQvvqrk hQsBzQguNXtwiDm+Hfa9DJG5X41wscFPzqEQ8K2vxIDZZj5YpMCOHT1gJQn9NG8ijc+9 K2lA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=GepLbdbjGV1ycrQxG4b8/nNqglHTIxbk99LIKbMgmyo=; b=CEkszBDm8PScA37dcwIm3McfJwU4chW+swBQJ9H2ZDAwRpmFHmrfQ700T5FmUuAzqm IOUwDmswoI/WJ8S7YWpz7c8sPHSN24iV8E1Zjpc4lO+zr1OaSNJnfkO/Oe0dfq0sHiZt LUlPjrVvZW+icO2x0cyW46Y4C7X71pXLtyMIlDoiq2/fVjYR8024eRLiTpTQYX7+Fhhn j4jkuAFGNDfzaOlUWgkb9qMzXXZK4lvLDLwu/cAyGXPc9emuDr28frfAxHWyIRm+BGis S+IB1n7yItf61xgKvj7GXidJDfrq5qi6ke7cPVrGVHoXKYELrcUnEzh+KjECjQs1+eWk yIJA== X-Gm-Message-State: AOAM533lFlPuUja0DxO6fXAAmY6IYocfhTOqdpKn3ea3LdUE+2s3ysHl YER9ljft/FaeRvrj8HmL9Thf X-Received: by 2002:a63:cd08:: with SMTP id i8mr11363145pgg.312.1621831353424; Sun, 23 May 2021 21:42:33 -0700 (PDT) Received: from work ([120.138.12.48]) by smtp.gmail.com with ESMTPSA id m191sm10216832pga.88.2021.05.23.21.42.30 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 23 May 2021 21:42:32 -0700 (PDT) Date: Mon, 24 May 2021 10:12:28 +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: <20210524044228.GD8823@work> 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> User-Agent: Mutt/1.9.4 (2018-02-28) 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 Applied to mhi-next! 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 >