Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp170587ybk; Fri, 8 May 2020 22:51:56 -0700 (PDT) X-Google-Smtp-Source: APiQypIAzvUU6wvV1IF/1CYFiitLS24qUcWpj30aZvw00uwQ0ZP1ECXQMiXLh6lmNKHDnfMgab4v X-Received: by 2002:aa7:c606:: with SMTP id h6mr5120919edq.265.1589003515998; Fri, 08 May 2020 22:51:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589003515; cv=none; d=google.com; s=arc-20160816; b=ztzuxBEyyszY6qGDUxhaa4oU+B3H0na2nKylGx4eHhuxYcpVy9UgGj4RO8c1jeo/WE MC3osNgDD9NP+ICaOgEwygqtCtqF0KQNFHFfBq/6UsmljBfCjKCXB3xj5MV/ua5WY8qf 54mWYlsMpu+F2/hPbpePv1zYNZHqT9tpsZz8vlpMPnOrMYYKaIpMPurkp3kjO78XGya0 CAvWKBiyal6hAv3HyPZm5e+/lHAAD+058Xy4WhgrQMWls3D1fpxH4jCmTbi6pSUG2iZM kB3s+ja4uqjDa+bw1g04QAqsRlUF6GYKkpxBZx8SUI1fCKWY3P+jAqJEMr5kyNMEwQWO VOyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=UTsYNNg6/ImkBFmD+Mx+o8hefWjZHqjjHqjvwNd6AaI=; b=HjPf1CdaFpGm4J1dfM953KMG3hxZd7vxvs6bqZtmuknUL+2A6XuUqmVdu1BTvGKbTW R0w/s1dNMNAeiwP3N0B+4h9ZbICZLvAbCVqdgisbUlJhhn2WmrjXUrcLDRBgCfLI0jVV BM2D/nBu5O6HGl+sodpc2O/fmAFU51pWFywP9T0bWkhqfeUGpfmmTFpgpTPfcX8si30O rtRObldxhTuKZlighuWhplBM5oBSpdKP/q56qhRgXbnOjUxMXMgeDX5qdAhKp+c77ze6 rAF7IXfv02sMhVYIR6dqSqIQ+Y7Sm+hTGFWV10zgu2bp+3so9ZnDxr5Jru4TJbrfzdXA Ttgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KWpBbfDN; 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 t24si2160964ejb.144.2020.05.08.22.51.33; Fri, 08 May 2020 22:51:55 -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=KWpBbfDN; 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 S1728952AbgEIFtT (ORCPT + 99 others); Sat, 9 May 2020 01:49:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725820AbgEIFtS (ORCPT ); Sat, 9 May 2020 01:49:18 -0400 Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC692C05BD09 for ; Fri, 8 May 2020 22:49:18 -0700 (PDT) Received: by mail-pl1-x644.google.com with SMTP id z6so1667247plk.10 for ; Fri, 08 May 2020 22:49:18 -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=UTsYNNg6/ImkBFmD+Mx+o8hefWjZHqjjHqjvwNd6AaI=; b=KWpBbfDNThXu0samEeWM29vOiWvpu8bLxOq8vtogPK4chc1jyMzdaIKh2bH3uXnPOJ O1/Z9EivVp8xAYBnw92K8gKiR9Jx97wf7m86eWMtdj91DMsdiV41QkFXwkfpzmaoG0iL ox+ZjcuLM4UJegbJ67vEC8n/GIV3Ilkq5ptfOAnRptAjC94Wk5ATFS0VzKiNz2PtaRtw XNtQt0bVmYUaeVm7KvwzHY3xEzVrCgHVK5xxmk1QlkhLJt7+5XwK9+JfT3BsRoEet2H4 zPYFvlGMT73gmKk7Udha74SQogviTkysjoKmNK9EtzzRumTgUD0oWPr+84HkXuIPLPVr r7ag== 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=UTsYNNg6/ImkBFmD+Mx+o8hefWjZHqjjHqjvwNd6AaI=; b=Bk7x8AAy3i5ryVlDtNohxIKe////4xf8g3vr4PgIFq8FjwjeC403AX9M7Xra+JR26K Mv74AXGpV9D7Y5OiSM4QvdC5dEN7kDwT+8cJrJliHKKWWyUMBaRsk5CUhbSdaWi7pEmy twCxt/6+G/rN0q1mrefk89kTDt3zM+eobGeZU/O6dUTgb8n5f/imp0KxMlhbWaJbdKq7 sTJXIFAVoYQuweSvJdC0eCilWIz2uQp/F7MqLsiPIke43nbl0zuiXNdgd91C+/o5WqRJ 14hdAg5MMBmrv+7MknhKj0TMcbhiTeMJR+S8BGTQLwwfpLNWdI9YdhGpqAgdc5B26Vmy LILQ== X-Gm-Message-State: AGi0PubXBN/Q7hRyKwhY9p8zGSZYVpxbnCvCGiGisbtGRjVNpeA00k8J MRPPYf3xxqn5YVQiY+rNBmkx X-Received: by 2002:a17:90a:8c9:: with SMTP id 9mr9910633pjn.183.1589003358252; Fri, 08 May 2020 22:49:18 -0700 (PDT) Received: from Mani-XPS-13-9360 ([2409:4072:6e0c:55d2:2cb4:da01:ad1e:6ad9]) by smtp.gmail.com with ESMTPSA id gv7sm3824144pjb.16.2020.05.08.22.49.14 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 08 May 2020 22:49:17 -0700 (PDT) Date: Sat, 9 May 2020 11:19:11 +0530 From: Manivannan Sadhasivam To: Bhaumik Bhatt Cc: linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, hemantk@codeaurora.org, jhugo@codeaurora.org Subject: Re: [PATCH v7 4/8] bus: mhi: core: Read transfer length from an event properly Message-ID: <20200509054911.GD5845@Mani-XPS-13-9360> References: <1588991208-26928-1-git-send-email-bbhatt@codeaurora.org> <1588991208-26928-5-git-send-email-bbhatt@codeaurora.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1588991208-26928-5-git-send-email-bbhatt@codeaurora.org> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 08, 2020 at 07:26:44PM -0700, Bhaumik Bhatt wrote: > From: Hemant Kumar > > When MHI Driver receives an EOT event, it reads xfer_len from the > event in the last TRE. The value is under control of the MHI device > and never validated by Host MHI driver. The value should never be > larger than the real size of the buffer but a malicious device can > set the value 0xFFFF as maximum. This causes driver to memory > overflow (both read or write). Fix this issue by reading minimum of > transfer length from event and the buffer length provided. > > Signed-off-by: Hemant Kumar > Signed-off-by: Bhaumik Bhatt > Reviewed-by: Jeffrey Hugo Reviewed-by: Manivannan Sadhasivam Thanks, Mani > --- > drivers/bus/mhi/core/main.c | 9 +++++++-- > 1 file changed, 7 insertions(+), 2 deletions(-) > > diff --git a/drivers/bus/mhi/core/main.c b/drivers/bus/mhi/core/main.c > index 30798ec..6a80666 100644 > --- a/drivers/bus/mhi/core/main.c > +++ b/drivers/bus/mhi/core/main.c > @@ -514,7 +514,10 @@ static int parse_xfer_event(struct mhi_controller *mhi_cntrl, > mhi_cntrl->unmap_single(mhi_cntrl, buf_info); > > result.buf_addr = buf_info->cb_buf; > - result.bytes_xferd = xfer_len; > + > + /* truncate to buf len if xfer_len is larger */ > + result.bytes_xferd = > + min_t(u16, xfer_len, buf_info->len); > mhi_del_ring_element(mhi_cntrl, buf_ring); > mhi_del_ring_element(mhi_cntrl, tre_ring); > local_rp = tre_ring->rp; > @@ -598,7 +601,9 @@ static int parse_rsc_event(struct mhi_controller *mhi_cntrl, > > result.transaction_status = (ev_code == MHI_EV_CC_OVERFLOW) ? > -EOVERFLOW : 0; > - result.bytes_xferd = xfer_len; > + > + /* truncate to buf len if xfer_len is larger */ > + result.bytes_xferd = min_t(u16, xfer_len, buf_info->len); > result.buf_addr = buf_info->cb_buf; > result.dir = mhi_chan->dir; > > -- > The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, > a Linux Foundation Collaborative Project