Received: by 2002:a05:7412:2a91:b0:fc:a2b0:25d7 with SMTP id u17csp364407rdh; Tue, 13 Feb 2024 21:42:29 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWQXrh5XTL342uQxO/qM2ML31Pma6XxJmXRZ+C4eZkbDwE4hTm5ia2s7bdXIdrEVx9HGu4rUiqe/aUwOGIE4luftvrq758gFJMBbUZwQA== X-Google-Smtp-Source: AGHT+IFXtTBc5Z5q1dvEJaCCQqZYzSwzVbyBfdkmi5gFEejC13M5oxvKHP8TYud5vNSs4n96jNUt X-Received: by 2002:a05:622a:2d1:b0:42c:7c3d:e20e with SMTP id a17-20020a05622a02d100b0042c7c3de20emr1682698qtx.41.1707889348913; Tue, 13 Feb 2024 21:42:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707889348; cv=pass; d=google.com; s=arc-20160816; b=asq+P3dzyhXXX+3ls7pEi49/+qLBhvf0HXTU2luU8i9+ulIM150IK7korw0wBT49k9 vCTdHQX3KOLU0++X7j4SC7ZTjvlJcYmR9Mfs+VkSG6IzdrutkfAmZGhh9+J8jP6YHSRh ZCHM+qSQYHLLjlA5EOqHXJwE5zhbrIQBsekaviICNIrQ4zUzT/zhZgasbh7R6lCP+oUL km9p+H6fdW4wacG8Mv3HK8iIje6AYsOHPfu8ncSs66YnMbmvhA8IHpbjcXo6rjEdQCtM wgp9VtangEwawnVgjBgJhYDewwnMp2Yq0JTVB8T10AMMafxytoLQyG28+L/+UA2zriN3 fxpw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=zQ15goAr1IMQoMFuqF3VF3rFuoZnlOb+aWFiNsDJbKA=; fh=RmH/365SDZu0UlK/5fkTf6fj6WGg5kUKbmK/NexUN6U=; b=BpSLTmRteLqnOcOYStTZgGFkgIXazU/jiGgFhi/pzzxPCPMBkZTNlM5yDEvUm8ItGN 86k0LNkbe+GL8X0+5KJoT9WpcU3Z7sfymmNFrks3Z9r0Ei1Tc28pLe0npp9kWHQie5hD DZ8lU92ZUO5Fj2y2ko7E5sWNhcwSilnCohxnJy6bWNbMeeWGRyrSCXjLDFVm+5GJ+6P7 ErOC8QRpTD7lsR+YZP1kAZx6lP4XOQdQtJ654GTBARSQJT4ProcsxT6OTjaP5w930xch 0dg8nlzSiIiulj6oVmZobtDFt4fhSK4m39KwmDxxwWwpxgENJ0IsxwqocqWMNzsCVdSk lWlw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=olwoA2tA; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-64756-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64756-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCX23BgQuf9KzbyZGtTpTj7ORQkNusyZB+zoMsYFBNkvs12jcczh1pPnwRmrZpbDPb90httNXiZqmaRT0OwAPxHmVY7lVA3twfzFnXOmtw== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id r13-20020ac8520d000000b0042d345271d8si4389889qtn.11.2024.02.13.21.42.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 21:42:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-64756-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=@kernel.org header.s=k20201202 header.b=olwoA2tA; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-64756-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64756-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 A9CCE1C2408D for ; Wed, 14 Feb 2024 05:42:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7FB3710958; Wed, 14 Feb 2024 05:42:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="olwoA2tA" 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 9726133EA; Wed, 14 Feb 2024 05:42:19 +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=1707889339; cv=none; b=uvJgiwzfmKUZk0bajge/l32k9ZUAFzTyB4If8lHFzGURlEAoXfXEio77pkR40wjKNRH+lunAQKZ4EiY+v47mYjIxHGnr3MiMLChG4QC9CBBofvm3rh9YdgaPLZM6LFjtGW3doyjpGZr32ai/BGOggc0AOPB1DolW23Gbatjdohg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707889339; c=relaxed/simple; bh=4mDh0LX7kjicHsC+/bogzJBPJ1vYaIpsGeKF5S23PFQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=kJisoaT1frzfWLKRuXUkMbUA3b/HXpd9QLgPf7XmDQxSUj/jB/e/lYwsOGAKaqtszfK7BZvYTtZSJnEh9Xlk1Jy+2Rr/F1yQFTL0SYkTdP7vTE9tqcMg3vHrzt15vm0jwecLjf7MfNq0ehnis0uyqocxuVKUYSKSx89Eq1tKNfI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=olwoA2tA; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id B5D31C433F1; Wed, 14 Feb 2024 05:42:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707889339; bh=4mDh0LX7kjicHsC+/bogzJBPJ1vYaIpsGeKF5S23PFQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=olwoA2tAvRitfGmHoVY0DqilINYX9nwBfOyF7olEZcMqx33n0FtBZWIgYQgJCaGxl exJUOUaJzi7Ssc3LMxh6CGIgOZyDtszGRinH1/oD7VING9JhKh5Demig9tCgV4UzH+ 6+zVBaL5wt/3ZYigGrAXeJK7TmLZVHv1VNwolH+c9VTX4CIXpWjP1nuhifk5Ky0UZJ rVujQVWmBoxY6gKOblG88WN2ZJDYWzP2EbFD7aZCpT9N0UVV4sv9e+tSkE0ToAY1vq rx0sNpYOF3pIBRiE9ULnQUmEXcdCsOCZe5VCseayKDQckiijX/y6Axxe20LQg6uNd3 MEDY2FUHMijAg== Date: Tue, 13 Feb 2024 23:42:16 -0600 From: Bjorn Andersson To: Auditya Bhattaram Cc: konrad.dybcio@linaro.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH v4] soc: qcom: mdt_loader: Add Upperbounds check for program header access Message-ID: References: <20240213080010.16924-1-quic_audityab@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240213080010.16924-1-quic_audityab@quicinc.com> On Tue, Feb 13, 2024 at 01:30:10PM +0530, Auditya Bhattaram wrote: > 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. > How is this compatible with what is being observed on SM8450 and implemented in commit 8bd42e2341a7 ("soc: qcom: mdt_loader: Allow hash segment to be split out"? Regards, Bjorn > Fixes: 64fb5eb87d58 ("soc: qcom: mdt_loader: Allow hash to reside in any segment") > Cc: > Signed-off-by: Auditya Bhattaram > Acked-by: Mukesh Ojha > --- > Changes in v4: > - Added additional prints incase of Invalid access. > Link to v3 https://lore.kernel.org/stable/1c91c653-cebe-4407-bdd6-cfc73b64c0fb@quicinc.com > 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 | 7 +++++++ > 1 file changed, 7 insertions(+) > > diff --git a/drivers/soc/qcom/mdt_loader.c b/drivers/soc/qcom/mdt_loader.c > index 6f177e46fa0f..1a79a7bba468 100644 > --- a/drivers/soc/qcom/mdt_loader.c > +++ b/drivers/soc/qcom/mdt_loader.c > @@ -145,6 +143,13 @@ 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 for fw: %s, e_phnum: %u, fw->size: %zu\n", > + fw_name, ehdr->e_phnum, 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 >