From patchwork Mon May 17 14:00: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: 440119 Delivered-To: patch@linaro.org Received: by 2002:a02:7a1b:0:0:0:0:0 with SMTP id a27csp1163819jac; Mon, 17 May 2021 07:57:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy41U1Xn2lPCmokkG8po7dVNKLAZDJ47N9G6YlMK35rAaIZBxQ1ocErU5R3yuleq+FlvfXO X-Received: by 2002:a6b:6d0e:: with SMTP id a14mr354670iod.40.1621263425985; Mon, 17 May 2021 07:57:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621263425; cv=none; d=google.com; s=arc-20160816; b=IhKHyvcrrraIAgUGWTB82J9BX9vHaT0NQVvrP9sLEKnKKRpNbAVCRAcjC3TQIq1VSD oTYT+QlkPWFKlp5M5dRi5U3T9tkH9l0j4P8k2LId27YYGOqmzi+TdiVIm/iCw9pSisAm OunNoTp021nRqdYiH/jEm3wfUuXiXV1xrZW25BSRE0Mj6zQIe/Ryy/PQDB/kRA3bkJae Lofb4dPrIAltlnrHsoccH1AqcjKATUNz0E2UbghrDVSFVfT7U/pFygCgkkHmN2JMHFva 87WUQqmoVo7Ut1QhsW42FtshRMYDrQIg0b3Gm5dZZ7N2qWZYiKHdrngEcZY1+egc8OMq 039A== 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=YyUFyMoxcdFCUdr9Wm3UcY4aZVJaNuJAiCmch4LNkHI=; b=S92tHQ0vPtx15H+yT5aDnc11lkUdxMB5JbkqfYXE6e4qfYUXeqW2kan5epMClG7V6S mmpOcF/BecnFsCwXBOG58X2LvzjF3237UqoCRmYwtcMXaulYyARzI98/iFLBhJoQDTgl b0Ea0Fswyi7+SaoA5IKIxxdvXnlN2kXQmVQDV/zQmuR8nNgAb/iDjTohQN6EdHSy6B/Q JR8HlwzqVHkcg+PpwVoliOh47IrLhn/NSU6StoJi3Yxkj4q6VY/G2bHSjwnrAc1MVIFZ 4ua7mP7y82XZIzs+o+PCWogCBp3cmo9fvNT3bGuK6bh0vtWaTazpV9shYh3/3/Cmx09I LHrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=AVEQvCsb; 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 u10si5255177jad.109.2021.05.17.07.57.05; Mon, 17 May 2021 07:57:05 -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=AVEQvCsb; 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 S240735AbhEQO6T (ORCPT + 12 others); Mon, 17 May 2021 10:58:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:48048 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240830AbhEQOz6 (ORCPT ); Mon, 17 May 2021 10:55:58 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id DD7BF61996; Mon, 17 May 2021 14:25:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621261510; bh=VUshgsG/2RrNZ38dN1n3YOr6lctXxWIjlFzdCAnZNaY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AVEQvCsbGj/MEjuuf9CqIZ9cGg/81JjyXX2PuLDuM02G9ClDPrsLTPGKvH6QQCGee gazfVm0x40RE8XaFeRVfbIfonZEoaAJ1E9TDENzNOvbdg3dEYJMUoPnqiSMaxfuO0G xRqEEhufRmPOvlqm8hIJ92+YJNF+cFO++ua8MFHk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mathieu Poirier , Bjorn Andersson , Sasha Levin Subject: [PATCH 5.11 118/329] remoteproc: qcom_q6v5_mss: Validate p_filesz in ELF loader Date: Mon, 17 May 2021 16:00:29 +0200 Message-Id: <20210517140306.097026674@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140302.043055203@linuxfoundation.org> References: <20210517140302.043055203@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 3d2ee78906af5f08d499d6aa3aa504406fa38106 ] Analog to the issue in the common mdt_loader code the MSS ELF loader does not validate that p_filesz bytes will fit in the memory region and that the loaded segments are not truncated. Fix this in the same way as proposed for the mdt_loader. Reviewed-by: Mathieu Poirier Fixes: 135b9e8d1cd8 ("remoteproc: qcom_q6v5_mss: Validate modem blob firmware size before load") Link: https://lore.kernel.org/r/20210312232002.3466791-1-bjorn.andersson@linaro.org Signed-off-by: Bjorn Andersson Signed-off-by: Sasha Levin --- drivers/remoteproc/qcom_q6v5_mss.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) -- 2.30.2 diff --git a/drivers/remoteproc/qcom_q6v5_mss.c b/drivers/remoteproc/qcom_q6v5_mss.c index 66106ba25ba3..14e0ce5f18f5 100644 --- a/drivers/remoteproc/qcom_q6v5_mss.c +++ b/drivers/remoteproc/qcom_q6v5_mss.c @@ -1210,6 +1210,14 @@ static int q6v5_mpss_load(struct q6v5 *qproc) goto release_firmware; } + if (phdr->p_filesz > phdr->p_memsz) { + dev_err(qproc->dev, + "refusing to load segment %d with p_filesz > p_memsz\n", + i); + ret = -EINVAL; + goto release_firmware; + } + ptr = memremap(qproc->mpss_phys + offset, phdr->p_memsz, MEMREMAP_WC); if (!ptr) { dev_err(qproc->dev, @@ -1241,6 +1249,16 @@ static int q6v5_mpss_load(struct q6v5 *qproc) goto release_firmware; } + if (seg_fw->size != phdr->p_filesz) { + dev_err(qproc->dev, + "failed to load segment %d from truncated file %s\n", + i, fw_name); + ret = -EINVAL; + release_firmware(seg_fw); + memunmap(ptr); + goto release_firmware; + } + release_firmware(seg_fw); }