mailarchive of the ptxdist mailing list
 help / color / mirror / Atom feed
From: ruggero rossi <rugrossi@googlemail.com>
To: ptxdist@pengutronix.de
Subject: [ptxdist] Bug in BusyBox 1.37.0 - NTPD Module
Date: Fri, 31 Jan 2025 13:06:05 +0100	[thread overview]
Message-ID: <20250131130605.05ea0372@RR-Laptop> (raw)

[-- Attachment #1: Type: text/plain, Size: 1001 bytes --]

HHello everyone,

My BSP still uses an older version of Linux and libc with a 32-bit time_t.

While migrating to ptxdist-2025.01.0, I encountered an unexpected crash in
the ntpd service. Specifically, when the BSP acts as an ntpd server, the
crash occurs on the client side.

After investigating the issue, I believe I have identified a bug. On my
system, time_t is effectively an int32_t. In the function that converts a
double to the NTP time format, I found the following code:

double d;
uint32_t intl;
intl = (uint32_t)(time_t)d;

Here, the integer part of d represents the number of seconds since
1900-01-01T00:00:00.0, which exceeds 31 bits.

Casting d to time_t in the server truncates the value to 0x7fffffff,
leading to a crash in the client.

The solution is to avoid the cast to time_t when sizeof(time_t) == 4.

I have attached a proposed patch for this issue. If someone with more
authority in the project could report this upstream, that would be
appreciated.

Best regards,

Ruggero



[-- Attachment #2: 0002-meson-dont-build-blkzone-if-blkzoned.h-is-not-available.patch --]
[-- Type: text/x-patch, Size: 1053 bytes --]

Some versions of Linux don't provide linux/blkzoned.h. In this case, attempting
to build blkzone produces an error. Suppress building of blkzone.  
Index: util-linux-2.39.2/meson.build
===================================================================
--- util-linux-2.39.2.orig/meson.build
+++ util-linux-2.39.2/meson.build
@@ -1477,16 +1477,19 @@ exes += exe
 manadocs += ['sys-utils/blkdiscard.8.adoc']
 bashcompletions += ['blkdiscard']
 
-exe = executable(
-  'blkzone',
-  blkzone_sources,
-  include_directories : includes,
-  link_with : [lib_common],
-  install_dir : sbindir,
-  install : true)
-exes += exe
-manadocs += ['sys-utils/blkzone.8.adoc']
-bashcompletions += ['blkzone']
+have = cc.has_header('linux/blkzoned.h')
+if have
+  exe = executable(
+    'blkzone',
+    blkzone_sources,
+    include_directories : includes,
+    link_with : [lib_common],
+    install_dir : sbindir,
+    install : true)
+  exes += exe
+  manadocs += ['sys-utils/blkzone.8.adoc']
+  bashcompletions += ['blkzone']
+endif
 
 exe = executable(
   'blkpr',

[-- Attachment #3: 0003-meson-dont-build-blkpr-if-pr.h-is-not-available.patch --]
[-- Type: text/x-patch, Size: 920 bytes --]

Some versions of Linux don't provide linux/pr.h.  In this case, attempting
to build blkpr produces an error. Suppress building of blkpr.
 
Index: util-linux-2.39.2/meson.build
===================================================================
--- util-linux-2.39.2.orig/meson.build
+++ util-linux-2.39.2/meson.build
@@ -1491,15 +1491,18 @@ if have
   bashcompletions += ['blkzone']
 endif
 
-exe = executable(
-  'blkpr',
-  blkpr_sources,
-  include_directories : includes,
-  link_with : [lib_common],
-  install_dir : sbindir,
-  install : true)
-exes += exe
-manadocs += ['sys-utils/blkpr.8.adoc']
+have = cc.has_header('linux/pr.h')
+if have
+  exe = executable(
+    'blkpr',
+    blkpr_sources,
+    include_directories : includes,
+    link_with : [lib_common],
+    install_dir : sbindir,
+    install : true)
+  exes += exe
+  manadocs += ['sys-utils/blkpr.8.adoc']
+endif
 
 exe = executable(
   'ldattach',

[-- Attachment #4: 0004-meson-dont-build-lsfd-if-kcmp.h-is-not-available.patch --]
[-- Type: text/x-patch, Size: 1066 bytes --]

Some versions of Linux don't provide linux/kcmp.h.   In this case, attempting
to build lsfd produces an error. Suppress building of lsfd.

Index: util-linux-2.39.2/meson.build
===================================================================
--- util-linux-2.39.2.orig/meson.build
+++ util-linux-2.39.2/meson.build
@@ -2595,17 +2595,20 @@ if not is_disabler(exe)
   bashcompletions += ['lsblk']
 endif
 
-exe = executable(
-  'lsfd',
-  lsfd_sources,
-  include_directories : includes,
-  link_with : [lib_common,
-               lib_smartcols],
-  install_dir : usrbin_exec_dir,
-  install : true)
-if not is_disabler(exe)
-  exes += exe
-  manadocs += ['misc-utils/lsfd.1.adoc']
+have = cc.has_header('linux/kcmp.h')
+if have
+  exe = executable(
+    'lsfd',
+    lsfd_sources,
+    include_directories : includes,
+    link_with : [lib_common,
+                 lib_smartcols],
+    install_dir : usrbin_exec_dir,
+    install : true)
+  if not is_disabler(exe)
+    exes += exe
+    manadocs += ['misc-utils/lsfd.1.adoc']
+  endif
 endif
 
 exe = executable(

[-- Attachment #5: 0005-meson-dont-build-mkfds-if-SIOCGSKNS-is-not-available.patch --]
[-- Type: text/x-patch, Size: 799 bytes --]

Some old version of Linux don't provide the SIOCGSKNS ioctl in linux/sockios.h. 
In this case, attempting to build test_mkfds produces an error. Suppress building 
of test_mkfds.
Index: util-linux-2.39.2/meson.build
===================================================================
--- util-linux-2.39.2.orig/meson.build
+++ util-linux-2.39.2/meson.build
@@ -3288,11 +3288,14 @@ exe = executable(
 exes += exe
 
 if LINUX
-  exe = executable(
-    'test_mkfds',
-    'tests/helpers/test_mkfds.c',
-    include_directories : includes)
-  exes += exe
+  have = cc.has_header_symbol('linux/sockios.h', 'SIOCGSKNS')
+  if have
+    exe = executable(
+      'test_mkfds',
+      'tests/helpers/test_mkfds.c',
+      include_directories : includes)
+    exes += exe
+  endif
 endif
 
 exe = executable(

[-- Attachment #6: util-linux.make.patch --]
[-- Type: text/x-patch, Size: 443 bytes --]

--- /usr/local/lib/ptxdist-2023.11.0/rules/util-linux.make	2023-10-30 11:15:25.000000000 +0100
+++ util-linux.make	2024-01-07 18:24:56.336248170 +0100
@@ -127,7 +127,7 @@
 	-Dlibpcre2-posix=disabled \
 	-Dlibuser=disabled \
 	-Dlibutempter=disabled \
-	-Dlibutil=disabled \
+	-Dlibutil=enabled \
 	-Dmagic=disabled \
 	-Dncurses=$(call ptx/endis, UTIL_LINUX_USES_NCURSES)d \
 	-Dncursesw=$(call ptx/endis, PTXCONF_UTIL_LINUX_USES_NCURSESW)d \

[-- Attachment #7: 0300-fix-ntpd-for-32-bit-time_t.patch --]
[-- Type: text/x-patch, Size: 623 bytes --]

Index: busybox-1.37.0/networking/ntpd.c
===================================================================
--- busybox-1.37.0.orig/networking/ntpd.c
+++ busybox-1.37.0/networking/ntpd.c
@@ -583,8 +583,13 @@ d_to_lfp(l_fixedpt_t *lfp, double d)
 {
 	uint32_t intl;
 	uint32_t frac;
-	intl = (uint32_t)(time_t)d;
-	frac = (uint32_t)((d - (time_t)d) * 0xffffffff);
+	if(sizeof(time_t) == 4){
+		intl = (uint32_t)d;
+		frac = (uint32_t)((d - intl) * 0xffffffff);
+	}else{
+		intl = (uint32_t)(time_t)d;
+		frac = (uint32_t)((d - (time_t)d) * 0xffffffff);
+	}
 	lfp->int_partl = htonl(intl);
 	lfp->fractionl = htonl(frac);
 }

             reply	other threads:[~2025-01-31 12:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-31 12:06 ruggero rossi [this message]
2025-02-07 14:07 ` Roland Hieber
  -- strict thread matches above, loose matches on Subject: below --
2025-01-31 10:15 ruggero

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250131130605.05ea0372@RR-Laptop \
    --to=rugrossi@googlemail.com \
    --cc=ptxdist@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox