Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1644783pxf; Fri, 12 Mar 2021 15:21:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJyAT7OvYzMSg2kjejFg2Qm9m80D9JnUPl0M6xHI2evZofBvStbjgOA+sNOoNKTp+6J+ZG+2 X-Received: by 2002:a17:906:a106:: with SMTP id t6mr11332717ejy.63.1615591267858; Fri, 12 Mar 2021 15:21:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615591267; cv=none; d=google.com; s=arc-20160816; b=R1T8IeJ8REWsCcIQk5dnq6GvqSkl71n0emVUGsU+WUkmJkQJQ9HS6zo2CuMJdLv4aH UpFBjZQSJuZajFLmE4gmw6qvf2n0eDcmhcGqS+XuCFYKI3T0HHW0NWHLgldPXwtXWdiG yRvjdPYGFVDlOuEguJ+dOqW7G9p9tjhKx+pmlNyKhFH8hrPOodAq1AF6/VPJciGbKq96 sMuC2As/MaAR0Ma5MAzMBsAeAHdwN/Ama6ab7uY2IW9RMkTQZJfuXtp4/F12BnYnZFU3 li2h+sZ7rnW6KOo/7afW7Z3/TN3QTgHVs+1Ie7BB7nooPHybGH3VyVqZd5QNwUUMTWnx 2DCQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=rqvOzI2zLGFbJ4M0ftg4qd6WsZiHet0rFkxEAgLUmfE=; b=Zc5GIBkWNvy4pMiN8wLW7lxBd2HbnDJPxIsWGP6PrRswwJbxQ+75w7C6eaB22BZUya VENGGGNcNb48b1tqXvHqf0jWdTGaMdWZKbke1TvysGp9F9e0JwMflgKM2HXbwd/UP6ob 2c7d/g9oaV6X7hHZ7JZg0AMreIpEhyG6Gxuuz6N+fjbTmYUrjQJV88uk4GohYeVL7MRD XiK4E0QpBEeHKIXtoxToANoO841+vtGSVkQP8J0PztMRTtcLeWx8c5TNqH3mL5XtTP9p UIg5ILBI0AylHhP1nBwCi6UpZKtTYI6zvF9/XP5JZm0mvCaJR2cgEDQr+7odatErCGx+ PPUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YT6UKyVu; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k19si5157522eja.265.2021.03.12.15.20.45; Fri, 12 Mar 2021 15:21:07 -0800 (PST) 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=@linaro.org header.s=google header.b=YT6UKyVu; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235792AbhCLXTG (ORCPT + 99 others); Fri, 12 Mar 2021 18:19:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235781AbhCLXTB (ORCPT ); Fri, 12 Mar 2021 18:19:01 -0500 Received: from mail-oi1-x234.google.com (mail-oi1-x234.google.com [IPv6:2607:f8b0:4864:20::234]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1965C061761 for ; Fri, 12 Mar 2021 15:19:00 -0800 (PST) Received: by mail-oi1-x234.google.com with SMTP id o22so18798885oic.3 for ; Fri, 12 Mar 2021 15:19:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=rqvOzI2zLGFbJ4M0ftg4qd6WsZiHet0rFkxEAgLUmfE=; b=YT6UKyVuPLm4XGX36k0chID5JVFUTUm8zaC+8n0ONRpoHzG7rrb+CAtxz+dNj1/idI XZQ3hYQwvEsFIZYhB0FlM5dHlIWLS0AgfNLTQpqn08wjRutjktwcT7WWJAnTboSY672l vbmx9Kycbh/EUq+HLiM2n/3rWT6fas3Vn0KBlj1PM9u5QGwn6F1p09hvTB7gWbLESuIC pEfmxn9BGn0UCJXDhkyL/blBVSRPOPoS2a9JtHhLooOGF/8+tY1o+FW1OM3j65u2CIoE VSinbeu0oomzXzf0R+3MAxDWr/F1pCNDlik2l6Df+q7Fj1Wg4v0ScbwfV/S7pLkNjMbL U8Gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=rqvOzI2zLGFbJ4M0ftg4qd6WsZiHet0rFkxEAgLUmfE=; b=kms/6Bc1LiLmv7Yal1jcuoX0bSpUXNnYIViMexNDGBniQfY9hUs53IzuPQm7LqHfaK e4aEpcUUuGQLler6IuO3ZXM0T5JRQeKBJYu3ZU3rjorqGHEMwg8Owr0BxetHjgwuI4ib FXKUyRpsuqjV0ZzC9gKnmdc0243Ae4RSg243HdmxXe5gY+oN5j5w/gcPg9GpJ5nC+Zss YTl0r93I1UHGW63ByfUelyI1YZO71jNBV8LzNa8Nr7ziKrHqDMS/VB3v/gHmTvxs63ky b5CP5a7UJg1rD9q1WfwCONw6ARyUOfW/aBQuZ1dws21yUWy0ZED3644/IzYFU59NDtKI n9ag== X-Gm-Message-State: AOAM533JUqdXglLVNvZPdiDGIVD+dgaJnf/QQQc0zaVVrWegDsARXPZP 2qsXLhBX3iML5NfVOFVuiydo0w== X-Received: by 2002:aca:3cd5:: with SMTP id j204mr11413488oia.29.1615591140160; Fri, 12 Mar 2021 15:19:00 -0800 (PST) Received: from localhost.localdomain (104-57-184-186.lightspeed.austtx.sbcglobal.net. [104.57.184.186]) by smtp.gmail.com with ESMTPSA id a6sm2326663otq.79.2021.03.12.15.18.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 15:18:59 -0800 (PST) From: Bjorn Andersson To: Andy Gross , Bjorn Andersson , Ohad Ben-Cohen , Mathieu Poirier , Sibi Sankar , Siddharth Gupta Cc: linux-arm-msm@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] remoteproc: qcom_q6v5_mss: Validate p_filesz in ELF loader Date: Fri, 12 Mar 2021 15:20:02 -0800 Message-Id: <20210312232002.3466791-1-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Fixes: 135b9e8d1cd8 ("remoteproc: qcom_q6v5_mss: Validate modem blob firmware size before load") Signed-off-by: Bjorn Andersson --- Changes since v1: - Don't just break the loop, goto release_firmware. - Release seg_fw as well. 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 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); } -- 2.29.2