From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796383855; b=fxLmPBqhGD2189npV/9ndjzYsnAUABY0awZECcEwtasb1TNNMteQe+H8fU1fKsLj0ON3 txvkIlzU5NnZ9Se75NNrq1uHxzojpGNeP6O7Wnw7vAF2HzuM5+PFVoDz4BohWMeJSY1tm b3QvgmJQbfHlTkxrhXxAoU/HNIqE0hFtOckg6r6nVb7fPcwIDuVY8h5/o+LtY6ldSKGut KgdmeVMSlIwnRO0Ek4pNJwTOW5YyADnv9OZIh82Aonv7hEULkWhIVIQdRSS7He2VMX60J dvWfN3egHSCMdHqTIJvmYcSjo31KlEppsxCBkUcbvwK/lETRDdmZufT0UMLpkB0NzBQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796383855; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=Vi6kBLF9qcSntzg+JZ5ASxiVHol/521cgwyXtJV+Sjk=; b=iVWuUagBp8I6upB3zQVySgKm3GNtsBMQpVm7C52mVqlZ5sNuL22pjEokRl9g9+NuCg+A KxXyZQJx5D0MCb6u+yihdXyOnU9QAmOWrcCpXVsPamH1YnDKZeh0sVK7hAm/EPnk7ne38 jHOvCJZEdE6PDXLvldIMXqihwzEtvmjt4T/5rFpZXo4ULLwgUQu56IJiT2skN4z6OD/u/ 80QQfJBXH0N8lE/B5S0qdmJLdrNgD9FhcwMdNtnr/8oBnq8xAR8+LeQtld7NjtKN84vMq hA0yLIAvz4wnvMFvHrsvOskFJVEcxDk0AdNR1mMRLNXN4x4pS/6iAHK7NxWltizmLOQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=avVdNkzE; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EC84B606A322; Fri, 4 Dec 2026 11:30:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=avVdNkzE Received: by smtp.kernel.org (Postfix) with ESMTPSA id 64DA01F00897; Fri, 4 Dec 2026 11:30:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796383854; bh=Vi6kBLF9qcSntzg+JZ5ASxiVHol/521cgwyXtJV+Sjk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=avVdNkzEECrG7v/xkytbLFzOWOigiZdg30VEU6ZxVr2LAoiPYEQu1M8S9liYhBBC8 wbTVe0EbDbRLpsXoByplxkJDx+Zb5nhI5L0RUvjLhmRvkBu24+l85ekdErUaVGjpmR bWSmvNYlT3gY4mj54hyEed5YG1crDx7NwCNT1G44= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Sashiko , Wayne Ho , Guenter Roeck Subject: [PATCH 6.12 396/555] hwmon: (sht3x) Fix overflow when writing alert limits Date: Fri, 4 Dec 2026 19:07:19 +0900 Message-ID: <20261204100624.740671787@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Wayne Ho commit e6872defbb2eb1dc61b3ea168ca13e1362efbd86 upstream. limit_write() encodes the limits with 32-bit arithmetic, which overflows for the largest accepted values: (130000 + 45000) * 24543 = 4295025000 > U32_MAX 100000 * 42950 = 4295000000 > U32_MAX Writing 130000 to temp1_max therefore programs -45 degrees C, and writing 100000 to humidity1_max programs 0 %RH, so a limit set to its maximum makes the alert fire instead of never firing. Reading the attributes back returns the cached values, so this is not visible from sysfs. Use 64-bit arithmetic and clamp each result to its field width. Even with 64-bit arithmetic, 130000 encodes to 0x200, which overflows the 9-bit temperature field, and 100000 encodes to 0x10000, which is still 0 after masking. Prepared with the help of an AI coding assistant (Claude); I reproduced the bug and tested the fix on hardware. Fixes: 7c84f7f80d6f ("hwmon: add support for Sensirion SHT3x sensors") Cc: stable@vger.kernel.org Reported-by: Sashiko Closes: https://lore.kernel.org/linux-hwmon/20260725222229.EA69B1F000E9@smtp.kernel.org/ Signed-off-by: Wayne Ho Link: https://patch.msgid.link/20261113054857.97048-1-wayneho219@gmail.com Signed-off-by: Guenter Roeck Signed-off-by: Greg Kroah-Hartman --- drivers/hwmon/sht3x.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/drivers/hwmon/sht3x.c +++ b/drivers/hwmon/sht3x.c @@ -390,8 +390,8 @@ static size_t limit_write(struct device * adapted for fixed point arithmetic and packed the same as * in limit_read() */ - raw = ((u32)(temperature + 45000) * 24543) >> (16 + 7); - raw |= ((humidity * 42950) >> 16) & 0xfe00; + raw = min(((u64)(temperature + 45000) * 24543) >> (16 + 7), 0x1ff); + raw |= min(((u64)humidity * 42950) >> 16, 0xffff) & 0xfe00; put_unaligned_be16(raw, position); position += SHT3X_WORD_LEN;