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=1795024887; b=xv+WXwJzaSGE4AGA8qUWDZhuBfxQ+vbU9qAjO5Y07lVQwzH3Yt9+ftmSeN37GvsCna25 rvDM7Jd9ajCMDrTn2VcUTaYUHRwTbdYmIeG+dKRikdI8CKb98TGFiv+c6jfELIvt/Hqgj /SV0Fy4r16inK9KTlItsOzDT9lID9li2+TZag3BqG3HlWjNRIzTDdjy8Wxg+XXenewWS0 UTRUw/jCbc+LOQ0GWsESRVT6eWUO1bOiwzd63aW5WNQP69/IJ0C7nBh0t7jHDy1e1wb0k jz+5INeZIpeZsTZcjn2LjLPMrJcaggeiA9hWz+bG3JWcBpPj5fjfvZyZXnk0VpKINcw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795024887; 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-Type:Content-Transfer-Encoding; bh=S+uNcZUOJSePS4usgphvh5YF9mORZwQUQrLt5aJfpdg=; b=U0OrT3X9aMbDw0sMyuK01Qwq1xlFbdaVkQdW7pmKYoPApXFjsKkyhPwKyJ4ft0VwLhkt BcsCQjt2iSugLH2QzyKn8FaF4aESMRAIOKWXst/RQ77IcpCt1xoIsFHjwEEIMeFYNNXdL /TWOnv2KEVULqOPOVvFyga65rt3XDf67bGie7R5biOP9AO06USW1wlR1X9dLK0T4SR+wi 2VU+ZQ3GE1WKtKQwEm01lVh7q8BJg4115/mXEkzOQ0RB7V4TVDpp/LAABrmxpLiv4bl1k SJqYFjulUSXphcKBLFgC1kGAF7a3/sWg2t4rkEaLNg9d6BfYf8oAkE2VjXmRNIczicg== 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=YmBUKrpB; 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 51112606A31C; Wed, 18 Nov 2026 18:01:27 +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=YmBUKrpB Received: by smtp.kernel.org (Postfix) with ESMTPSA id A65A51F000C4; Wed, 18 Nov 2026 18:01:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795024887; bh=S+uNcZUOJSePS4usgphvh5YF9mORZwQUQrLt5aJfpdg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=YmBUKrpByIKFCkMtgtzU3XKGCdc8J2wgEu4lO+Uypi/IGWxQRIA2CmHflsSN/YdpV /TWB8T4rgFfpbrlJumj9GBG0ntjhxBidWYPIUqdQX5OZmG11sLCK1tZTwN1a5bZ1xq zsFBPZ/pd8VUachdD9t0/e7K4pZkE0peCo8GOb9g= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Karl Mehltretter , Thomas Gleixner , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Sasha Levin Subject: [PATCH 6.18 0885/2151] time: Prevent time64_to_tm() day truncation on 32-bit Date: Wed, 18 Nov 2026 15:43:40 +0100 Message-ID: <20261118150154.549738653@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150121.603863898@linuxfoundation.org> References: <20261118150121.603863898@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-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Karl Mehltretter [ Upstream commit 2927f7ca78448781e11a4623d347cd653c28adf6 ] time64_to_tm() accepts a 64-bit seconds value, but stores the quotient in long. On a 32-bit kernel the day count therefore wraps when it reaches 2^31, even though the corresponding year remains representable in struct tm. This is reachable when formatting externally supplied timestamps. For example, NILFS recovery copies the little-endian 64-bit ss_create field from an on-disk segment summary into time64_t. Its sysfs attributes then print that value with %ptTs, whose formatter calls time64_to_tm(). A corrupted image can consequently produce an architecture-dependent printed date. Keep the day quotient in s64 while leaving the seconds-within-day remainder as long. Use div_s64_rem() for the weekday calculation so 32-bit builds do not require compiler runtime division helpers. Fixes: e6c2682a1da3 ("time: Add time64_to_tm()") Signed-off-by: Karl Mehltretter Signed-off-by: Thomas Gleixner Assisted-by: LLM Reviewed-by: Thomas Weißschuh Link: https://patch.msgid.link/20260925165702.51677-2-kmehltretter@gmail.com Signed-off-by: Sasha Levin --- kernel/time/timeconv.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kernel/time/timeconv.c b/kernel/time/timeconv.c index 59b922c826e77..aed3af950fa0b 100644 --- a/kernel/time/timeconv.c +++ b/kernel/time/timeconv.c @@ -49,8 +49,9 @@ void time64_to_tm(time64_t totalsecs, int offset, struct tm *result) u32 u32tmp, day_of_century, year_of_century, day_of_year, month, day; u64 u64tmp, udays, century, year; bool is_Jan_or_Feb, is_leap_year; - long days, rem; int remainder; + long rem; + s64 days; days = div_s64_rem(totalsecs, SECS_PER_DAY, &remainder); rem = remainder; @@ -70,7 +71,8 @@ void time64_to_tm(time64_t totalsecs, int offset, struct tm *result) result->tm_sec = rem % 60; /* January 1, 1970 was a Thursday. */ - result->tm_wday = (4 + days) % 7; + div_s64_rem(days + 4, 7, &remainder); + result->tm_wday = remainder; if (result->tm_wday < 0) result->tm_wday += 7; -- 2.53.0