Received: by 2002:a05:6520:4211:b029:f4:110d:56bc with SMTP id o17csp2115328lkv; Thu, 20 May 2021 03:46:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyFJpCkHV0eOypZsGO0My5HayiITQhgSXfQ15GCnPz2mKrAcQOBjYSzNm+x5xsTP+UcFsOu X-Received: by 2002:a17:906:6549:: with SMTP id u9mr3946028ejn.506.1621507589430; Thu, 20 May 2021 03:46:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621507589; cv=none; d=google.com; s=arc-20160816; b=PJpZxIx13EjgiHzF38wAUnOcH2LCu+3gGSgpqg3jqXRcahjh4H4cOLPBzPUiukeHVd S/E8a3/IDolDYaeh1zgzLhzx0vkSnEtEpvUCFVJfJghObByyTlMk88Zi4l3yn2TrsgkG y887nUyAGoHVmQlzpn4fnp7dnYSFzQPlzskCpMpbL8ILXe6l5PPIN+kax+NK+rbMZ8Lr dnFdGjw45cO5SCzbgN0YJLWUnh5J4SvSYE9Vj0yv3EtgM82rGnEYsEgGFQ4j/nB1IHkK UKAEltvuabttspMD3Q/RF/XQmwEqbmho6sg2Kg+Oo3HcbzAHOttlLyM0n+5x5LGMqXH4 DgHg== 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=NJqkKbbplRGdgrJxCZIHMUuBIdJs+jPOZg9zzaaFq98=; b=q9/b+/KRBOme+i6zpNQo6dNfYnTSY9qipAEZe3F+F/OeVYb+Zo3is+IhnG/fIAxvWG RmJ7oL0CEy6/IFF543LMaH4Vj64zr0C5abMhyWulr4b4YU+65fEjDpNlbfBuqXGkVAGp CNkZFp06rosaRkhKMp8OzJDVZJClOmn3LyxE0y89sgMPdEOpLi5C4M4I1cZrzlcBXmZz q+tHWJTa5fwzUigGQDckFA48worbo7XDRemB/MzmOrj3vWLbt9RVqyD5B7Z7Co+YjjHr kkuxc3Iux3GkFfa5OkIXLNASUxtAhiNThcTlYP/18IehbV722JDfB9B8myZvYm9ZEb9m W4uA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=PgLEFy7V; 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 nb19si2475394ejc.581.2021.05.20.03.46.04; Thu, 20 May 2021 03:46:29 -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=PgLEFy7V; 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 S237971AbhETKpS (ORCPT + 99 others); Thu, 20 May 2021 06:45:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:60378 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237040AbhETK33 (ORCPT ); Thu, 20 May 2021 06:29:29 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id CF94E61C32; Thu, 20 May 2021 09:51:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621504279; bh=UWOtLWdQXeQzFwHT9Vd1Ir8taV4/nvpEYENR+ttPtHY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PgLEFy7VZxUGeK5zEmw3rDX172YT2li+2FadtLZTtTX0i08LfXxMUijwnlcyTBwA2 Uv0oy3o4LPJouMdfYdIWD50BER3IGVLSfeUBbVQyO+X5h9aWiKYG9C7yuXIE7sXMRz +0i/uHieRO2X8FZBroUvCxBGDddYFxx7EGhN9aeQ= 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 4.14 166/323] soc: qcom: mdt_loader: Validate that p_filesz < p_memsz Date: Thu, 20 May 2021 11:20:58 +0200 Message-Id: <20210520092125.791670717@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092120.115153432@linuxfoundation.org> References: <20210520092120.115153432@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 08bd8549242a..17cba12cdf61 100644 --- a/drivers/soc/qcom/mdt_loader.c +++ b/drivers/soc/qcom/mdt_loader.c @@ -174,6 +174,14 @@ 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) { -- 2.30.2