From patchwork Sun Jun 14 00:51:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 1308787 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ens-lyon.org Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49kwsX2BmTz9s1x for ; Sun, 14 Jun 2020 10:52:15 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2AED139D580D; Sun, 14 Jun 2020 00:52:07 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from hera.aquilenet.fr (hera.aquilenet.fr [IPv6:2a0c:e300::1]) by sourceware.org (Postfix) with ESMTPS id 2E70D3870872 for ; Sun, 14 Jun 2020 00:52:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2E70D3870872 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=ens-lyon.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=samuel.thibault@ens-lyon.org Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id C8A2C3263; Sun, 14 Jun 2020 02:52:01 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id fZ3Dh5CFg5Zl; Sun, 14 Jun 2020 02:52:00 +0200 (CEST) Received: from function (lfbn-bor-1-797-11.w86-234.abo.wanadoo.fr [86.234.239.11]) by hera.aquilenet.fr (Postfix) with ESMTPSA id C8C763262; Sun, 14 Jun 2020 02:52:00 +0200 (CEST) Received: from samy by function with local (Exim 4.93) (envelope-from ) id 1jkGsR-00FoNu-Ls; Sun, 14 Jun 2020 02:51:59 +0200 From: Samuel Thibault To: libc-alpha@sourceware.org Subject: [hurd,commited] hurd: Make recv* cancellation points Date: Sun, 14 Jun 2020 02:51:59 +0200 Message-Id: <20200614005159.3768557-1-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_NEUTRAL, 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: , Cc: commit-hurd@gnu.org Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" * sysdeps/mach/hurd/recv.c (__recv): Make the __socket_recv call cancellable. * sysdeps/mach/hurd/recvfrom.c (__recvfrom): Make the __socket_recv and __socket_whatis_address calls cancellable. * sysdeps/mach/hurd/recvmsg.c (__libc_recvmsg): Make the __socket_recv, __socket_whatis_address, __io_reauthenticate, and __auth_user_authenticate calls cancellable. --- sysdeps/mach/hurd/recv.c | 5 +++++ sysdeps/mach/hurd/recvfrom.c | 22 +++++++++++++++------- sysdeps/mach/hurd/recvmsg.c | 23 ++++++++++++++++++----- 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/sysdeps/mach/hurd/recv.c b/sysdeps/mach/hurd/recv.c index 6dd556cc12..b9ed067265 100644 --- a/sysdeps/mach/hurd/recv.c +++ b/sysdeps/mach/hurd/recv.c @@ -21,6 +21,7 @@ #include #include #include +#include /* Read N bytes into BUF from socket FD. Returns the number read or -1 for errors. */ @@ -36,13 +37,17 @@ __recv (int fd, void *buf, size_t n, int flags) mach_msg_type_number_t nports = 0; char *cdata = NULL; mach_msg_type_number_t clen = 0; + int cancel_oldtype; + cancel_oldtype = LIBC_CANCEL_ASYNC(); err = HURD_DPORT_USE (fd, __socket_recv (port, &addrport, flags, &bufp, &nread, &ports, &nports, &cdata, &clen, &flags, n)); + LIBC_CANCEL_RESET (cancel_oldtype); + if (err == MIG_BAD_ID || err == EOPNOTSUPP) /* The file did not grok the socket protocol. */ err = ENOTSOCK; diff --git a/sysdeps/mach/hurd/recvfrom.c b/sysdeps/mach/hurd/recvfrom.c index 4479158d70..ed3d970722 100644 --- a/sysdeps/mach/hurd/recvfrom.c +++ b/sysdeps/mach/hurd/recvfrom.c @@ -21,6 +21,7 @@ #include #include #include +#include /* Read N bytes into BUF through socket FD. If ADDR is not NULL, fill in *ADDR_LEN bytes of it with tha address of @@ -39,13 +40,18 @@ __recvfrom (int fd, void *buf, size_t n, int flags, __SOCKADDR_ARG addrarg, char *cdata = NULL; mach_msg_type_number_t clen = 0; struct sockaddr *addr = addrarg.__sockaddr__; - - if (err = HURD_DPORT_USE (fd, __socket_recv (port, &addrport, - flags, &bufp, &nread, - &ports, &nports, - &cdata, &clen, - &flags, - n))) + int cancel_oldtype; + + cancel_oldtype = LIBC_CANCEL_ASYNC(); + err = HURD_DPORT_USE (fd, __socket_recv (port, &addrport, + flags, &bufp, &nread, + &ports, &nports, + &cdata, &clen, + &flags, + n)); + LIBC_CANCEL_RESET (cancel_oldtype); + + if (err) return __hurd_sockfail (fd, flags, err); /* Get address data for the returned address port if requested. */ @@ -55,7 +61,9 @@ __recvfrom (int fd, void *buf, size_t n, int flags, __SOCKADDR_ARG addrarg, mach_msg_type_number_t buflen = *addr_len; int type; + cancel_oldtype = LIBC_CANCEL_ASYNC(); err = __socket_whatis_address (addrport, &type, &buf, &buflen); + LIBC_CANCEL_RESET (cancel_oldtype); if (err == EOPNOTSUPP) /* If the protocol server can't tell us the address, just return a zero-length one. */ diff --git a/sysdeps/mach/hurd/recvmsg.c b/sysdeps/mach/hurd/recvmsg.c index 4297a90b32..75c5f37f0e 100644 --- a/sysdeps/mach/hurd/recvmsg.c +++ b/sysdeps/mach/hurd/recvmsg.c @@ -22,6 +22,7 @@ #include #include #include +#include /* Receive a message as described by MESSAGE from socket FD. Returns the number of bytes read or -1 for errors. */ @@ -42,12 +43,16 @@ __libc_recvmsg (int fd, struct msghdr *message, int flags) int nfds, *opened_fds = NULL; int i, ii, j; int newfds; + int cancel_oldtype; error_t reauthenticate (mach_port_t port, mach_port_t *result) { error_t err; mach_port_t ref; ref = __mach_reply_port (); + int cancel_oldtype; + + cancel_oldtype = LIBC_CANCEL_ASYNC(); do err = __io_reauthenticate (port, ref, MACH_MSG_TYPE_MAKE_SEND); while (err == EINTR); @@ -57,6 +62,8 @@ __libc_recvmsg (int fd, struct msghdr *message, int flags) ref, MACH_MSG_TYPE_MAKE_SEND, result)); while (err == EINTR); + LIBC_CANCEL_RESET (cancel_oldtype); + __mach_port_destroy (__mach_task_self (), ref); return err; } @@ -78,11 +85,14 @@ __libc_recvmsg (int fd, struct msghdr *message, int flags) } buf = data; - if (err = HURD_DPORT_USE (fd, __socket_recv (port, &aport, - flags, &data, &len, - &ports, &nports, - &cdata, &clen, - &message->msg_flags, amount))) + cancel_oldtype = LIBC_CANCEL_ASYNC(); + err = HURD_DPORT_USE (fd, __socket_recv (port, &aport, + flags, &data, &len, + &ports, &nports, + &cdata, &clen, + &message->msg_flags, amount)); + LIBC_CANCEL_RESET (cancel_oldtype); + if (err) return __hurd_sockfail (fd, flags, err); if (message->msg_name != NULL && aport != MACH_PORT_NULL) @@ -91,7 +101,10 @@ __libc_recvmsg (int fd, struct msghdr *message, int flags) mach_msg_type_number_t buflen = message->msg_namelen; int type; + cancel_oldtype = LIBC_CANCEL_ASYNC(); err = __socket_whatis_address (aport, &type, &buf, &buflen); + LIBC_CANCEL_RESET (cancel_oldtype); + if (err == EOPNOTSUPP) /* If the protocol server can't tell us the address, just return a zero-length one. */