Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3026030pxj; Mon, 17 May 2021 15:54:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwNUI8IRXPG47ij32Dg32K6ym7Uz26B184RAfNFvGrqUmOmKqLxtpFJgRbWAocSN6Oee/iB X-Received: by 2002:a6b:f21a:: with SMTP id q26mr1842296ioh.152.1621292096237; Mon, 17 May 2021 15:54:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621292096; cv=none; d=google.com; s=arc-20160816; b=BmicyiM8TJZ1nlBt1lqHnCsRUVXiuCZgHIIw2zwYyUiOLWANfWKw6YosPm/E2DF7uL 4Ot910CxTjvU7sN3ppupfMAFylKuhS6CmWx1Vh9O/56G07j1nySOpL9lR2wHwZYiIQZi ceho8XaWi1b14WFqdsBiE5qJoPxJUfLVXfugkxx+Y8E5rSMhrKCnKwUfYqJJkc7swn19 L1RLcFZG5CGgdEFLq/RBWZHle+NSfZ5WGaGzneed3At8dEKdV/ptrlBbSU/dX5sEyovM NTJQGl+NAvKdWtq2lVtN9c7N+tgqOEHC/9LDFIisiRin6WRWCCsWB0Fj2HjigJRLJEHK w3FA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=YyUFyMoxcdFCUdr9Wm3UcY4aZVJaNuJAiCmch4LNkHI=; b=TCrqW4x/+iR+DF1EhbNSBTPHqU54PcD44L7ajPUp2hn+fB6EyKG2nAyY5UiS/5st2u c37DGpl2QpdiZ1c+YYnG9MaF16ZzAzqDICTyR8Okoo65Bz+ZsriC83UR0m/rpscboyB2 ToJHFyWyVtntnWceBFsO1FmrmRyt92xH6/6Z63FPRvV8W7kDvIQ1rToMgDg+686Z8Bs7 fIjcYQbCdStIlGLxmgVmXWrgoLjNM1A6kjBVn+HsbDn++DFpXivcDKLmXoFO4+AhqD07 ReSmilNW47RyUz7+pA0i1ga+RX33vm00x4EtnBXxDpo+6F/I0/0B4J9ZK23HALe+XG2K gIxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QrqnQMcD; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y23si18755208iot.95.2021.05.17.15.54.21; Mon, 17 May 2021 15:54:56 -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=@linuxfoundation.org header.s=korg header.b=QrqnQMcD; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238318AbhEQORf (ORCPT + 99 others); Mon, 17 May 2021 10:17:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:46782 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239043AbhEQOOr (ORCPT ); Mon, 17 May 2021 10:14:47 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 96BE161378; Mon, 17 May 2021 14:09:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621260553; bh=VUshgsG/2RrNZ38dN1n3YOr6lctXxWIjlFzdCAnZNaY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QrqnQMcDHTxSKv5mLU/vEFRo+tMrm3XhbxXOiBoKyWHsokcSB5AjP5kCAkq+VzJ6h KfODrM6zgvFVoSDxV2aFDqgcXZBecNcU/p7tw3x55VmPqiN/7Tbgn0HNFUhr5wgouQ ul9N7fuE3KbqItfYd6grnNKIDv+/+lTQHA7t+atk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mathieu Poirier , Bjorn Andersson , Sasha Levin Subject: [PATCH 5.12 132/363] remoteproc: qcom_q6v5_mss: Validate p_filesz in ELF loader Date: Mon, 17 May 2021 15:59:58 +0200 Message-Id: <20210517140307.084067030@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140302.508966430@linuxfoundation.org> References: <20210517140302.508966430@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bjorn Andersson [ Upstream commit 3d2ee78906af5f08d499d6aa3aa504406fa38106 ] 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. Reviewed-by: Mathieu Poirier Fixes: 135b9e8d1cd8 ("remoteproc: qcom_q6v5_mss: Validate modem blob firmware size before load") Link: https://lore.kernel.org/r/20210312232002.3466791-1-bjorn.andersson@linaro.org Signed-off-by: Bjorn Andersson Signed-off-by: Sasha Levin --- drivers/remoteproc/qcom_q6v5_mss.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/remoteproc/qcom_q6v5_mss.c b/drivers/remoteproc/qcom_q6v5_mss.c index 66106ba25ba3..14e0ce5f18f5 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; + goto release_firmware; + } + ptr = memremap(qproc->mpss_phys + offset, phdr->p_memsz, MEMREMAP_WC); if (!ptr) { dev_err(qproc->dev, @@ -1241,6 +1249,16 @@ 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; + release_firmware(seg_fw); + memunmap(ptr); + goto release_firmware; + } + release_firmware(seg_fw); } -- 2.30.2