tgt on arm64 and USE_SIGNALFD

Andreas Hasenack <[email protected]> Wed, 14 Feb 2024 17:14:42 -0300
Newsgroups org.kernel.vger.stgt
Message-ID <CANYNYEGR=8vV4JFicnWZ=MDwMc9zjPxHJ8tNj=zSner30UpeXg@mail.gmail.com>
Hi,

is USE_SIGNALFD meant to be supported on arm64? The check in
bs/util.h[1] is looking for __NR_signalfd, but arm64 only has the
newer __NR_signalfd4[2]:

#if defined(__NR_signalfd) && defined(USE_SIGNALFD)
...
#else
#define __signalfd(fd, mask, flags) (-1)
struct signalfd_siginfo {
};
#endif

Since that #ifdef fails, the signalfd_siginfo struct gets redefined to
be empty, and this is tripping a gcc check later on in usr/bs.c[3]
when gcc thinks something is being written into siginfo which is now
zero bytes long:

struct signalfd_siginfo siginfo[16];
...
ret =3D read(fd, (char *)siginfo, sizeof(siginfo));

Build:
bs.c: In function =E2=80=98bs_sig_request_done=E2=80=99:
bs.c:196:15: error: =E2=80=98read=E2=80=99 writing 1 byte into a region of =
size 0
overflows the destination [-Werror=3Dstringop-overflow=3D]
  196 |         ret =3D read(fd, (char *)siginfo, sizeof(siginfo));
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bs.c:193:33: note: destination object =E2=80=98siginfo=E2=80=99 of size 0
  193 |         struct signalfd_siginfo siginfo[16];
      |                                 ^~~~~~~

This error happens with -D_FORTIFY_SOURCE=3D3 and -O of 1 or higher, and
looks like a gcc bug, and a few similar to this have been filed
already[4].


1. https://github.com/fujita/tgt/blob/master/usr/util.h#L106
2. https://github.com/bminor/glibc/blob/f9ac84f92f151e07586c55e14ed628d493a=
5929d/sysdeps/unix/sysv/linux/aarch64/arch-syscall.h#L255
3. https://github.com/fujita/tgt/blob/master/usr/bs.c#L196
4. https://gcc.gnu.org/bugzilla/buglist.cgi?quicksearch=3Dwriting%201%20byt=
e%20into%20a%20region%20of%20size%200