From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 0D1E23857414 for ; Fri, 25 Jun 2021 15:20:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0D1E23857414 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-360-pNywTfYQNS6Hfa2FMly5jw-1; Fri, 25 Jun 2021 11:20:06 -0400 X-MC-Unique: pNywTfYQNS6Hfa2FMly5jw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3A45C8042A8; Fri, 25 Jun 2021 15:20:05 +0000 (UTC) Received: from oldenburg.str.redhat.com (ovpn-112-228.ams2.redhat.com [10.36.112.228]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 663EC5D6AB; Fri, 25 Jun 2021 15:20:04 +0000 (UTC) From: Florian Weimer To: Adhemerval Zanella via Libc-alpha Subject: Re: [PATCH v3 05/24] linux: Add fallback for 64-bit time_t SO_TIMESTAMP{NS} References: <20210607203613.282543-1-adhemerval.zanella@linaro.org> <20210607203613.282543-6-adhemerval.zanella@linaro.org> Date: Fri, 25 Jun 2021 17:20:02 +0200 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") Message-ID: <87k0mi7yzh.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org 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: Fri, 25 Jun 2021 15:20:12 -0000 * 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) 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 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