Bug 29746 - ppoll() does not switch to __ppoll64 when -D_TIME_BITS=64 and -D_FORTIFY_SOURCE=2 is given on 32bit
Summary: ppoll() does not switch to __ppoll64 when -D_TIME_BITS=64 and -D_FORTIFY_SOUR...
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: libc (show other bugs)
Version: 2.36
: P2 normal
Target Milestone: 2.37
Assignee: Adhemerval Zanella
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-11-03 13:09 UTC by Kabe
Modified: 2022-11-08 16:46 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kabe 2022-11-03 13:09:42 UTC
glibc version: 2.36 (git commit 19535f3b57)

host/build triplets: i586-redhat-linux

../configure --prefix=/usr/local/glibc2 --with-headers=/usr/include --enable-bind-now --build=i586-redhat-linux --host=i586-redhat-linux
kernel: Linux rocky9.five.ten 5.14.0-168.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Sep 23 11:43:25 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

gcc: 
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/i586-redhat-linux/11/lto-wrapper
Target: i586-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-host-pie --enable-host-bind-now --enable-languages=c,c++,fortran,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.rockylinux.org/ --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --without-isl --enable-gnu-indirect-function --with-tune=generic --with-arch=i586 --build=i586-redhat-linux --with-build-config=bootstrap-lto --enable-link-serialization=1
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.2.1 20220127 (Red Hat 11.2.1-9) (GCC)

binutils: binutils-2.35.2-17.el9.v1.i586

Additional URL: https://github.com/systemd/systemd/issues/25176

Consider the following code as poll.c:
```
#define _GNU_SOURCE 1
#define _TIME_BITS 64
#define _FILE_OFFSET_BITS 64

#include <stdio.h>
#include <sys/time.h>
#include <poll.h>

void wait1(void);

void wait1(void)
{
        struct pollfd fds[1];
        int nfds=0;
        struct timespec ts = {1, 0};
        ppoll(fds, nfds, &ts, NULL);
}
```

compiling as below shows no problem:
$ gcc -I/usr/local/glibc2/include/ -march=i686 -m32 -O -g -c poll.c
$ objdump -t poll.o|grep ppoll
00000000         *UND*  00000000 __ppoll64

ppoll() is properly redirected to __ppoll64 by -D_TIME_BITS=64.

Now add -D_FORTIFY_SOURCE=2:

$ gcc -I/usr/local/glibc2/include/ -march=i686 -m32 -O -g -D_FORTIFY_SOURCE=2 -c poll.c
$ objdump -t poll.o|grep ppoll
00000000         *UND*  00000000 ppoll

switching to __ppoll is nullified(bad).
Application passes paramters in 64bit time_t, whereas kernel will parse data as 32bit time_t,
which will upset ppoll().

I could not crank and a patch, since _TIME_BITS=64 involves heavy use of
asm and attributes trickery.
Comment 1 Adhemerval Zanella 2022-11-03 16:20:55 UTC
I will take a look.
Comment 2 Adhemerval Zanella 2022-11-08 16:46:15 UTC
Fixed on 2.37.