From patchwork Thu May 20 09:20:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 443207 Delivered-To: patch@linaro.org Received: by 2002:a02:7a1b:0:0:0:0:0 with SMTP id a27csp2156573jac; Thu, 20 May 2021 03:30:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyxZrT7RE+jTuNRzGXCnqZo0p5KzBqd6t4dYqTBVBibqKwAf9IUhG6AqOpQY537GyqmZyXO X-Received: by 2002:a92:c205:: with SMTP id j5mr4315669ilo.1.1621506615245; Thu, 20 May 2021 03:30:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621506615; cv=none; d=google.com; s=arc-20160816; b=gfEuN0X8FNnWxTBQobnV+MGvkI1vAusmbToAEo8UZ2xucsLyltQ3Fk9K9vXxzkqi0f XlHzcIFLdkgnwujrpf+CPDvGhuPb+HCQvuoCH7y1eJyNao3Smb1sPIssXGShqAxD8gKX L7+E6bRzi7UReo39eaBF6Zi98SZofQhxCgyPWGkPKQ0x5+s67s2g7fTc0SNmtsUKwj06 XMensbnOGV5Uk3EBz9X2l7KH5I0BW2M5b1uHXuE5G29+ycFY4DautQi2IOPX0cSoFAel +msaI/PKGSjiuj3sRuyeGmO5okyW8qjBPPr/9JpoziHKmFDye8jHF45+Ry6BTamJC5eZ KD5g== 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=bIHSf1FcMPHGcCXeHhgqSCL2a0U/dQN+q28WOLD/Ied+tqTAvassHBandlWRgSCOlO I37BmvDTB3QRlb+UZGO6DwO7TNrgQQH9rrwsYWeJ6ldOakOt4BVO+DQ47X1HPTKyTBhd sEnaBUfv9zukTmqBAhRKdA0A3+qPd9zSuZyP2wU02goXB/p+BoumU98DEobWfVTTjnqO 68Qovn7vdjMHSLfTCF4SfJz/uvDvpU4mOynJRhUkGwd+1KmzdexXU6kfC76hTmjbn0hR +rwAS8egY7hA3GDWXR7tftHLK9NNmijsKcXEvD6I7mzCiobW/kZSPzogKdpT0ywEiqpV 6+Wg== 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 stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-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 u8si155192iol.18.2021.05.20.03.30.14; Thu, 20 May 2021 03:30:15 -0700 (PDT) Received-SPF: pass (google.com: domain of stable-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 stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-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 S237300AbhETKbd (ORCPT + 12 others); Thu, 20 May 2021 06:31:33 -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 Precedence: bulk List-ID: X-Mailing-List: stable@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(+) -- 2.30.2 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) {