Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp849935pxb; Wed, 13 Jan 2021 18:16:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJx9UQ8mMosTzgxAnWxZtaBhozvurLj2IWJAqsc0xKDXsYkBSwcQwPG7tiAYLYGodzg86JEO X-Received: by 2002:a17:906:c349:: with SMTP id ci9mr2552597ejb.198.1610590585369; Wed, 13 Jan 2021 18:16:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610590585; cv=none; d=google.com; s=arc-20160816; b=aPVO92oPgJqlGeyvh92BUnXRwMLu9HbZop+WH3ZrmxY2YPG02XYr80YWWnd8V/jRs9 uorYxbdvYiE75a84h5BQU0FoD+TZUL/Ygj5r/2oNMdMNBo92gCU0DQS6LY9FIipiULWu a4/g8baPYeDVxZrDs/K5eAqYbA9QoIdhQnyXh7vJTOqVjaKpLrVIpfowMPUagHQOZ5Ej SdLRE7nsrvStBJ+8LcRItrK7B7umO5Bdkz+dKm4WJD1DtUQBpfd0ok6MuPjYIFZ0k9GR bs0CmlDlCGxO5Y9K843TJ4BOxKe50l2SmHg/l1K+FFSsLdwlGNfAdxVCC1hUrHCTi4c2 AkQA== 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:dkim-signature; bh=2oVuzEK0sHFjnoocbJw1sqteX5S5UuoEAAdB30o3rmg=; b=EvZSu2ZTOBhyH9NfCWWCTfXC6vggdbXag50INGitS8gMymIlfBJUxKs6EPFbQfujPu L+P6+UxOTLwb0ya+UM78X77Tg20mSSNOCHFkIwNcP+SuZuuBBr2NhvqUBHn+epKMLe+I XDrMPM6XHf3ZgjFxHcvJgYqdu95dn9qn4yVFmCFNzblgeG+BpCm1kVGru/cw8OWRVqNo 7stggwwYl90PY8BdFNj/pM2KmBaOs9xRotMptoa5rQfIQo86UZ7Itrv5yZapdzwYliRP sXvvjWIitmdDOUO8w5rAg584faFym6SyHCsOQOcGsY/MD3oGd1e1UwCgBYrleChquKcM cM4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=t+gXcNaa; 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 h12si1928494ejx.467.2021.01.13.18.16.02; Wed, 13 Jan 2021 18:16:25 -0800 (PST) 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=t+gXcNaa; 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 S1728658AbhANCO5 (ORCPT + 99 others); Wed, 13 Jan 2021 21:14:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729106AbhAMVXy (ORCPT ); Wed, 13 Jan 2021 16:23:54 -0500 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 824A3C061575 for ; Wed, 13 Jan 2021 13:23:00 -0800 (PST) Received: by mail-pf1-x434.google.com with SMTP id b3so2051214pft.3 for ; Wed, 13 Jan 2021 13:23:00 -0800 (PST) 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; bh=2oVuzEK0sHFjnoocbJw1sqteX5S5UuoEAAdB30o3rmg=; b=t+gXcNaa45OlK6+8xH7sItflZVBIhUj34KZPFZWe/JMyLbGnPghaSz/K8BQ4y7Guvr wk+cfVxX+4UJEaPnLuq3i+kANW6mX1qN6RZQBNTO99pDJxtK4i6b7XcJLDwMXZgh4ipO eD2yDQOuniD4PTq9feSqqc5mvmFiZ37hweclA+KmWD42DeMcdlo+hb8luIyfbscoodge mTVQKGIE0xsGiSYAE/VFQIYOswrZrQGxy3qXN5CNp0666Tva2F0GiaAcYRu7oJiTv7Rc 940RCWMVXSQESVs7hvM7R0RUiR2rdYl+GKgjKt6m0/GK7llECaFlNai63pl/KVaOwmSr LVfg== 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; bh=2oVuzEK0sHFjnoocbJw1sqteX5S5UuoEAAdB30o3rmg=; b=Cg0QUUSjZTBYcNq5FzM/UNm0eB5gQyCo4zwXdEFHGDBANUvfA6jT3piVglcVkX9Yvz V3VYz85dsZBPjYzZmB+GNcUuHOnXGooJHNcWMbaIHXqjdugEBPW7oztLBCuQ4KYODCWY jPRP0hAjI6YnCbgiJQmCS5lrM0MaWks6a5jpz5GJKIThrYeWuX3OKOvsSzZQu2anjg2M X9LPFjsK2htwJrE87nNkcXHzJ9acJznP3jZnfMwCjnyEc0EhS/BdmmUmEHLkIDjLxgnr 7LR3r+MSuIW9XNyYsFuZbzr4JAXw7rU8xGhMIVlU+qSUJuxeMnA5tM6c+nns8QVJfyiE gLdg== X-Gm-Message-State: AOAM533gFM2dmrx/pn6MoLg9zmqdk6xPcvFgaSN0jgyGKHtKgC8RSEgI g8dZ6Cbg7neIHpWatlrmToXWKqag0oTAQA== X-Received: by 2002:a63:1322:: with SMTP id i34mr3945492pgl.282.1610572980072; Wed, 13 Jan 2021 13:23:00 -0800 (PST) Received: from xps15 (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id x15sm3284847pfn.118.2021.01.13.13.22.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jan 2021 13:22:59 -0800 (PST) Date: Wed, 13 Jan 2021 14:22:57 -0700 From: Mathieu Poirier To: Bjorn Andersson Cc: Andy Gross , Ohad Ben-Cohen , Sibi Sankar , linux-arm-msm@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] remoteproc: qcom_q6v5_mss: Validate p_filesz in ELF loader Message-ID: <20210113212257.GB229796@xps15> References: <20210107235053.745888-1-bjorn.andersson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210107235053.745888-1-bjorn.andersson@linaro.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Bjorn, On Thu, Jan 07, 2021 at 03:50:53PM -0800, Bjorn Andersson wrote: > Analog to the issue in the common mdt_loader code the MSS ELF loader > does not validate that p_filesz bytes will fit in the memory region and > that the loaded segments are not truncated. Fix this in the same way > as proposed for the mdt_loader. > > Fixes: 135b9e8d1cd8 ("remoteproc: qcom_q6v5_mss: Validate modem blob firmware size before load") > Signed-off-by: Bjorn Andersson > --- > drivers/remoteproc/qcom_q6v5_mss.c | 17 +++++++++++++++++ > 1 file changed, 17 insertions(+) > > diff --git a/drivers/remoteproc/qcom_q6v5_mss.c b/drivers/remoteproc/qcom_q6v5_mss.c > index 66106ba25ba3..2b59e0cbdce1 100644 > --- a/drivers/remoteproc/qcom_q6v5_mss.c > +++ b/drivers/remoteproc/qcom_q6v5_mss.c > @@ -1210,6 +1210,14 @@ static int q6v5_mpss_load(struct q6v5 *qproc) > goto release_firmware; > } > > + if (phdr->p_filesz > phdr->p_memsz) { > + dev_err(qproc->dev, > + "refusing to load segment %d with p_filesz > p_memsz\n", > + i); > + ret = -EINVAL; > + break; Based on the error handling for the above and below conditions, I would have expected a "goto release_firmware" rather than a "break". > + } > + > ptr = memremap(qproc->mpss_phys + offset, phdr->p_memsz, MEMREMAP_WC); > if (!ptr) { > dev_err(qproc->dev, > @@ -1241,6 +1249,15 @@ static int q6v5_mpss_load(struct q6v5 *qproc) > goto release_firmware; > } > > + if (seg_fw->size != phdr->p_filesz) { > + dev_err(qproc->dev, > + "failed to load segment %d from truncated file %s\n", > + i, fw_name); > + ret = -EINVAL; > + memunmap(ptr); > + break; Same here. > + } > + > release_firmware(seg_fw); > } Thanks, Mathieu > > -- > 2.29.2 >