Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1545392rdb; Wed, 31 Jan 2024 01:43:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IFLJ3LNuHkv89w0GsD35+Zm+isxYZUuWFeSrXnnPKQ3C3jhREQOzSKKb9dxKUGNZehEhTBv X-Received: by 2002:a81:a103:0:b0:5fa:564:afad with SMTP id y3-20020a81a103000000b005fa0564afadmr961345ywg.7.1706694196005; Wed, 31 Jan 2024 01:43:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706694195; cv=pass; d=google.com; s=arc-20160816; b=mREhvj6N9r6Vt8zq1NRSEY+LYduUZ39i3PdHbdrUh5z2dJsZ5Z28sI8cWY5O/cqJMm uDDlogNoolpM5/dn4VcnvV8pmlT8Cqmbv6jGH0Sxhch3PygEANITuWtsjpOij4bhbfxF AifXJZQ7y0uNNL0p9Hk6TNOGmkSy9aVRYy8uN834FZWg27GEknlqySbLsRwTHxaXaEAs CrHyyEKp72TR5vkBO4QG10eiP8oqDd1fjzzTcK+M+ZtEqv4QHuNWU6a5xrCOCNZQsTRE 8919ddsHa3+/EYzI5jdN+dXvnK81NbsGLp766YB2YXLNd5cQqgyLkYxfyrU5OllNQFEd FIbg== 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=TN8sUvXkG9tan3zwgK4OGu5R676NcyPOdYBP/KAfGds=; fh=PjhPIOM8gfjKzVCBjCaOXJWJtno9jIBDG/hXM3wHW18=; b=qPR0v6VDJb7cq6QUbFhMHBs1N16L/18q5SB18B/R1urrQXwXVz6lVBUgzuHOmYhJZx 5go3yXtoPFcd4BLSQ8e2OLoXUfhsFqDnLvpD6BrtyY2AAb4mzab67IQz/RGFmfe4DHkK tXmSfeVXsqcerEkojO2SgGpsUaj9Xi9Ox15td8zFHirX4NikP9JZGdNEmb/QYUMxoVLy tFbXOGdhhVA2tHHDfS0UyICzmekOUoXndvIrl275naGzUMSE/4MzfozvqvwyaE8e0Vnm HDkBt2K+PcBLkFwrs3qBYJJ63GJ4C5ORvMgkNr885h92OKKIK+qUYuEkLnzu2UyvQDxK Vhfg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Bq1S3GYN; 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-46155-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46155-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=1; AJvYcCV3v03z+evfWrjKtGKO8ykDdsauhFvZF7vEZvVRiAczC4Gy4PlOngXZ25h/Qinv4xMOnc8VAyTK127zmZfPsxJBbkk+HTKATwIjm5RrNg== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id n11-20020ac85a0b000000b0042bec84a454si311070qta.116.2024.01.31.01.43.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 01:43:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-46155-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=Bq1S3GYN; 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-46155-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46155-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 72AAA1C25035 for ; Wed, 31 Jan 2024 09:43:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0229469944; Wed, 31 Jan 2024 09:43:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="Bq1S3GYN" Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.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 6A0CB67A16; Wed, 31 Jan 2024 09:43:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706694186; cv=none; b=JbYzvTwLBSLmSXX9T4JrBs/eAc7CdbbZ5qHZgpzX6Dqv08JIeZPlH/Z7gx19A4NVxGjDjo4rua9OYDyqevZ/CS88Qf2E3ab/Ku9zNSdQQNQon4HgZ3PsoX3yqdXKGioDCze4XL49tomSbQLBMJ+Vxe16TxFnvQrRyYQ6cYrK4Ys= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706694186; c=relaxed/simple; bh=+3j16HGIZAY4J4ZI60uEGjVzbBn8FpbNDoy1EDVdFHo=; h=From:To:Cc:Subject:Date:Message-Id; b=n5DwC1I0tYuUttP+oN1VPS++PEeDBqO+vAl0aaSyRMQttDr6b77wil4tAGZuO2C6YcP1Ts/tDVI5RTRAdkEluOeh7BxG6IcQrp4X4rG6KlBFFz0M9Mqv2RtKDqsKiQX/15+VrLMjjhwJyf/cyuXs/uQN4d7n3tIFG5SThJCiI+M= 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=Bq1S3GYN; arc=none smtp.client-ip=205.220.168.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 (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 40V80efM016875; Wed, 31 Jan 2024 09:43:00 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=TN8sUvXkG9ta n3zwgK4OGu5R676NcyPOdYBP/KAfGds=; b=Bq1S3GYNNIHG9pXoyO22im1PE6mf JkqGXNMrMJ5cEyJhukntcsP78Zni8m0NMENIQl+VX5SLmBltHpVOe69PhxkYX4oM OTTywGkylxW66kbfrKXKDfXQXNcZU7UKg88BR9JASZwJGO/4fb5cE0e8BPQhZlNf xkxUXf3lUN4SVkSdvEjabRmKs0AsREH+boyjpQmNnItx3lbwB2VSRv92qLv0toCs 1lEIRdiiwT5FJ2h2TAXZa4gUGPXQTEm00WUzxO9+i50TPz53ZjNt4XhheZF1Avg/ pGOlw+ufkTO5jn6MWUFSyfLOF+pjSjBoYQn+OGnQkOohjJzx15yHQW4V6g== 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 3vyjas084k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 31 Jan 2024 09:43:00 +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 40V9guWa008461; Wed, 31 Jan 2024 09:42:56 GMT Received: from pps.reinject (localhost [127.0.0.1]) by APBLRPPMTA01.qualcomm.com (PPS) with ESMTP id 3vvtwmc41r-1; Wed, 31 Jan 2024 09:42:56 +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 40V9gu4s008455; Wed, 31 Jan 2024 09:42:56 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 40V9guun008454; Wed, 31 Jan 2024 09:42:56 +0000 Received: by hu-maiyas-hyd.qualcomm.com (Postfix, from userid 207879) id 876B35001C2; Wed, 31 Jan 2024 15:12:55 +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, Auditya Bhattaram Subject: [PATCH] soc: qcom: mdt_loader: Add Upperbounds check for program header access Date: Wed, 31 Jan 2024 15:12:53 +0530 Message-Id: <20240131094253.20384-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-GUID: KjhyxFA81mRL8g4Csd0T608oga8KSAz5 X-Proofpoint-ORIG-GUID: KjhyxFA81mRL8g4Csd0T608oga8KSAz5 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-01-31_03,2024-01-30_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 priorityscore=1501 lowpriorityscore=0 phishscore=0 mlxscore=0 mlxlogscore=999 suspectscore=0 adultscore=0 bulkscore=0 impostorscore=0 clxscore=1011 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401190000 definitions=main-2401310073 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. Signed-off-by: Auditya Bhattaram --- drivers/soc/qcom/mdt_loader.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/soc/qcom/mdt_loader.c b/drivers/soc/qcom/mdt_loader.c index 6f177e46fa0f..fee86317ad83 100644 --- a/drivers/soc/qcom/mdt_loader.c +++ b/drivers/soc/qcom/mdt_loader.c @@ -145,6 +145,9 @@ 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)) + 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