Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2490034lqp; Sun, 24 Mar 2024 23:17:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXhB1rF8d7uG4mS7s3o5WtxY8fCzuK64haBVHJrqEy+hoGOTBUJoPCVCAoCSABeRvTH9aWpvm1TwlSdPzAVHFuCQc6ZYdF0nnz+vrX+fA== X-Google-Smtp-Source: AGHT+IHeZo166s4WvadkGI4NRHbOXz0fZN7/WdAKwb8mBj9UaIu+DELKa/HMTia1Oa1BSO0cV+lv X-Received: by 2002:a05:6808:2f0d:b0:3c2:aaa4:a6f7 with SMTP id gu13-20020a0568082f0d00b003c2aaa4a6f7mr8908413oib.24.1711347475396; Sun, 24 Mar 2024 23:17:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711347475; cv=pass; d=google.com; s=arc-20160816; b=pTtVSdWd39RW7rkPrQ9Vqtj2IDNDFROFcoAXWXlWR1H5UQWyMXd+qPap17yejnyPiA ZZxnfWLsUvvnV7jND3mGbCyY6YPMW+ejU65zNbVgqGKMAhd+VSzS7hbO/5OAI4ugD+e6 SH6lf+U7F/t0pgA3Icr0eVsPUFrShly4jsHmPuXkonWVZR9Nee1nb+JRReahSjxGEvlK vS0RcVvesYRgdiub5pia/Y4XTV2XuToKbZ1yV8ioRKRb5pqYbk2IqK2VdIN8lIinBB+y 8Rng+O0gKYn9LaoJE4gNdImWYoMkTEGXf/xFse7zAU6sOxI+OWDXZNVRZF2nB2il/AM/ 5Hcg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=ADwF7pQv04LbjnR/FRFu73IvyN9dWTfxXt5KUNatz1g=; fh=BlFRI6UyI6n9MOjrgleffrjRNXt83ywP5vl8tlIPTmc=; b=jvLm/1/ATAqCEos2uLPtvsoIwaQdnAzXVyWYrkCcDCIvysrlFc8d2eXDV2Z27Y+mvm 8R/aoRo2KMd8mfbXVdqkxrKIKnS+wVDB8yz7r1ZxEWhhqBCccNLrhv8swoeCDui2qt3E 5OrS+fQmfcH5ljx2sOEufpqA+LQBDMuzUXDq4kTYtodg+jat6WKZCQzTrMHATE19rgbx 5hACrlQavGc0GRVLHqB7Hapfsrd/+17ZPl7iLnjloZ5nwCDqA9VxL8XimZdOIXkpNz/s zujpChNamldZvjy+/sZlI/xu4OGhKiXpHcErRf4S8tmQLe7B+4xmR08YHEwnoI73x7o7 uNhA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TOBfIDDm; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-114569-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-114569-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id x23-20020a631717000000b005dc48e561adsi6846694pgl.20.2024.03.24.23.17.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 23:17:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-114569-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TOBfIDDm; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-114569-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-114569-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id F08B428CDC8 for ; Mon, 25 Mar 2024 06:17:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 95F7A22F4F9; Sun, 24 Mar 2024 23:52:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TOBfIDDm" 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 A503122F8D0; Sun, 24 Mar 2024 23:16:53 +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=1711322214; cv=none; b=tnh3fn5Abl5g39QonZAi6UHpk1kh+h7lKqCwG7xHN9glsEa0anl+FLJmIZulCFQc7x5+xJB/NzWkQic0aTuVFbnLolU53x5RgzEk9IK3bd12EcZGOfK6EeJTSXw7ZV8xdIfR/XSG4wfb74pPP0WdJ9MMjWLwdotmNi0vly9OcxU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711322214; c=relaxed/simple; bh=BUaEXJZUG8etbIU7z42ZW4ULk/Wh+ZSN13xgmYO0WqQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JNqoiyPW7+QEMHlFWmN9jBdRIf+EsAq3hScvW8qHqO6jdjYv6KAsaPr6yHEk22Ef3O0/Oo+sNsDqoaRAIzFKLOXyas8GES1sW6HJ6XFLxApk8DC9InjLrupkiFtgao5hCYYFgCdtiFJriFsWYpFcNI9FeLrrA4ERj+aDuhKfm6A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TOBfIDDm; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id DFE95C433F1; Sun, 24 Mar 2024 23:16:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711322213; bh=BUaEXJZUG8etbIU7z42ZW4ULk/Wh+ZSN13xgmYO0WqQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TOBfIDDm8Z/KEyAQW1sVlj50TAVNSv6Rh1uK4msq7A7MY8nY5v+XQOTlIUvSqGkVa 5c4Vvnmet65xeZvpomL23RgPLWDK3sbAi/jPm2RZK5rN83ZIuyblaWA+rqwYRHOKHU Uc/ygwo6GBRVhwIOe1Dq5gM4T5y43MjaZHiUHknIRUDFsv05ptEYCLRAxfIIxVROFP Xgz22LHNT3+CKxLyls2To1957wnwA/Il1r3D9v6QY+6+7l/GSU096IjzMbkXP95sUv uUNELb1n2Veq1KjKW1FmDV+8tbn9fUMPopE0VQo2OlJjUxR0NLrvs8HoN/FG4mXGZX 3rdXoXWbXiLxQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Dan Carpenter , Mark Brown , Sasha Levin Subject: [PATCH 6.1 293/451] ASoC: SOF: Add some bounds checking to firmware data Date: Sun, 24 Mar 2024 19:09:29 -0400 Message-ID: <20240324231207.1351418-294-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324231207.1351418-1-sashal@kernel.org> References: <20240324231207.1351418-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Dan Carpenter [ Upstream commit 98f681b0f84cfc3a1d83287b77697679e0398306 ] Smatch complains about "head->full_size - head->header_size" can underflow. To some extent, we're always going to have to trust the firmware a bit. However, it's easy enough to add a check for negatives, and let's add a upper bounds check as well. Fixes: d2458baa799f ("ASoC: SOF: ipc3-loader: Implement firmware parsing and loading") Signed-off-by: Dan Carpenter Link: https://msgid.link/r/5593d147-058c-4de3-a6f5-540ecb96f6f8@moroto.mountain Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- sound/soc/sof/ipc3-loader.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sound/soc/sof/ipc3-loader.c b/sound/soc/sof/ipc3-loader.c index 28218766d2114..6e3ef06721106 100644 --- a/sound/soc/sof/ipc3-loader.c +++ b/sound/soc/sof/ipc3-loader.c @@ -148,6 +148,8 @@ static size_t sof_ipc3_fw_parse_ext_man(struct snd_sof_dev *sdev) head = (struct sof_ext_man_header *)fw->data; remaining = head->full_size - head->header_size; + if (remaining < 0 || remaining > sdev->basefw.fw->size) + return -EINVAL; ext_man_size = ipc3_fw_ext_man_size(sdev, fw); /* Assert firmware starts with extended manifest */ -- 2.43.0