From patchwork Wed Sep 14 16:58:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 57638 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B1ABA384D1A1 for ; Wed, 14 Sep 2022 16:59:03 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from sonata.ens-lyon.org (sonata.ens-lyon.org [140.77.166.138]) by sourceware.org (Postfix) with ESMTPS id CD565384F024 for ; Wed, 14 Sep 2022 16:58:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CD565384F024 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=ens-lyon.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=bounce.ens-lyon.org Received: from localhost (localhost [127.0.0.1]) by sonata.ens-lyon.org (Postfix) with ESMTP id DD13B2010B; Wed, 14 Sep 2022 18:58:48 +0200 (CEST) Received: from sonata.ens-lyon.org ([127.0.0.1]) by localhost (sonata.ens-lyon.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id rPMEeajv6TOi; Wed, 14 Sep 2022 18:58:48 +0200 (CEST) Received: from begin (unknown [89.207.171.76]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by sonata.ens-lyon.org (Postfix) with ESMTPSA id BF22520105; Wed, 14 Sep 2022 18:58:48 +0200 (CEST) Received: from samy by begin with local (Exim 4.96) (envelope-from ) id 1oYViV-000Uvp-39; Wed, 14 Sep 2022 18:58:27 +0200 From: Samuel Thibault To: libc-alpha@sourceware.org Subject: [hurd,commited] hurd: Fix readlink() hanging on fifo Date: Wed, 14 Sep 2022 18:58:27 +0200 Message-Id: <20220914165827.118893-1-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_SBL_CSS, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" readlink() opens the target with O_READ to be able to read the symlink content. When the target is actually a fifo, that would hang waiting for a writer (caught in the coreutils testsuite). We thus have to first lookup the target without O_READ to perform io_stat and lookout for fifos, and only after checking the symlink type, we can re-lookup with O_READ. --- sysdeps/mach/hurd/readlink.c | 5 ++++- sysdeps/mach/hurd/readlinkat.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/sysdeps/mach/hurd/readlink.c b/sysdeps/mach/hurd/readlink.c index 770462714f..2d75ef7725 100644 --- a/sysdeps/mach/hurd/readlink.c +++ b/sysdeps/mach/hurd/readlink.c @@ -31,7 +31,7 @@ __readlink (const char *file_name, char *buf, size_t len) file_t file; struct stat64 st; - file = __file_name_lookup (file_name, O_READ | O_NOLINK, 0); + file = __file_name_lookup (file_name, O_NOLINK, 0); if (file == MACH_PORT_NULL) return -1; @@ -41,6 +41,9 @@ __readlink (const char *file_name, char *buf, size_t len) { char *rbuf = buf; + __mach_port_deallocate (__mach_task_self (), file); + file = __file_name_lookup (file_name, O_READ | O_NOLINK, 0); + err = __io_read (file, &rbuf, &len, 0, len); if (!err && rbuf != buf) { diff --git a/sysdeps/mach/hurd/readlinkat.c b/sysdeps/mach/hurd/readlinkat.c index 059aad9f58..113b92b732 100644 --- a/sysdeps/mach/hurd/readlinkat.c +++ b/sysdeps/mach/hurd/readlinkat.c @@ -32,7 +32,7 @@ readlinkat (int fd, const char *file_name, char *buf, size_t len) file_t file; struct stat64 st; - file = __file_name_lookup_at (fd, 0, file_name, O_READ | O_NOLINK, 0); + file = __file_name_lookup_at (fd, 0, file_name, O_NOLINK, 0); if (file == MACH_PORT_NULL) return -1; @@ -42,6 +42,9 @@ readlinkat (int fd, const char *file_name, char *buf, size_t len) { char *rbuf = buf; + __mach_port_deallocate (__mach_task_self (), file); + file = __file_name_lookup_at (fd, 0, file_name, O_READ | O_NOLINK, 0); + err = __io_read (file, &rbuf, &len, 0, len); if (!err && rbuf != buf) {