From: Florian Weimer <fweimer@redhat.com>
To: Adhemerval Zanella via Libc-alpha <libc-alpha@sourceware.org>
Subject: Re: [PATCH v3 05/24] linux: Add fallback for 64-bit time_t SO_TIMESTAMP{NS}
Date: Fri, 25 Jun 2021 17:20:02 +0200 [thread overview]
Message-ID: <87k0mi7yzh.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <20210607203613.282543-6-adhemerval.zanella@linaro.org> (Adhemerval Zanella via Libc-alpha's message of "Mon, 7 Jun 2021 17:35:54 -0300")
* Adhemerval Zanella via Libc-alpha:
> +/* It converts the first SO_TIMESTAMP or SO_TIMESTAMPNS with 32-bit time and
> + appends it to the control buffer. The 32-bit time field is kept as-is.
> +
> + Calls with __TIMESIZE=32 will see the converted 64-bit time control
> + messages as spurious control message of unknown type.
> +
> + Calls with __TIMESIZE=64 running on pre-time64 kernels will see the
> + original message as a spurious control ones of unknown typ while running
> + on kernel with native 64-bit time support will only see the time64 version
> + of the control message. */
> +void
> +__convert_scm_timestamps (struct msghdr *msg, socklen_t msgsize)
> +{
> + if (msg->msg_control == NULL || msg->msg_controllen == 0)
> + return;
> +
> + /* The returned control message format for SO_TIMESTAMP_NEW is a
> + 'struct __kernel_sock_timeval' while for SO_TIMESTAMPNS_NEW is a
> + 'struct __kernel_timespec'. In either case it is two uint64_t
> + members. */
> + uint64_t tvts[2];
> +
> + struct cmsghdr *cmsg, *last = NULL;
> + int type = 0;
> +
> + for (cmsg = CMSG_FIRSTHDR (msg);
> + cmsg != NULL;
> + cmsg = CMSG_NXTHDR (msg, cmsg))
> + {
> + if (cmsg->cmsg_level != SOL_SOCKET)
> + continue;
> +
> + switch (cmsg->cmsg_type)
> + {
> + case COMPAT_SO_TIMESTAMP_OLD:
> + if (type != 0)
> + break;
> + type = COMPAT_SO_TIMESTAMP_NEW;
> + goto common;
> +
> + case COMPAT_SO_TIMESTAMPNS_OLD:
> + type = COMPAT_SO_TIMESTAMPNS_NEW;
> +
> + /* fallthrough */
> + common:
> + memcpy (tvts, CMSG_DATA (cmsg), sizeof (tvts));
> + break;
> + }
> +
> + last = cmsg;
> + }
> +
> + if (last == NULL || type == 0)
> + return;
> +
> + if (CMSG_SPACE (sizeof tvts) > msgsize - msg->msg_controllen)
> + {
> + msg->msg_flags |= MSG_CTRUNC;
> + return;
> + }
> +
> + msg->msg_controllen += CMSG_SPACE (sizeof tvts);
> + cmsg = CMSG_NXTHDR(msg, last);
> + cmsg->cmsg_level = SOL_SOCKET;
> + cmsg->cmsg_type = type;
> + cmsg->cmsg_len = CMSG_LEN (sizeof tvts);
> + memcpy (CMSG_DATA (cmsg), tvts, sizeof tvts);
> +}
> +libc_hidden_def (__convert_scm_timestamps)
> +#endif
The Ruby test suite crashes on this line:
cmsg->cmsg_level = SOL_SOCKET;
See:
ruby: FTBFS with test suite failure (glibc 2.34 related)
<https://bugzilla.redhat.com/show_bug.cgi?id=1975144>
The disassembly suggests that GCC has detected some undefined behavior.
This looks like a related bug:
__cmsg_nxthdr in cmsg_nxthdr.c (CMSG_NXTHDR) has undefined behavior when setting up ancillary data
<https://sourceware.org/bugzilla/show_bug.cgi?id=13500>
I believe you cannot use CMSG_NXTHDR to append data in this way.
The other question is why this code is running at all. Doing this
complex conversion for a 32-bit applications doing a 32-bit function
call on a kernel which supports 32-bit system calls does not make much
sense to me.
Thanks,
Florian
next prev parent reply other threads:[~2021-06-25 15:20 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-07 20:35 [PATCH v3 00/24] Add 64 bit time support on legacy ABIs Adhemerval Zanella
2021-06-07 20:35 ` [PATCH v3 01/24] linux: mips: Split librt.abilist in n32 and n64 Adhemerval Zanella
2021-06-07 20:35 ` [PATCH v3 02/24] linux: mips: Split libanl.abilist " Adhemerval Zanella
2021-06-07 20:35 ` [PATCH v3 03/24] linux: s390: Add libanl.abilist in s390 and s390x Adhemerval Zanella
2021-06-07 20:35 ` [PATCH v3 04/24] linux: Add fallback for 64-bit time_t SO_{RCV, SND}TIMEO Adhemerval Zanella
2021-06-14 14:52 ` [PATCH v3 04/24] linux: Add fallback for 64-bit time_t SO_{RCV,SND}TIMEO Carlos O'Donell
2021-06-07 20:35 ` [PATCH v3 05/24] linux: Add fallback for 64-bit time_t SO_TIMESTAMP{NS} Adhemerval Zanella
2021-06-25 15:20 ` Florian Weimer [this message]
2021-06-25 18:11 ` Adhemerval Zanella
2021-06-25 19:16 ` Florian Weimer
2021-06-28 13:36 ` Adhemerval Zanella
2021-06-07 20:35 ` [PATCH v3 06/24] linux: Add recvvmsg " Adhemerval Zanella
2021-06-07 20:35 ` [PATCH v3 07/24] y2038: Add __USE_TIME_BITS64 support for time_t Adhemerval Zanella
2021-06-07 20:35 ` [PATCH v3 08/24] y2038: Add __USE_TIME_BITS64 support for struct timeval Adhemerval Zanella
2021-06-07 20:35 ` [PATCH v3 09/24] y2038: Add __USE_TIME_BITS64 support for struct timespec Adhemerval Zanella
2021-06-07 20:35 ` [PATCH v3 10/24] y2038: Add __USE_TIME_BITS64 support for struct utimbuf Adhemerval Zanella
2021-06-07 20:36 ` [PATCH v3 11/24] y2038: linux: Add __USE_TIME_BITS64 support for struct timex Adhemerval Zanella
2021-06-07 20:36 ` [PATCH v3 12/24] y2038: Use a common definition for stat Adhemerval Zanella
2021-06-14 14:52 ` Carlos O'Donell
2021-06-07 20:36 ` [PATCH v3 13/24] y2038: Use a common definition for msqid_ds Adhemerval Zanella
2021-06-14 14:52 ` Carlos O'Donell
2021-06-07 20:36 ` [PATCH v3 14/24] y2038: Use a common definition for semid_ds Adhemerval Zanella
2021-06-14 14:52 ` Carlos O'Donell
2021-06-07 20:36 ` [PATCH v3 15/24] y2038: Use a common definition for shmid_ds Adhemerval Zanella
2021-06-14 14:59 ` Carlos O'Donell
2021-06-07 20:36 ` [PATCH v3 16/24] y2038: Add __USE_TIME_BITS64 support for socket-constants.h Adhemerval Zanella
2021-06-07 20:36 ` [PATCH v3 17/24] time: Add 64-bit time support for getdate Adhemerval Zanella
2021-06-07 20:36 ` [PATCH v3 18/24] y2038: Add support for 64-bit time on legacy ABIs Adhemerval Zanella
2021-10-13 11:44 ` Stafford Horne
2021-10-13 16:45 ` Paul Eggert
2021-10-13 21:51 ` Stafford Horne
2021-10-13 20:47 ` Joseph Myers
2021-10-13 21:50 ` Stafford Horne
2021-06-07 20:36 ` [PATCH v3 19/24] posix: Add glob64 with 64-bit time_t support Adhemerval Zanella
2021-06-14 14:52 ` Carlos O'Donell
2021-06-07 20:36 ` [PATCH v3 20/24] io: Add fts64 " Adhemerval Zanella
2021-06-07 20:36 ` [PATCH v3 21/24] io: Add ftw64 " Adhemerval Zanella
2021-06-07 20:36 ` [PATCH v3 22/24] libsupport: Add 64-bit time_t support for time functions Adhemerval Zanella
2021-06-14 14:52 ` Carlos O'Donell
2021-06-07 20:36 ` [PATCH v3 23/24] libsupport: Add 64-bit time_t support for stat functions Adhemerval Zanella
2021-06-07 20:36 ` [PATCH v3 24/24] y2038: Add test coverage Adhemerval Zanella
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=87k0mi7yzh.fsf@oldenburg.str.redhat.com \
--to=fweimer@redhat.com \
--cc=libc-alpha@sourceware.org \
/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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).