Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4600584pxj; Wed, 12 May 2021 09:01:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx6eYeAiwLV1TYpoplYQ633htqHAVXpJjEukG/EgQVP7yRGA4EdZydqZsv/xev3eGImKrBm X-Received: by 2002:a9d:39c2:: with SMTP id y60mr7922952otb.360.1620835290308; Wed, 12 May 2021 09:01:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620835290; cv=none; d=google.com; s=arc-20160816; b=uRU0E+tpCJ/b4piLrbtkL+YwLKo38xC/2b6wIaNQxh0Yod3woBWeJl9TN7Wh1/m7Vd RVS92q9z1Wf49T32Hi67HvSnRWM4jiTTUQ3PyE337chi9SNrQWf0RaD5iSsJAYfvggnh pQn/KOzwPUTLSbBtLk958tQoIFmghjJSDCc/MaDrABrPEfrVRR9pRQ4rYN61ZMeXQaxX DdNIm3WQl3ongzqm045+lYJU2AB9ROHrfXJ2HKbhB9hBmGaI1donLEbFlM66vcRlXj29 jpZNDVXjbB5vmrnkiJziL+DfSvy+pkKZtYE4G2ldjGjgVvcvEz3OQMXeYKwRB8J1KLAq Ks4Q== 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=S3qC9AE/jEWxmNtp7tMEbrOGEDhTodu8xTm2csM4ldY=; b=BZSisGYnxExGtmT3Fmox4AEvol5h0YFgYePUGNITVoG+oI/fs17r64LcW6P8VZJpsg Az9sngFPXy+FhdTT+PkjTH5+pnMRLnC9NV429//bLIhckfgpfw04mJGMHnVc3oapNf+/ o6JytVbydAU7H6+2QTdU8Y7VtJmGEO85S4+ZQVtpp2GkdGKh1kDugayhghZdAg0fB6Eg texnJE3m+xBD7Adz58afiZH4qbPyJRBm+JBPowc5/qnLtsz5a6LKq9xvNa17dBAjwLiS IrCURBq6xYlR28iQvcGJz/KIKK0cGC+X16Lb17wBj86XB0GF93UOt4r5UMTOFNpSgKXX 9k5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=V+3Xhfml; 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 a9si392982oif.124.2021.05.12.09.01.15; Wed, 12 May 2021 09:01:30 -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=V+3Xhfml; 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 S234418AbhELP6M (ORCPT + 99 others); Wed, 12 May 2021 11:58:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:40502 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235455AbhELP2E (ORCPT ); Wed, 12 May 2021 11:28:04 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3DEB861628; Wed, 12 May 2021 15:12:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620832378; bh=xfco83/Vv5h5DsQ/gshP76G6OEa8DgT+NMphR6cfa9A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V+3XhfmlfKOKGiXRB83rOp6oqGff4/Oi17b8I1eMQ/Jp44v4ARniIWcg3JV6bSE3v lfV41tLZ9AMjNVph0ksybaOgdcvXM3entRZ12DqVI/+0rGkYAU46x5LqY13Wuouj5X V3Ivvw5aIvMmrgz9/Q4nYhI/6HD24Hd6PSFTqaDg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sibi Sankar , Bjorn Andersson , Sasha Levin Subject: [PATCH 5.10 221/530] soc: qcom: mdt_loader: Validate that p_filesz < p_memsz Date: Wed, 12 May 2021 16:45:31 +0200 Message-Id: <20210512144827.096695934@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144819.664462530@linuxfoundation.org> References: <20210512144819.664462530@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 84168d1b54e76a1bcb5192991adde5176abe02e3 ] The code validates that segments of p_memsz bytes of a segment will fit in the provided memory region, but does not validate that p_filesz bytes will, which means that an incorrectly crafted ELF header might write beyond the provided memory region. Fixes: 051fb70fd4ea ("remoteproc: qcom: Driver for the self-authenticating Hexagon v5") Reviewed-by: Sibi Sankar Link: https://lore.kernel.org/r/20210107233119.717173-1-bjorn.andersson@linaro.org Signed-off-by: Bjorn Andersson Signed-off-by: Sasha Levin --- drivers/soc/qcom/mdt_loader.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/soc/qcom/mdt_loader.c b/drivers/soc/qcom/mdt_loader.c index 24cd193dec55..2ddaee5ef9cc 100644 --- a/drivers/soc/qcom/mdt_loader.c +++ b/drivers/soc/qcom/mdt_loader.c @@ -230,6 +230,14 @@ static int __qcom_mdt_load(struct device *dev, const struct firmware *fw, break; } + if (phdr->p_filesz > phdr->p_memsz) { + dev_err(dev, + "refusing to load segment %d with p_filesz > p_memsz\n", + i); + ret = -EINVAL; + break; + } + ptr = mem_region + offset; if (phdr->p_filesz && phdr->p_offset < fw->size) { -- 2.30.2