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=1796380966; b=QFz7sMKS//HZ0mfYXi4VVKgfkbH9G+i+1DjyeYWk0+xSosImVMqvgdUGRi1Wz1wYXUAP LI//5cQH92k8PYMJ0tDKNGbH12h9eT/tENA3qdv4m8/PH8blIr6E6yEvP6ASL2xkP0iIi WkEaa+Z40G5ETc0W+V82FlTFWA74HbBJCZ0YBj0+Lw9KCG27kfZPyNH2BUqgOW8/z4l28 WYX9i+ZfUW2zmZVgOUdEozS/fQnO/g/6GN33x2A4U4wRvIWCqN2CLPH1xWc1rvemiSO5F T7QacEDCBMtFO0JlBL2t55gBc/MkIuhZV2bXvEvJpD9lKvAGaEoCyNleUbc1FmbIuKg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380966; 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=jE2i28Gw+fP/kWi5lOjjouQfTwhml1v2y019pOjHPzY=; b=YyxrnMwu8sI75c4V3HBZXPUcp6z9ufjrtMu/BD/ptF1biOFxznpftJDyxA/6uYwoo/cn bsD5iZKHB3MAUU1A9diaKYjP1dDFfNmyT2ztIDVPuGCdOfmNSMbUHbuawNdMFXCX+aRTU mh0r1pkxHaQD/GiQU8OX5YzGtO3trLCCGw0sKEfgwDNGyUWBHZ0G4SjAyiEsGIn0zjf8Z Vk6CL5n5Dh1ADm4KHJlGnnaAdQOq4qjwepTQ1tYi02E3J+hHUQ7FyD6JxLrbelB6/epXD TaYhEKq7EiCKA/T2xP1o8hMCmICJpZLPzwxaBw0SMrbfRAuvGJLddZCB4YlJo0J8Wiw== 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=fqpqMlQM; 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 A5873606A332; Fri, 4 Dec 2026 10:42:46 +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=fqpqMlQM Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1ECE21F000C2; Fri, 4 Dec 2026 10:42:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380966; bh=jE2i28Gw+fP/kWi5lOjjouQfTwhml1v2y019pOjHPzY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=fqpqMlQMyKYsntozkDWaTtOwL1sbtyxXiIz4gLXsI7Tl1BY+fXelMX3r1VHAUkJS5 gXE8lFqD6bwnV27JSOPseZZTxfksxW+A7a+ibsvxHGsjZQv2CIPcKLsMIB8SQ5Wvii LcfYp4g4TY0ZwQVaBPNrdQeLDeA8xBXQR/TALdQs= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Sashiko , Wayne Ho , Guenter Roeck Subject: [PATCH 7.3 502/742] hwmon: (sht3x) Fix overflow when writing alert limits Date: Fri, 4 Dec 2026 19:06:06 +0900 Message-ID: <20261204100648.472868734@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@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 7.3-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 @@ -387,8 +387,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;