From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E3D7265CCD; Tue, 30 Sep 2025 14:52:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759243934; cv=none; b=jvqJd2dHv7gUa6fAS1MrXZgUafkwCLf6s0ORT7fcERSop7AkKjNiBYxPeOi4F9YBBmnaJo4ddm71ahjdcDwE/SStpzMMdVhSZKYqJLuW+45nwoXMSI9A8NDWaxkqbTFpMhwacC5cEOSjGLBS4gd59LKDmP1x0M1Q20LBJduQQEQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759243934; c=relaxed/simple; bh=+VsETWWpp0FCF81YojyfwdwhrP3wI/mlDu9Omwn5C5Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=J20T8SE3W10e/MPjPEepqozNZoIFe12CRjscoaGHtsG0WMdJ+HnOactE7Ve//VdjHcTK69hJiR9Jp1lRtURsNVUFsLB8rOuVEpvnB8R4laj+LHtEhZEDIyIIG5U+/5CIBuPEx3i9Hwxoo7YeBFVCZjlORO4I/feYtauQUNFh73c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=E5RVYQ8c; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="E5RVYQ8c" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C4D29C4CEF0; Tue, 30 Sep 2025 14:52:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1759243934; bh=+VsETWWpp0FCF81YojyfwdwhrP3wI/mlDu9Omwn5C5Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E5RVYQ8cjlpK/QKrZGqVGisUWiuR//+WCImkYtPQjJdFD+Pt2rWNFZjB0D+kYRkaP 7wdtErEk7AAACGRwq2vX7ebQRAfwMvIe+YI+hOi+V66LqWrVvyQsB0/CEc5abowMir VzBnUZjuKME4c5btBk5WfZfjujtHJRd2fhr+HVQs= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Val Packett , Neil Armstrong , Bjorn Andersson , Dmitry Baryshkov , Bjorn Andersson , Yongqin Liu Subject: [PATCH 5.4 29/81] soc: qcom: mdt_loader: Deal with zero e_shentsize Date: Tue, 30 Sep 2025 16:46:31 +0200 Message-ID: <20250930143820.883820292@linuxfoundation.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250930143819.654157320@linuxfoundation.org> References: <20250930143819.654157320@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Bjorn Andersson commit 25daf9af0ac1bf12490b723b5efaf8dcc85980bc upstream. Firmware that doesn't provide section headers leave both e_shentsize and e_shnum 0, which obvious isn't compatible with the newly introduced stricter checks. Make the section-related checks conditional on either of these values being non-zero. Fixes: 9f9967fed9d0 ("soc: qcom: mdt_loader: Ensure we don't read past the ELF header") Reported-by: Val Packett Closes: https://lore.kernel.org/all/ece307c3-7d65-440f-babd-88cf9705b908@packett.cool/ Reported-by: Neil Armstrong Closes: https://lore.kernel.org/all/aec9cd03-6fc2-4dc8-b937-8b7cf7bf4128@linaro.org/ Signed-off-by: Bjorn Andersson Fixes: 9f35ab0e53cc ("soc: qcom: mdt_loader: Fix error return values in mdt_header_valid()") Tested-by: Neil Armstrong # on SM8650-QRD Reviewed-by: Dmitry Baryshkov Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20250730-mdt-loader-shentsize-zero-v1-1-04f43186229c@oss.qualcomm.com Signed-off-by: Bjorn Andersson Cc: Yongqin Liu Signed-off-by: Greg Kroah-Hartman --- drivers/soc/qcom/mdt_loader.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) --- a/drivers/soc/qcom/mdt_loader.c +++ b/drivers/soc/qcom/mdt_loader.c @@ -39,12 +39,14 @@ static bool mdt_header_valid(const struc if (phend > fw->size) return false; - if (ehdr->e_shentsize != sizeof(struct elf32_shdr)) - return false; + if (ehdr->e_shentsize || ehdr->e_shnum) { + if (ehdr->e_shentsize != sizeof(struct elf32_shdr)) + return false; - shend = size_add(size_mul(sizeof(struct elf32_shdr), ehdr->e_shnum), ehdr->e_shoff); - if (shend > fw->size) - return false; + shend = size_add(size_mul(sizeof(struct elf32_shdr), ehdr->e_shnum), ehdr->e_shoff); + if (shend > fw->size) + return false; + } return true; }