From patchwork Thu May 20 09:19:31 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: 443190 Delivered-To: patch@linaro.org Received: by 2002:a02:7a1b:0:0:0:0:0 with SMTP id a27csp2129821jac; Thu, 20 May 2021 02:54:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzsKsJw4q8JSu0m3KrgUSFwDW1v3FQ49yO4kX5I3TsLn2k8LxqCOmvBsnESq1Ws93ZS7w3I X-Received: by 2002:a6b:f602:: with SMTP id n2mr4714073ioh.174.1621504489579; Thu, 20 May 2021 02:54:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621504489; cv=none; d=google.com; s=arc-20160816; b=ZeqUuE6j7o6NTDahtH2L93AFZFR0E9etsimzDNeapj21qgIF/SK3ER/Y5tQ/60dn6K TO92oBEY3K6hER9ShARgVVDnWeWnnTeTQOnJikt3l3YTDWqUJgBxroi05OM7uhDOzRd+ 5IC/QUDeyACXZ+rWUHTNPgyYM0ibFCxnD0/bGvkpQALX6BFfk0w90HOspXUXa1r0ApbU H6xHLHx0FTL+CEyOvG8PpFKtD2AO3bf28suW11uh6srE+KDx7vo3DLZv0G7oIf/5F4SC a2UKNgCvGjOuUhLqHPtHwamK/qvXl9FeNIQaO7wqVnJqndOSAtnOdJ2SKD5zqjiiUENF hIPA== 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=envoYNI7nsPT9U3kJ8d6KjC4D5coXr0gJbIgMmRkE5Q=; b=jfac7bdUlTkCAClEZP/4vyhbdu4ylJ6hQJlaeacpXKAt4bKdqzDoJj/8ym0QZegqn5 ixChWZItXQ9r7z+SNCwVoK+NY1O1X3q64xI21pa4cQlB9StW+btiODTWazj1DJdTivt0 Bavo1LwvE+2490wADPrjJ4DPhvNNNuKXlVgjtt1yYef2/2AWslqi/yuIMXUNX/3wZeHz biht7aMtEy+gXceA07nPkLqv2TeSS4kHjIWEy4ln9iEJ5bJ4fYRhvYyb7VI+KBaxDeBc wZYPS2sk62sXALYD8kwe86xqrAdUqvys5Bo7+d/dxPK9nPuqZ16IcIWZz/v+wTQLhXhm SwaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LmMahA7f; 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 w36si1802867jal.44.2021.05.20.02.54.49; Thu, 20 May 2021 02:54:49 -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=LmMahA7f; 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 S234352AbhETJ4G (ORCPT + 12 others); Thu, 20 May 2021 05:56:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:53174 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234377AbhETJxr (ORCPT ); Thu, 20 May 2021 05:53:47 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 03E456024A; Thu, 20 May 2021 09:36:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621503396; bh=sSNw2j+udEE3HtCzoKp4Dx5j2tRsVlCX0HNeL2Eb5ZE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LmMahA7fBdz1acBO1Oo+tjiK2mt/XXIfxFUuy92p+AdeA7C1JEzGWQp2KNkjwMRSA sqHrKjTuoHjkYUBZmlqHBiUhRNP0tMiSd0JrZVoU7tKemaitoCSPiSfjogIq0+KgZg utbeNNYge13/V2pmibf0LRVlpfxJof6X3qx85lro= 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.19 202/425] soc: qcom: mdt_loader: Validate that p_filesz < p_memsz Date: Thu, 20 May 2021 11:19:31 +0200 Message-Id: <20210520092138.052707559@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092131.308959589@linuxfoundation.org> References: <20210520092131.308959589@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 1c488024c698..7584b81d06a1 100644 --- a/drivers/soc/qcom/mdt_loader.c +++ b/drivers/soc/qcom/mdt_loader.c @@ -168,6 +168,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) {