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=1796382522; b=LzDpvm4vMjuBrt9Mk2e7ut6uj1wWrEQiNKdOfzh8KvlowxhchZ/8kRoFv8NzjycV2WnF HH72w0hu4vh71J/8ZHID0ey+AT8xSZhlly1zlQ8FV3YGZ0isFTCHBd9H3zeb/W75IJtxF uZkYdh2ZoEKacS7mEfocCI7aXZSf93EdQP0FWGA2W/m9r38bKrumsE00hppquCXjkCUkZ f3zQi/y5/ywJuEl+QlI2Pwu4dhAoKW0zvDm6H8O3St12xt+VvBIeqvyLVtMvZQa1u4/86 d6xcxBBIeAjOgBeVUxX1vZbTyGIgqkQ+ymAuV2EOzBuBfp1G4l1JrYebQ9EW8dOVttw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382522; 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=WFI+LGXmzm1Mpyx+ZqRbSrCvwhjG5hnbsFgCOzLgPao=; b=dUXbYApVvMKHnu3QAnamdcDUV88KDzazQ2D3hYL7VbNzNYKRg2QJIK36xll0812yP5Rf SlkJ5sep3veY7VC7gjtsma4NulyDvSVx0PRq3erNTKQ6nNQka39A/+rg+1J8aF0y4OyI5 rVBbTl3rkl7RY8Ik3SBvB3IorvDe6t9ooNrs163nqBLix+4fTkXrgNLbH5o0e2BbG9AMM RfPFjMtaWm9KL+IU8r8Nga71L0r6fZyqPHHWjeinDmzhkE/6B5g0vBr6F7nL/qotX9Hkx PXJQDjR7d8qHyIMFcKFo32ojKi5mbCcoACeNN9hkEpUJIjo+UnwOjLmO23Pq8l95gQA== 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=Gq9+vtTG; 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 0F672606A322; Fri, 4 Dec 2026 11:08:42 +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=Gq9+vtTG Received: by smtp.kernel.org (Postfix) with ESMTPSA id 787E51F000C2; Fri, 4 Dec 2026 11:08:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382521; bh=WFI+LGXmzm1Mpyx+ZqRbSrCvwhjG5hnbsFgCOzLgPao=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Gq9+vtTG5FYsBRSTThE+q69WZFqO7B3lLF//XGZssPDNU+tcQ6mFrak+sd77/PQ6r viNJq/OOxnCWkwCl+thAi4kWl8PN19tbnFBEX/B4uHEwQlF86WHWbiQsYkvhuf5368 3ifvQooIgrvl3HE3QVZyjfr7ogJcOvTMykREKMzQ= 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.18 453/703] hwmon: (sht3x) Fix overflow when writing alert limits Date: Fri, 4 Dec 2026 19:05:52 +0900 Message-ID: <20261204100639.837886252@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@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.18-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;