From patchwork Fri Jun 25 12:33:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 466851 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp1417616jao; Fri, 25 Jun 2021 05:34:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJybrX7+szNs4vwroHNisDiJiiVGs0j2RGrYE3EEUuLGHGad05CQDSx/YWbSZ7LaNe2xNgHn X-Received: by 2002:a05:6402:411:: with SMTP id q17mr14252674edv.313.1624624494033; Fri, 25 Jun 2021 05:34:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624624494; cv=none; d=google.com; s=arc-20160816; b=pZtRuLSHWSRFPcGlvfTb8b1R3ghCf/1j3HsGTCzNeqH7ZWa+USSGfSA+QHyV7VJhiU PvuGJ6HobQ5r5Mblr2DV/S4L1Y4hXtuBvJZXoXftbhN6KklGo5gW/scPei7buJ6tf1YE MQN7GtsepMSFb+IyX1O2cwunoNWMjhTYa+hArc5x6Xb3eVMBmiEOrVcl/2DUhMkBojmR bdOgUPHS8jPuqT47zljJsmMl6k6zcw0d0Ub+5+EQw+zs/vfOrmG67DuDxVYd6iQ0REFJ sgp+qOXShZEul6yC52sLvbhoBxFw9ZnCWdCxCpOF3xRvdjA+S1RCjrsbQY6wGO5EBdss yCDg== 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=g+lLagFeszou/6sKi0JtQNyDv5OxzHHtHPuB74dMzb0=; b=y0z6otPUFtuNPRn4WjX83JhBfRdN/iiSAYfdPFsFzzAtku2oljiXkCq55KhYFed8j+ qNtdUroQ/P0QMCd3LGCCG5vWgQQZIVMrA1lL07cyq+VVLThx3YrPZ770QAAURECfBIq9 K2teGbGmN9n+vxiXt0LXIin/QoG6oaZc+zzdwGYQX6l1pii7F7d0OIC/htmyqCwuAGL9 EJUP8dgFNPqXdhtwJ7pf6+5bn7d2CQh1XZR2GI04JawpTyza3PSC/zl+kHCbJ9Fq5bf0 KV5UO1PDc/wfBeSQFxK564lJNsmD0PenLybaDa6FTs6JItkwrZi4pXYuLpHIZKCh0Y77 t8Dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=S83L6xzt; spf=pass (google.com: domain of linux-arm-msm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-arm-msm-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 w9si5765682ejk.580.2021.06.25.05.34.53; Fri, 25 Jun 2021 05:34:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-arm-msm-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=S83L6xzt; spf=pass (google.com: domain of linux-arm-msm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-arm-msm-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 S231607AbhFYMhL (ORCPT + 17 others); Fri, 25 Jun 2021 08:37:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231630AbhFYMg5 (ORCPT ); Fri, 25 Jun 2021 08:36:57 -0400 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07DBAC061768 for ; Fri, 25 Jun 2021 05:34:34 -0700 (PDT) Received: by mail-pl1-x62e.google.com with SMTP id b3so4656598plg.2 for ; Fri, 25 Jun 2021 05:34: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=g+lLagFeszou/6sKi0JtQNyDv5OxzHHtHPuB74dMzb0=; b=S83L6xztJyvMDdrDFudWRKLH2YgerUT+jvHanW2eS+hr0VefoDlCCLQxtDG9RwEV9B WocxhY2bygwxU1a+h4YRatVNm8Pu+p4kQpIR8AV9HJrzPaZs+wbPsujVvyhJKbHhIvnl 3fZcwkDXnx1o4sS6fWNHoN4vjTJAgsJ2wD1ObNa1zhzvz8iFz0QlLAHr5uk/rBNJV2kR SOgH278CQrhzmGgm1dmbaVUnnZpckIYDupAzYRTE2bV7GLro+DD9xhXf66jyWaS4p8zf ezLhNM1qCEhYlr9VM+CsGs1HiVKqFI0gzDpDylrcMlWu5BXXUazz665O5/OV5520le5H +YjA== 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=g+lLagFeszou/6sKi0JtQNyDv5OxzHHtHPuB74dMzb0=; b=hUYG1f9fxsxcemu5GgIxL47djLEZm42jXdJkQ7C44oKYhEnWkhWTCDxeHFgUas0UDw MWnOwmrcAcNK2DdUjnlYjnhqsiEkDzlKGxdJ9gr5/nn3dEHfFrOeiRWtrQE7WsEetf3Q fC/oog8Jq+7CUubwzs3mxuJkJGV8yYY2jqXWEf+i7L6nawcM8k8fSbWLTa4jbRQh4ZUK xA8eEYYJL3Xq7T9xMzh6N115DzzE0ScKIVz7fIR8cUK8TcRUBszGAmkYYHLA+PltzaOk 3PkRQgCRfHLFwQ3v6fqsz9QE5cNun/AngH7jDHCfAG4rViCwjX/uizvQjjGVMmL9EoUs p8kQ== X-Gm-Message-State: AOAM5329g4hLcCc4L7UtU/ada6YXyimH95P+ONBsSlWgXEiPLchtO93+ +wfhk2f1HHIj/nRvlUho6a8V X-Received: by 2002:a17:90b:603:: with SMTP id gb3mr11364268pjb.230.1624624473578; Fri, 25 Jun 2021 05:34:33 -0700 (PDT) Received: from localhost.localdomain ([2409:4072:600b:2a0:ed5d:53e7:c64e:1bac]) by smtp.gmail.com with ESMTPSA id y7sm6077780pfy.153.2021.06.25.05.34.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Jun 2021 05:34:32 -0700 (PDT) From: Manivannan Sadhasivam To: gregkh@linuxfoundation.org Cc: hemantk@codeaurora.org, bbhatt@codeaurora.org, linux-arm-msm@vger.kernel.org, jhugo@codeaurora.org, linux-kernel@vger.kernel.org, loic.poulain@linaro.org, kvalo@codeaurora.org, ath11k@lists.infradead.org, stable@vger.kernel.org, Manivannan Sadhasivam , Jeffrey Hugo Subject: [PATCH 04/10] bus: mhi: core: Validate channel ID when processing command completions Date: Fri, 25 Jun 2021 18:03:49 +0530 Message-Id: <20210625123355.11578-5-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210625123355.11578-1-manivannan.sadhasivam@linaro.org> References: <20210625123355.11578-1-manivannan.sadhasivam@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@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/1624558141-11045-1-git-send-email-bbhatt@codeaurora.org Signed-off-by: Manivannan Sadhasivam --- drivers/bus/mhi/core/main.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) -- 2.25.1 diff --git a/drivers/bus/mhi/core/main.c b/drivers/bus/mhi/core/main.c index 69cd9dcde6d8..26bbc812121d 100644 --- a/drivers/bus/mhi/core/main.c +++ b/drivers/bus/mhi/core/main.c @@ -773,11 +773,18 @@ 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); + + 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); + } else { + dev_err(&mhi_cntrl->mhi_dev->dev, + "Completion packet for invalid channel ID: %d\n", chan); + } mhi_del_ring_element(mhi_cntrl, mhi_ring); }