From patchwork Mon May 17 14:00:26 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: 440127 Delivered-To: patch@linaro.org Received: by 2002:a02:7a1b:0:0:0:0:0 with SMTP id a27csp1187230jac; Mon, 17 May 2021 08:23:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzsF64tOKdE7msQNK6P/KxSQDmQ/ro2DUJ+DD0tyIVmNKUpYOt11nYo8yUIi2cGKm3TSGcz X-Received: by 2002:a5d:8c89:: with SMTP id g9mr422097ion.27.1621264938034; Mon, 17 May 2021 08:22:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621264938; cv=none; d=google.com; s=arc-20160816; b=etNpCCHVarlL0wSWWUt7r3CHgHYcJ0RtMMgCDpoWybKs6WoGVV0A18H4vawbZ+PCvc 9Cy82Vq7wDZRrD5SeCHD+jht61nE7AiFkze8BDub0/JR9YcFiqidlRdVt/ZzI2VzJI1S Bv0XTuoc6DJ0nPbj7TOf79Fb0cm1jo8VhoAze2ujd9xkwhAbUlSGDXK2wLjccUeE9diD DN/uUol50lm5i49OEW4pmzdruQ8FP2jTjHB1uYzzz+CozPo4Zlhc6zgyOjhX4nntmeYc WsDeeGWl/g/zaOeYrSLCj02Nn32Xus1YSwnbqMLAqT9H8Ap4psaOx6TFqrnp50yhVhuE JB/g== 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=IGLVqbaNVYKXHYvAqz+9sAihmGYTgeM/Q+JzhS9vsVHpL1nOH/kvSHodRinPUuB08J sS39uLV+PFYbFz5VmHuvg8cu9jSRJ8pMuCvqa9rxAItHahg3vhlLTlvx45ZnLU8g3tyO VpeF7Ca4d5gtmuPi1qUMTY2BLw+60vMdbfI8+RT7e8VI+dvQt+GDaqgXdQi4oYBkxB3V cCLngb6VTzn8idD8enYq4BamEekUq4TH8yQTLi7BxXGdfKoUxAFsLsM10WK8lteSuGd/ pCt4a6Xo0yPAbtPdwwiBEVmE0ke+MuyzQFs+t7SEkS9lxwvWY2xBo5xzKSSMka791WDQ sCXg== 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 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 g10si19122043iow.86.2021.05.17.08.22.17; Mon, 17 May 2021 08:22:18 -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=JeoLwZCY; 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 S241238AbhEQPXX (ORCPT + 12 others); Mon, 17 May 2021 11:23: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 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 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); }