From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 01C321FF604 for ; Fri, 6 Dec 2024 12:03:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733486613; cv=none; b=lbpwRxxbzt77yJ6kY3f3MWRq4VUyT5pwjWj605GS83ib7PlgjifuP5vrTti3YqJZWIvM01Z/C9qOAE3qnmRe2m07eUfjAX1uw2rPlbFOpxeGydGq2nn+hod3mGNenCeeZRCsAdK43r1LFQ2MSo95Bs7JyCkCrqTfS3NiwlHHstQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733486613; c=relaxed/simple; bh=+KBUBEdALReY/TGZodbTiFV00JP4qbYSnZEtcH7cnws=; h=Subject:To:Cc:From:Date:Message-ID:MIME-Version:Content-Type; b=T+x1ORYjWQ6Emu3i1zGRItYVMNxDAvF/mf2iN1kW1ka1dTM3VCBHYqasGregmE6rXXZsiCRe2ieEStUJ89Mz3OV2CShykRWg4sQ9hzGV+rtjBnoOCUSDx+2PmFeZXrkJrhM1rPnlbQLOhsBfUPdpLXF43uB+owUb+ysQ1pxK1/o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=cGEsz7jk; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="cGEsz7jk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 64A01C4CED1; Fri, 6 Dec 2024 12:03:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1733486612; bh=+KBUBEdALReY/TGZodbTiFV00JP4qbYSnZEtcH7cnws=; h=Subject:To:Cc:From:Date:From; b=cGEsz7jkM7uZZaKYhGhrD4vJej4FcLqhX5HoGEUBNnGL2IGGpOAZGbdHs2XvubRHb j01F1lY8vIjiOy4MYUupyUJQhicQ/QNf4+gSXmNhNq80vUcTSVYwoBqFJw3EjY+Mx3 0l70/lfg0Scq2L3GKcSPtXkyE7buSVC1Wcds2Jd0= Subject: FAILED: patch "[PATCH] ntp: Remove invalid cast in time offset math" failed to apply to 5.15-stable tree To: marcelo.dalmas@ge.com,tglx@linutronix.de Cc: From: Date: Fri, 06 Dec 2024 13:03:24 +0100 Message-ID: <2024120624-statutory-lustrous-bc12@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=ANSI_X3.4-1968 Content-Transfer-Encoding: 8bit The patch below does not apply to the 5.15-stable tree. If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to . To reproduce the conflict and resubmit, you may use the following commands: git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.15.y git checkout FETCH_HEAD git cherry-pick -x f5807b0606da7ac7c1b74a386b22134ec7702d05 # git commit -s git send-email --to '' --in-reply-to '2024120624-statutory-lustrous-bc12@gregkh' --subject-prefix 'PATCH 5.15.y' HEAD^.. Possible dependencies: thanks, greg k-h ------------------ original commit in Linus's tree ------------------ >From f5807b0606da7ac7c1b74a386b22134ec7702d05 Mon Sep 17 00:00:00 2001 From: Marcelo Dalmas Date: Mon, 25 Nov 2024 12:16:09 +0000 Subject: [PATCH] ntp: Remove invalid cast in time offset math Due to an unsigned cast, adjtimex() returns the wrong offest when using ADJ_MICRO and the offset is negative. In this case a small negative offset returns approximately 4.29 seconds (~ 2^32/1000 milliseconds) due to the unsigned cast of the negative offset. This cast was added when the kernel internal struct timex was changed to use type long long for the time offset value to address the problem of a 64bit/32bit division on 32bit systems. The correct cast would have been (s32), which is correct as time_offset can only be in the range of [INT_MIN..INT_MAX] because the shift constant used for calculating it is 32. But that's non-obvious. Remove the cast and use div_s64() to cure the issue. [ tglx: Fix white space damage, use div_s64() and amend the change log ] Fixes: ead25417f82e ("timex: use __kernel_timex internally") Signed-off-by: Marcelo Dalmas Signed-off-by: Thomas Gleixner Cc: stable@vger.kernel.org Link: https://lore.kernel.org/all/SJ0P101MB03687BF7D5A10FD3C49C51E5F42E2@SJ0P101MB0368.NAMP101.PROD.OUTLOOK.COM diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c index b550ebe0f03b..163e7a2033b6 100644 --- a/kernel/time/ntp.c +++ b/kernel/time/ntp.c @@ -798,7 +798,7 @@ int __do_adjtimex(struct __kernel_timex *txc, const struct timespec64 *ts, txc->offset = shift_right(ntpdata->time_offset * NTP_INTERVAL_FREQ, NTP_SCALE_SHIFT); if (!(ntpdata->time_status & STA_NANO)) - txc->offset = (u32)txc->offset / NSEC_PER_USEC; + txc->offset = div_s64(txc->offset, NSEC_PER_USEC); } result = ntpdata->time_state;