From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout-xforward.gmx.net (mout-xforward.gmx.net [82.165.159.12]) by sourceware.org (Postfix) with ESMTPS id 1F2C9383D834 for ; Tue, 31 May 2022 09:02:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1F2C9383D834 X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [100.120.170.163] ([84.17.52.175]) by mail.gmx.net (mrgmx004 [212.227.17.184]) with ESMTPSA (Nemesis) id 1M7b6l-1nsMjx1sHl-0086lH; Tue, 31 May 2022 11:02:28 +0200 Message-ID: <87fbe46f-3ebd-8659-055d-19a5145edb6c@gmx.fr> Date: Tue, 31 May 2022 11:02:28 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: Re: PROBLEM: with daemon.c after y2038 on 32-bits Kernel Content-Language: en-US To: Arnd Bergmann Cc: linux-kernel@vger.kernel.org, y2038@lists.linaro.org, libc-alpha@sourceware.org References: From: =?UTF-8?Q?Arnaud_Pana=c3=afotis?= In-Reply-To: X-Antivirus: Avast (VPS 220530-4, 30/5/2022), Outbound message X-Antivirus-Status: Clean X-Provags-ID: V03:K1:mUQ9ZqExppe1fU3lJ5zIeI2GrfFkrj+jVJaiNEqo0Uy59LXovG5 0uJs4Yd2+nKAvHr6PGyG+qW5JSRw+m/mkwvgoHLWNOGnDx5iDi8+DSGLFPLSPA+H8+Fv1/9 l7focTVcpioGzSnuB+Iq13IrQz/qXS96yT4q5uZTnCa+pfRMVzlfr4gm6RRQQFIzCmvZDmv ubXV26ENc2J04pDDJsfgQ== X-UI-Out-Filterresults: junk:10;V03:K0:qZSS6JDjPM4=:Dr0ss4/etd9a0H+nuAo/0lsM +OXRpTg22q2fJkOplg8MNoiCaAg7aqqvV5m+Vr5wOOGB14TXxekllaA49wSxuc8B3cg+kn4Jz yj/GA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I39QFWzsIxTAk5vdy5AW92 lVIKsGDwI4lGquXlGKJP5D3m4EVKuzfz3Mg8Ox2vOHFQ4TkRY3lN7b0dTp3XG7kHN4hRMwVrs bdULl4xc5ql/z01FQDQPckPX+aK6u+ZQBgLGQ== X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_40, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, HTML_MESSAGE, NICE_REPLY_A, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP, T_REMOTE_IMAGE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 31 May 2022 09:02:43 -0000 Hello On 31/05/2022 10:33, Arnd Bergmann wrote: > (cc correct libc-alpha list, sorry for the typo) > > On Tue, May 31, 2022 at 10:24 AM Arnd Bergmann wrote: >> On 17/05/2022 09:51, Arnaud Pana=C3=AFotis wrote: >>> I'm working for a client to generate embedded 32-bits Linux Kernel wor= king after y2038 issue. >>> >>> I generated a 5.15 Kernel thought Buildroot with Coreutils 9.0, GCC 11= .2.0, Binutils 2.37, Glibc 2.34-9 and CFLAGS -D_LARGEFILE_SOURCE -D_FILE_= OFFSET_BITS=3D64 -D_TIME_BITS=3D64. >>> >>> I encounter an issue while working with OpenSSH (I initially contacted= them before). >> To clarify: did you build just openssh with -D_TIME_BITS=3D64, or did >> you build the entire user space this way? I'm using Buildroot, I added it to TARGET_CPPFLAGS (also used by TARGET_CLAGS) and HOST_CPPFLAGS (used by HOST_CFLAGS) in buildroot/package/Makefile.in Then all packages are built with the option (unless the package filter it out, I had to create patches for few of them). Extracts of logs while rebuild openssh: /home/arnaud/devenv/branches/kernel510/output/host/bin/i686-buildroot-linu= x-gnu-gcc -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=3D64 -D_TIME_BITS=3D64=C2=A0 -Os= -g0 -D_FORTIFY_SOURCE=3D1 -pipe -Wno-error=3Dformat-truncation -Wall -Wextra -Wpointer-arith -Wuninitialized -Wsign-compare -Wformat-security -Wsizeof-pointer-memaccess -Wno-pointer-sign -Wno-unused-parameter -Wno-unused-result -Wimplicit-fallthrough -fno-strict-aliasing -ftrapv -fno-builtin-memset -fstack-protector-strong=C2=A0=C2=A0 -fPIC -I. -I.. -I= . -I./.. -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=3D64 -D_TIME_BITS=3D64 -D_XOPEN_SOURCE=3D600 -D_BSD_SOURCE -D_DEFAULT_SOURCE -DHAVE_CONFIG_H -c daemon.c /home/arnaud/devenv/branches/kernel510/output/host/bin/i686-buildroot-linu= x-gnu-gcc -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=3D64 -D_TIME_BITS=3D64=C2=A0 -Os= -g0 -D_FORTIFY_SOURCE=3D1 -pipe -Wno-error=3Dformat-truncation -Wall -Wextra -Wpointer-arith -Wuninitialized -Wsign-compare -Wformat-security -Wsizeof-pointer-memaccess -Wno-pointer-sign -Wno-unused-parameter -Wno-unused-result -Wimplicit-fallthrough -fno-strict-aliasing -ftrapv -fno-builtin-memset -fstack-protector-strong -fPIE=C2=A0=C2=A0 -I. -I. -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=3D64 -D_TIME_BITS=3D64 -D_XOPEN_SOURCE=3D600 -D_BSD_SOURCE -D_DEFAULT_SOURCE -DSSHDIR=3D\"/etc/ssh\" -D_PATH_SSH_PROGRAM=3D\"/usr/bin/ssh\" -D_PATH_SSH_ASKPASS_DEFAULT=3D\"/usr/libexec/ssh-askpass\" -D_PATH_SFTP_SERVER=3D\"/usr/libexec/sftp-server\" -D_PATH_SSH_KEY_SIGN=3D\"/usr/libexec/ssh-keysign\" -D_PATH_SSH_PKCS11_HELPER=3D\"/usr/libexec/ssh-pkcs11-helper\" -D_PATH_SSH_SK_HELPER=3D\"/usr/libexec/ssh-sk-helper\" -D_PATH_SSH_PIDDIR=3D\"/var/run\" -D_PATH_PRIVSEP_CHROOT_DIR=3D\"/var/empty\" -DHAVE_CONFIG_H -c sshd.c -o sshd.o >> >>> After 2038, /usr/sbin/sshd does not create an error but it child does = generate this one: >>> daemon() failed: Value too large for defined data type >>> >>> This happend here in sshd.c: >>> >>> 2019 /* >>> 2020 * If not in debugging mode, not started from inetd and n= ot already >>> 2021 * daemonized (eg re-exec via SIGHUP), disconnect from th= e controlling >>> 2022 * terminal, and fork. The original process exits. >>> 2023 */ >>> 2024 already_daemon =3D daemonized(); >>> 2025 if (!(debug_flag || inetd_flag || no_daemon_flag || alrea= dy_daemon)) { >>> 2026 >>> 2027 if (daemon(0, 0) =3D=3D -1) >>> 2028 fatal("daemon() failed: %.200s", strerror= (errno)); >> My guess is that there are parts of glibc that are not fully >> y2038-safe at the moment, but >> merely provide the interfaces for time64 applications. >> >> >> In the glibc code, I see >> >> int >> daemon (int nochdir, int noclose) >> { >> ... >> if ((fd =3D __open_nocancel(_PATH_DEVNULL, O_RDWR, 0))= !=3D -1 >> && (__builtin_expect (__fstat64 (fd, &st), 0) >> =3D=3D 0)) { >> ... >> } else { >> __close_nocancel_nostatus (fd); >> return -1; >> } >> return (0); >> } >> >> __fstatat64 (int fd, const char *file, struct stat64 *buf, int flags) >> { >> struct __stat64_t64 st_t64; >> return __fstatat64_time64 (fd, file, &st_t64, flags) >> ?: __cp_stat64_t64_stat64 (&st_t64, buf); >> } >> >> If I'm reading this correctly, daemon() internally uses the time32 >> version of 'stat', which fails for files with out-of-range timestamps. >> Are you able to rebuild the ssh binary (or your entire distro, if that'= s >> easier) against musl-1.2.x instead of glibc to see if the same thing >> happens there? I'd tried previously to build the entire distro with musl without success, not sure I can do it only for openssh. >> >> Arnd >> >>> To reproduce: >>> >>> # date -s "2040-05-12" >>> # hwclock --systohc >>> # reboot >>> # /usr/sbin/sshd >>> >>> Note this error occurs only after the reboot, and setting a date befor= e 2038 also require a reboot to remove the error. >>> >>> strace and gdb trace linked. >>> >>> Let me know if you need additional information. =2D- *Arnaud PANA=C3=8FOTIS* | Lead Developer Freelance +33 6 34 82 12 62 | arnaud.panaiotis@gmx.fr > 18 place Jean Moulin - 38000 Grenoble APsudo - www.panaiotis.fr =2D- L'absence de virus dans ce courrier =C3=A9lectronique a =C3=A9t=C3=A9 v=C3= =A9rifi=C3=A9e par le logiciel antivirus Avast. https://www.avast.com/antivirus