Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp231545rdb; Thu, 8 Feb 2024 04:36:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IFhbA91h1/0WU7odLIUO/xhVDqcSZ9hMENN7QrujTaH/mRs2XbLsT7hJ/SrYmVrnu6Rxyhr X-Received: by 2002:a25:b202:0:b0:dc6:bde1:3e36 with SMTP id i2-20020a25b202000000b00dc6bde13e36mr7311296ybj.45.1707395779348; Thu, 08 Feb 2024 04:36:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707395779; cv=pass; d=google.com; s=arc-20160816; b=PZidwPWqypSaM8BBa0S56m9FJlS+mO9vUmbcATTeKK4XEsx4g1H1izARtkg6Z1Wwbu ePhDfP5DW2CLHv6Srevkbz97Q0eLf1ojgn4Uj5wfOhtiL3nahmzfEoQswaRRN/X9/rp2 xF1vXlkPgKGso9FdzySgUoiG9SC3Ln3LWhx0FvAesS1pVhl814+UZrv4n/ecdgCcepdI RHrM2sHeImCUKAO9efuOErZQaOkNN+Kh/lmq1c/guHaLYnB/IhJ2FtZdaZ+uyyEB6AcY eH7NX3+2XyHSKGnb9O+UeM4brtVdjiAoPOilfFIbdlWXDPyinBP3b/tl5tfb7czZBhqW G7yA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-id:precedence:message-id:date :subject:cc:to:from:dkim-signature; bh=ikMJYK2WAvNNKXWt0Hgg52AE4P+Ye/pJr8QAkUFv0NQ=; fh=NyG2hua7vzVDbm7u594fq6vIRDoWiwaCJ/LNF9ur7DY=; b=UG+xURpNpG/HN3nFcyirh0FzlkfQZlKAY0rumYmpdBMl/yTlvKhW7yJikYNIujoW3X nH656ratcoAKjHvNsVvuVSzsNNo0b1Uw89irnOi3PHJ4rIqaRgCo/X2J3gQCaCkkkNZi vrTHQy8sbr/DO7261K5ve0Y4bBXI7L6xmG+KWQrqJMk11wKVrleJnKXkcnDhbTKaNJzP kRf/klwXgAU+F4AHwWUKwBFy3PbcSUa5IRYcKFmeLg9ExscY0u0ciZpiOcaMOBBNOMIZ 7ecHvbjZTt3NpEHR4f4RPoeplp60CQhGizTl2BMfYUNmS7BU6L+9r0SrOr1Zx+FGzPY1 OKLA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=f8W0zxW0; arc=pass (i=1 spf=pass spfdomain=qualcomm.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-58064-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58064-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCV7+IsFLZiNablQjrz0Qxi1B3NncZf67yeOIGehQsJsHC6mvJZemVzEKoVZa1J0vKPFsGf2mHoRcl2CcN0xsyE/OFXQd9Db4qblnzPZBw== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id g21-20020a05620a40d500b007855eda5446si3540360qko.392.2024.02.08.04.36.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 04:36:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58064-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=f8W0zxW0; arc=pass (i=1 spf=pass spfdomain=qualcomm.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-58064-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58064-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 406451C25DAE for ; Thu, 8 Feb 2024 12:35:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7286E76046; Thu, 8 Feb 2024 12:35:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="f8W0zxW0" Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (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 DB59F1D525; Thu, 8 Feb 2024 12:35:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707395740; cv=none; b=mo9xmzYWM5Mlw+klxu1jm9A3LO+50P+hfHZaVcCuOKd2KyTou2hJerNpuUeDkJ4E26yMJi0mzueqOIsNAHZ4LrWsBI4iXrY55pbAL3tH+aeqwsyl7B0N6mv3WM18yYjAYLRExXz13/ScqQzVOxTqBgyUkZ2ZsUMMEuBAJtP5EkA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707395740; c=relaxed/simple; bh=yfrto/Me4qW2MHQY54SNciFA0kVeMHFuyf7ci+k9tSY=; h=From:To:Cc:Subject:Date:Message-Id; b=rzmIr3h/Ps6SHBp22Nur5Q4qpyrvaVWgESapIXlA82Ox11rwZzGI8z788dVzm+CcKbeCE9gmD4HZ7uwv9kuNXyFX0AL+k0oknR4c3+6S0+GoEfKOBSPjv8wGng1YuKjsg9rY/Cy1fl6b4dXNi9I0Ej1H0JTaRrdF+kPY+Gu01tE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=qualcomm.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=f8W0zxW0; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=qualcomm.com Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 418Akbvd028072; Thu, 8 Feb 2024 12:35:34 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id; s=qcppdkim1; bh=ikMJYK2WAvNN KXWt0Hgg52AE4P+Ye/pJr8QAkUFv0NQ=; b=f8W0zxW08WbA/IprkZBzMd5VuzhS +H15aAaaoFyuRBbGE1QfjXEcyu78EXwkrotzaBLZR2OWZDBTJRS62MNYXZQJap6c Mv0VBajbBOdXDnQ//mHn3bOvQ3xEBvbkKM05CzOPjMqtbyUDYoyECPhoATdji0sN JqTr/bt8PS6IbTgLOCbTzgAu9V8A94vf0nOzaZqV/AIfgrEC1yFkXaqO0wOvCqlr HilALapNQhAgNDwRJPEwfh8mwriUfWSh75iU+UgNkuhphzhNXDotsXWtS6qQ2kFP M0yr8f1QnmafH51pU7RnHcqpP6sDz9NOAxmtQfvhmC0ViAXUPnTwPm4s2A== Received: from apblrppmta01.qualcomm.com (blr-bdr-fw-01_GlobalNAT_AllZones-Outside.qualcomm.com [103.229.18.19]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4pavhcun-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 12:35:34 +0000 (GMT) Received: from pps.filterd (APBLRPPMTA01.qualcomm.com [127.0.0.1]) by APBLRPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTP id 418CZVVs014362; Thu, 8 Feb 2024 12:35:31 GMT Received: from pps.reinject (localhost [127.0.0.1]) by APBLRPPMTA01.qualcomm.com (PPS) with ESMTPS id 3w1ejm9s7a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 08 Feb 2024 12:35:31 +0000 Received: from APBLRPPMTA01.qualcomm.com (APBLRPPMTA01.qualcomm.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 418CZVNP014356; Thu, 8 Feb 2024 12:35:31 GMT Received: from hu-maiyas-hyd.qualcomm.com (hu-audityab-hyd.qualcomm.com [10.147.244.159]) by APBLRPPMTA01.qualcomm.com (PPS) with ESMTP id 418CZUqm014355; Thu, 08 Feb 2024 12:35:31 +0000 Received: by hu-maiyas-hyd.qualcomm.com (Postfix, from userid 207879) id 9BC3E5001CE; Thu, 8 Feb 2024 18:05:29 +0530 (+0530) From: Auditya Bhattaram To: andersson@kernel.org, konrad.dybcio@linaro.org Cc: linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Auditya Bhattaram Subject: [PATCH v3] soc: qcom: mdt_loader: Add Upperbounds check for program header access Date: Thu, 8 Feb 2024 18:05:27 +0530 Message-Id: <20240208123527.19725-1-quic_audityab@quicinc.com> X-Mailer: git-send-email 2.17.1 X-QCInternal: smtphost X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: Z6aUr7cHfi8mP0tq78xzmvJYc9DNKQLd X-Proofpoint-GUID: Z6aUr7cHfi8mP0tq78xzmvJYc9DNKQLd X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-08_03,2024-02-07_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 priorityscore=1501 mlxscore=0 lowpriorityscore=0 malwarescore=0 mlxlogscore=999 phishscore=0 bulkscore=0 adultscore=0 clxscore=1011 suspectscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080066 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: hash_index is evaluated by looping phdrs till QCOM_MDT_TYPE_HASH is found. Add an upperbound check to phdrs to access within elf size. Fixes: 64fb5eb87d58 ("soc: qcom: mdt_loader: Allow hash to reside in any segment") Cc: Signed-off-by: Auditya Bhattaram --- Changes in v3: - Corrected wrong patch versioning in the Subject. - Added error prints for Invalid access. Link to v2 https://lore.kernel.org/linux-arm-msm/9773d189-c896-d5c5-804c-e086c24987b4@quicinc.com/T/#t Link to v1 https://lore.kernel.org/linux-arm-msm/5d7a3b97-d840-4863-91a0-32c1d8e7532f@linaro.org/T/#t --- drivers/soc/qcom/mdt_loader.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/soc/qcom/mdt_loader.c b/drivers/soc/qcom/mdt_loader.c index 6f177e46fa0f..61e2377cc5c3 100644 --- a/drivers/soc/qcom/mdt_loader.c +++ b/drivers/soc/qcom/mdt_loader.c @@ -145,6 +145,11 @@ void *qcom_mdt_read_metadata(const struct firmware *fw, size_t *data_len, if (phdrs[0].p_type == PT_LOAD) return ERR_PTR(-EINVAL); + if (((size_t)(phdrs + ehdr->e_phnum)) > ((size_t)ehdr + fw->size)) { + dev_err(dev, "Invalid phdrs access: %s\n", fw_name); + return ERR_PTR(-EINVAL); + } + for (i = 1; i < ehdr->e_phnum; i++) { if ((phdrs[i].p_flags & QCOM_MDT_TYPE_MASK) == QCOM_MDT_TYPE_HASH) { hash_segment = i; -- 2.17.1