Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp379790pxj; Tue, 18 May 2021 05:36:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwXa6mvuzRMsfZ8lP5MbcbVacjob2adyIz3hCBe3UbAAssUI+ykrEF46W4urvkO5HQoed/t X-Received: by 2002:aa7:dd41:: with SMTP id o1mr6604482edw.361.1621341389423; Tue, 18 May 2021 05:36:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621341389; cv=none; d=google.com; s=arc-20160816; b=WoX6kU1VfMYToe+JbEJS7TK5ejDN0m+ZY/RO9kf2XsIuE/sPc9YRK0zMNJb4cV5m4m 2+wYGSAZnJeQDHFxpfxW5C8DQWK/c/Ll/ymyRAPU3xH/AI71/8SnnQdyL1fEYbQi+OTK h/kv0BaVlropQ9DE0Iv6YPKaVEW2qD25YKsaq9lBl3TM8OdHC2SUeqOytfqcE8tErGvu 06flLc0lcxOtkTLKYHDN/f5Cz24UHBwypKwcTUt2zIaaZ+WspuWb2NMmHssuLSgAvyvU fepfVTs2biK3fwvACOpVetHPCwLkFhvkPRgl0ir/PVmLnOOiLVzeOSRmsYJ0C99ZIqSt 8kXw== 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=KpxKd8JGPTd5+ZRDocGSbM28mS4MsaR/XVxldDhkVdI=; b=L9300qj4htWmXQAv0/Bresz7EQopLvym7X7ZPFASjCd3xXCzxwVr05OVjyETBAPDWJ gSUvkUJs2K5LhTee4mQxe4AAXmytkLuB95QutmsDaUmWYi7GPeR54UFQN/MXPSGyYBzM jfy3Qn33yVIOg7+9+/FeNgUAobrnVIqc7BdN+0rZEMWO48v7QGoQuy39lDfV6vNzNdYs ggCueMH3JV1KWyLUgTvdH3g9DO0CZQ0CzqfjHosx1FpoDdKfkITrfXDG+waslINoj7oF L0+B7eSBizUzI77fE/Pdjd7EMU4JxqykOoJGO9dyL7khq2tT/QB5JyBHV/soOcFb1W85 DcSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JeoLwZCY; 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 a90si18182943edf.408.2021.05.18.05.36.05; Tue, 18 May 2021 05:36: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=JeoLwZCY; 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 S245235AbhEQPeX (ORCPT + 99 others); Mon, 17 May 2021 11:34:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:57662 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244139AbhEQPTS (ORCPT ); Mon, 17 May 2021 11:19:18 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5809661C79; Mon, 17 May 2021 14:33:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621262028; bh=Sdo9KzY1plZ8NIkbs/p9NPagRCERxP5HP7fTwwto9qo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JeoLwZCYf+hjmeKiJl5YF2ynab663jg6UMku+Axjlo3ZfEPW4ptsxZuirw2GU8rvT tnUWZm40jFR65zOQI2e3j/Y4ToC9sEBQFubOIfpQHCbILXQl7nexrLGxCbtuuZ4IZY m5ZyYzia76VjJ9phkEs4GsdNLqSyKIYNnA/owIoc= 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.10 101/289] remoteproc: qcom_q6v5_mss: Validate p_filesz in ELF loader Date: Mon, 17 May 2021 16:00:26 +0200 Message-Id: <20210517140308.584202008@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140305.140529752@linuxfoundation.org> References: <20210517140305.140529752@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 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(+) diff --git a/drivers/remoteproc/qcom_q6v5_mss.c b/drivers/remoteproc/qcom_q6v5_mss.c index 126a9706449a..ebc3e755bcbc 100644 --- a/drivers/remoteproc/qcom_q6v5_mss.c +++ b/drivers/remoteproc/qcom_q6v5_mss.c @@ -1182,6 +1182,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, @@ -1213,6 +1221,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); } -- 2.30.2