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=1796389315; b=lPqb+cnSoH44zYa7elakkhgDcjWrPSyQDcV7ozqw+g6sqKnmG3VuPg80WR7cFEH+GCvq P0D4l4O8nI1KURMhRiDzedPdLtnCP3VXN65IuE40asrFtF8QbD2LeVohTLPbbWrmFNxJx 1+MwVTeT/WyUWgz/Es0S+WZ6ITakcTK1ZvxviBkgc/cj/hUji+U4FiIGfS07wUdj1tnJ4 h1QAqXT9l3YmHWST0A9EMKmSBhFgNUn7jRWUAr+8SezW4PGO4QXQw31FPzIt1v6oEvl82 vN47yq+hxEHqXa2jJVfuDHd0nnjIm3iE2fE7dl24MRCezN5W8rU6PX28RJW4338nGUA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796389315; 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=WFGYb88lgTcmF3NlhwOusWdQRYioXa6UJPF72evYKSY=; b=zgCJbrWDf2JnxnW3Jk8SqkOlHJkLwl6KTCxN2TloWdz5YVi+9+ZZg7e3SAeZfOmiESYX GUgSdj8DcLW2D8thGSjPPDodLQD7WZBCq+I1Trg9e/tvKRHWjTGdfXv3ufYSTJd7aKq9o jnTvLkV6/wg1T6NLd58D1lwr2jG4PMfrHMxh5dz/X8/3M+6Zr42PkG4U/oXZvFIkRI9gi GLZ27AqVCZ2/fRYLXhlSSZIF3Q5aKeom1pInHwS/bHHawGiJgD8DU1hncrIE7vKxag0g/ XO+QpmqjgAm9LsNcmuhMLB5DZkQlKW10+aj3+vi/qef6oeS2awAcl8qemMYzbPKTVnw== 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=fWM1ZaTP; 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 56986606A322; Fri, 4 Dec 2026 13:01:55 +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=fWM1ZaTP Received: by smtp.kernel.org (Postfix) with ESMTPSA id 96CDC1F00931; Fri, 4 Dec 2026 13:01:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796389315; bh=WFGYb88lgTcmF3NlhwOusWdQRYioXa6UJPF72evYKSY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=fWM1ZaTP2dXsvK/WCd+q50UwtpsdTrBHifSLyMcxZmh8HyQzmZG1MnfV3rnbbBlFM 6g1OjJAhsMq2Lqn6NuxZtBazlWsf/9mXE5Gs+gZcuqBIJw0Lx+YM8DUBsj14sbklhc kaNHhO0AeZY5jjtbfaiV+VLUdMQBa4yJRC/QtM4g= 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.1 0947/1059] hwmon: (sht3x) Fix overflow when writing alert limits Date: Fri, 4 Dec 2026 19:07:58 +0900 Message-ID: <20261204100708.553213678@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-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 @@ -362,8 +362,8 @@ static size_t limit_store(struct device * adapted for fixed point arithmetic and packed the same as * in limit_show() */ - 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;