From patchwork Wed May 12 14:45:29 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: 435597 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp5007532jao; Wed, 12 May 2021 09:56:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyuau+618vQ8RUOXWW7Il4x8FCXs91MCyoEUjbE/c2GZWETIJDnRrAiP89htoKKSnW34L+j X-Received: by 2002:a05:6e02:118f:: with SMTP id y15mr6150388ili.52.1620838574446; Wed, 12 May 2021 09:56:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620838574; cv=none; d=google.com; s=arc-20160816; b=rxFn7fYlNq6N+azkOlswZhwqdcwkI/s2ZNDYrEk2Q+oWxr2Vn0C8PsqW1i7NbtiUG2 Qo1pzR9zK+iGN3x0wFuUT6aQWWxTr+/gVO8JetIPSTHG3xwQL1x46hcYd9BNFor0Bb7p kmfOtxL6R3J7SK6yQ7VxBsZadNqP46BgxyBc9Jj3FIJw9MMiRfJgaXRyWRnjijSuL2Kh YvlkIeQL+8qD9TlKwvBK8ONjZFevJ3Op9hr+VDe4IwPG1aMUJtY1gNuIqVmUq4KUZTSc OG8K2B0EhaHBveLf6iJdaS+EcoLd1nqmtiRJ5GTxRUS7/XTUTarAhViPccDNTtweN5f8 eBwA== 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=yivijBSNcAV1ljJw+OttZ4jUnEc2t1xyzM5wpdWVI9vxjfq6c2ruKk/DgxibA29IBA PcySj8scbcr3NTsn2qF/aGP8YJJ2pqfwm+E3a8oJ5bE0cMInPhjW2ObEWSYSK0nxacfh MOeg4y7I3tDShFqZHNrkoOlONiVcxeWq8S817tkeZNORbaCf1mKJe0cN5yZJ0D13EV4V aEWdH2jCFW3o7zfSkJkKJXn/QAmCQ4PWdrFJvQKXkH7P7vcoBJEyq3ZeH8BN2APXqt/C lBB8hrBvrXgQwWU0Qjk6nnEMBSxXzQyGNEkDx1SDYU7QtHT3wSplSt2xGAQ+9coFVS30 p4JA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Y12oAs8z; 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 q8si330223ior.12.2021.05.12.09.56.14; Wed, 12 May 2021 09:56:14 -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=Y12oAs8z; 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 S231902AbhELQLU (ORCPT + 12 others); Wed, 12 May 2021 12:11:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:53310 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238697AbhELQGC (ORCPT ); Wed, 12 May 2021 12:06:02 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id ADD5261990; Wed, 12 May 2021 15:34:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620833699; bh=xfco83/Vv5h5DsQ/gshP76G6OEa8DgT+NMphR6cfa9A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y12oAs8zV/Egc3cyfd5nMuAWUu8YteUbcKkqkhJb7PDHkgUNK5K8P/C8WJHLkh48f hs9VtP4CQoUsJlM8Uc0j6JjHyw3lLr+QLIGl0JN0YdXerX6IJOVghplWG/l2fDwrcm GanFiEAD8FoDAIiIQ6enDT5DTuLI0RSD5vStypc0= 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.11 252/601] soc: qcom: mdt_loader: Validate that p_filesz < p_memsz Date: Wed, 12 May 2021 16:45:29 +0200 Message-Id: <20210512144836.124867269@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144827.811958675@linuxfoundation.org> References: <20210512144827.811958675@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 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) {