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 163DD26B089; Thu, 13 Feb 2025 15:09:54 +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=1739459394; cv=none; b=g2RoQTO5KI+jbUwZZbTixkIo1hBovDkmpzJnEm7bqHAMKRBYrWRUxNGEQqfOqgeMHbO2mPI5kwb7DTB2vc4NYWMETtIjmeEvfBmPMXdvpWb55Lm6GuLLGzS4dfDBXfwQzQ9bDkh6f7u8jWkjal32k9auqBwCgT9h7cLYrpMpeYU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739459394; c=relaxed/simple; bh=zJO8bd3Ah8T3/24FOhcPnTPIhk7dkBxGMs0XggATT3M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EhBP1n9kcZinUK9H/uNv6tB8z/Gc+K+AqFu0nQoUBe2ozfFog7Lor3hfQTyygzh/D+RBIxDEVMwM2o0lmwzWh1gMXOZ0ZklaMQsTbZj17VXxiGoC6P72jkhgnrF8VdMdK0XAIfIHbhToe3ByhWkNeHC+EJ4zg3gCOlgjfACERxI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Ck24qMI/; 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="Ck24qMI/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 72D2FC4CED1; Thu, 13 Feb 2025 15:09:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1739459393; bh=zJO8bd3Ah8T3/24FOhcPnTPIhk7dkBxGMs0XggATT3M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ck24qMI/ByYmZx16qR+BBr/vJvEF5X1//VXJHuDakMAN99ap/C31UNIVW78wJd+Hb oVJQP2dOgtX+kXh7YvSjO6GxgldmilPmYt5oTw6UjVIHVIK6Tcc0JdTfSA2Wv0DETn Ipr4wGB4zGDYv07mtkCa5GXC2rNqIAd/yNmhBNCU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Stephan Gerhold , Dmitry Baryshkov , Bjorn Andersson Subject: [PATCH 6.13 252/443] soc: qcom: socinfo: Avoid out of bounds read of serial number Date: Thu, 13 Feb 2025 15:26:57 +0100 Message-ID: <20250213142450.340578893@linuxfoundation.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250213142440.609878115@linuxfoundation.org> References: <20250213142440.609878115@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.13-stable review patch. If anyone has any objections, please let me know. ------------------ From: Stephan Gerhold commit 22cf4fae6660b6e1a583a41cbf84e3046ca9ccd0 upstream. On MSM8916 devices, the serial number exposed in sysfs is constant and does not change across individual devices. It's always: db410c:/sys/devices/soc0$ cat serial_number 2644893864 The firmware used on MSM8916 exposes SOCINFO_VERSION(0, 8), which does not have support for the serial_num field in the socinfo struct. There is an existing check to avoid exposing the serial number in that case, but it's not correct: When checking the item_size returned by SMEM, we need to make sure the *end* of the serial_num is within bounds, instead of comparing with the *start* offset. The serial_number currently exposed on MSM8916 devices is just an out of bounds read of whatever comes after the socinfo struct in SMEM. Fix this by changing offsetof() to offsetofend(), so that the size of the field is also taken into account. Cc: stable@vger.kernel.org Fixes: efb448d0a3fc ("soc: qcom: Add socinfo driver") Signed-off-by: Stephan Gerhold Reviewed-by: Dmitry Baryshkov Link: https://lore.kernel.org/r/20241230-qcom-socinfo-serialno-oob-v1-1-9b7a890da3da@linaro.org Signed-off-by: Bjorn Andersson Signed-off-by: Greg Kroah-Hartman --- drivers/soc/qcom/socinfo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/soc/qcom/socinfo.c +++ b/drivers/soc/qcom/socinfo.c @@ -796,7 +796,7 @@ static int qcom_socinfo_probe(struct pla if (!qs->attr.soc_id || !qs->attr.revision) return -ENOMEM; - if (offsetof(struct socinfo, serial_num) <= item_size) { + if (offsetofend(struct socinfo, serial_num) <= item_size) { qs->attr.serial_number = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%u", le32_to_cpu(info->serial_num));