Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2876704pxb; Tue, 19 Jan 2021 08:10:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJxjCawUMuEC7G+wVnXcNpUc9/bJC4H+466OJP3q0lFooiaFgfnA36Z13HEbK7aquHrqKJSV X-Received: by 2002:a05:6402:2288:: with SMTP id cw8mr3923905edb.161.1611072657217; Tue, 19 Jan 2021 08:10:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611072657; cv=none; d=google.com; s=arc-20160816; b=UTIm/YryATPCzVT1kPO+g5TkeBefGyhze9jZCwVRvH+B2uKqVetL7ReZ9dSeq0Y/Wk 8TbIJkUsoMwB3IpXGrWvkN3x6Ht2mEpUX+el52zggnsOFWUYwjL4yGmLvYgKFw2mdlHX 07apBVPQln6g6V6QOZdsorioaRUPurjhSxH1Yiw0/IbWYpRYIYA+2wWLlAzRxH+0Qphz ag3RBij6UOAdcp9J4NnjmQ3jV74oLTOh8z5aC6mCyjtF64T6E/FoKL0C7KE5nOya56nB L62+QEtyn+/Nxouth+u6tpHsiG8hb8UEooGCsXJlM1+YokLrI1CnTqIk/vC+nb7Gk0LP oOuw== 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=OfkbJmLEDMRVH6PYECwDZwfn1Ald5phcm9+IMsNfgVA=; b=O5wHBMFp/T0dEcq3io3DUNWdiiQ9uaAqgxtnOhkOgnJcGHSknpZbUTk9SoZrlcYu7b ZoyhFxM/BFM6446iyuFo9JtmTCq+XwaF+u4uIGnN7aYNV61n+JU6aKGx1oGOR8MHCPH5 H6wgRqpsF+00CFLPQ+xBrYhzDVvLukC5hjo1n1/u8vfE9uTKNoED1BZ4qmNhgtXK/W5I JC63Ep/eqZ8mTbG9BwU2TN57/fusDH0UmNazIXexL79mfR6w4aYhCo5Q+sqEDYx7Yc9K 4BGAIRyg5HV7lDRkuGEVw/pqOkU2xQSJ5uPecAwMiyL7dOogWnL891nzDAlnQ1GwMTv4 A3kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ovffRAkU; 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 dv5si1438157ejb.231.2021.01.19.08.10.33; Tue, 19 Jan 2021 08:10:57 -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=ovffRAkU; 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 S2389567AbhASQJF (ORCPT + 99 others); Tue, 19 Jan 2021 11:09:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391616AbhASP5q (ORCPT ); Tue, 19 Jan 2021 10:57:46 -0500 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87A8EC061574 for ; Tue, 19 Jan 2021 07:57:06 -0800 (PST) Received: by mail-pl1-x632.google.com with SMTP id u11so6455579plg.13 for ; Tue, 19 Jan 2021 07:57:06 -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=OfkbJmLEDMRVH6PYECwDZwfn1Ald5phcm9+IMsNfgVA=; b=ovffRAkUEoLiq26/mhqXNH3l2nM6/RE9NSJyW8xFHWLYtXGwT32AC4K5dn+7/ak5+8 wkQAVCzk3M3yMAxumcr22LbfC43FjuS41NFTdb8z9rRzOxJfUM2XxbJCv5dV8kVsTut/ Asxg1oAui4F9crmG5BO3QT+G3oMnbSN27rzXZw4p7/Z6PJLOZIgtrNtiBUQrhJOXb99D lclr0Is/CPUkEq+KpDOf0LkbCGsshPMf337aUtY6gwgLnilOJDGJe9svQ18GNjNGyO5Z XMOj8/jHCDj69V5TaoHIpjww/0+WHJOsFDXgDCUf8cenDXVJsIQxhr9Lj5feYWy4DmpW Rk9A== 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=OfkbJmLEDMRVH6PYECwDZwfn1Ald5phcm9+IMsNfgVA=; b=qJCLn5duH6UXS9CnZ0TC0cfLt5mrjuv58OjhGAD12U16Yctsc/k/7iHuyythhDvCia U8GSZwcekS1xV/YBYF6dyPo5pwlL2zYlQ3CS/FCQf27oehgNTlKhHkBfsOqPYNm5wA0T hioBKGxIA05MelO1yCnT4z1bMS09zMk5YvwBafdm+5uJ8ft3rLqHMrMUwl09iVOFM9RS /MJoDL7Ycgrh+PACh+ddBZqE7rMO9ksyk4u3wlge0atFGB/kpxVmC4Mc70siDX77pWX6 nGUrbwUEhdpuPnvsj4h6D+lCa1cmmhgq4BUltGd7hnUnwqzZh5ySDpbIg4ZFzaqg/ZzL 8WPg== X-Gm-Message-State: AOAM533N58VOCoIpERi9nbLLukWpsXEFnx+FEkABWsQ6cE6SqaXIe2VI 7ddZUQt90TFm4hQuBcPX2kpE9A== X-Received: by 2002:a17:90b:33c4:: with SMTP id lk4mr315096pjb.157.1611071825991; Tue, 19 Jan 2021 07:57:05 -0800 (PST) Received: from xps15 (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id z29sm2415343pfk.67.2021.01.19.07.57.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Jan 2021 07:57:05 -0800 (PST) Date: Tue, 19 Jan 2021 08:57:03 -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: <20210119155703.GA611676@xps15> References: <20210107235053.745888-1-bjorn.andersson@linaro.org> <20210113212257.GB229796@xps15> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 13, 2021 at 04:03:59PM -0600, Bjorn Andersson wrote: > On Wed 13 Jan 15:22 CST 2021, Mathieu Poirier wrote: > > > 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". > > > > You're certainly right! > > Yet another reason for the duplication between this function, the > mdt_loader and the remoteproc_elf_loader is a bad idea - still not sure > how to refactor any one of them to fit the three. I feel the same way about duplication. On the flip side I don't think we have to take immediate action... The solution will come out at some point when there is more convergence. At least we know it is an area that needs attention. > > Thank you, > Bjorn > > > > + } > > > + > > > 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 > > >