From patchwork Mon Apr 17 22:58:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Bugaev X-Patchwork-Id: 1769900 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=F5D3m7E3; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Q0jDF6DXcz1ybC for ; Tue, 18 Apr 2023 08:59:25 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C25B4385734E for ; Mon, 17 Apr 2023 22:59:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C25B4385734E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1681772363; bh=4Y3NDn1LcRWhRVtTDJEP7/pyWL/Z5xbvw0ME1TTbjcI=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=F5D3m7E3BcIZkBTwZAJ4Xyhritpl8tnpBE2AFz2fSH3W6lPwUWYZdr5Tyi2FprgWG 3c6L4NGKIyJ17xqTP7d2JA4jp74W4TYJfWb2wpwI/gE1ET/Jqd4Ffax0cJ5kWOJ+wH hV61oWN8Qi8eMg42fAXAdY/IdRFDiC6sdy45ryis= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [IPv6:2a00:1450:4864:20::233]) by sourceware.org (Postfix) with ESMTPS id B48953858C53 for ; Mon, 17 Apr 2023 22:59:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B48953858C53 Received: by mail-lj1-x233.google.com with SMTP id k15so10293950ljq.4 for ; Mon, 17 Apr 2023 15:59:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681772346; x=1684364346; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4Y3NDn1LcRWhRVtTDJEP7/pyWL/Z5xbvw0ME1TTbjcI=; b=ZV7eddQ/f74TVu1Fe1fVHuO/aYrMlpwTMFzqOu/Wp2Wm+/PGGlzeZkHx7HfHi1YRMP 3lKiPSX2R31MWM3z7q9XdlXo/uagVDAXT68XqyYtY+KHB7KnkOg0uReBBWcpmRBpSpNK MTb08F2US1blLkRFcT2FF1AAJ0Kelc/Mo87E6pH5C7foFG0s3fmcxQqK+IHlSPoyDvUe 9UMMqO9jR1LDWdI7HiLg0xj1ZUgmmhYRDArv/pmfx3rgfoguZjHoLVloqNstoV38c4z7 4plXCaRqAH8t1/F1qpdJB/M+dvWpkmV4sNYTp7y/2qM54MH2jyOJc9BuWzCPCaKdTN2R zfTw== X-Gm-Message-State: AAQBX9e2jli4j+QXXl/Yy2JaCCsLT2IR+j9BnUY60bMRmJ3EYPAF/JGq aodRlU/W6BtthWh6v5nA7KYudfAKnCdiiA== X-Google-Smtp-Source: AKy350atpW4N9zJHeNOSNZPAH+jo8pLkDvqozLoSt2QFUG378F0bDfH5FoPIciVNnmOhL+8wtFqj5A== X-Received: by 2002:a2e:94d0:0:b0:2a8:b95a:c10d with SMTP id r16-20020a2e94d0000000b002a8b95ac10dmr170219ljh.8.1681772346037; Mon, 17 Apr 2023 15:59:06 -0700 (PDT) Received: from surface-pro-6.. ([2a00:1370:818c:4a57:d907:80f6:db70:646a]) by smtp.gmail.com with ESMTPSA id f7-20020a2ea0c7000000b002a8b5310642sm1463539ljm.5.2023.04.17.15.59.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Apr 2023 15:59:05 -0700 (PDT) To: libc-alpha@sourceware.org, bug-hurd@gnu.org Cc: Samuel Thibault , Sergey Bugaev Subject: [RFC PATCH 1/5] misc: Convert daemon () to GNU coding style Date: Tue, 18 Apr 2023 01:58:53 +0300 Message-Id: <20230417225857.2006561-2-bugaevc@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230417225857.2006561-1-bugaevc@gmail.com> References: <20230417225857.2006561-1-bugaevc@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, 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: , X-Patchwork-Original-From: Sergey Bugaev via Libc-alpha From: Sergey Bugaev Reply-To: Sergey Bugaev Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" This is nicer, and is going to be required for the following changes to reasonably stay within the 79 column limit. No functional change. Signed-off-by: Sergey Bugaev --- misc/daemon.c | 88 ++++++++++++++++++++++++++++----------------------- 1 file changed, 49 insertions(+), 39 deletions(-) diff --git a/misc/daemon.c b/misc/daemon.c index 3c73ac2a..61da49b7 100644 --- a/misc/daemon.c +++ b/misc/daemon.c @@ -43,50 +43,60 @@ static char sccsid[] = "@(#)daemon.c 8.1 (Berkeley) 6/4/93"; int daemon (int nochdir, int noclose) { - int fd; + int fd; - switch (__fork()) { - case -1: - return (-1); - case 0: - break; - default: - _exit(0); - } + switch (__fork ()) + { + case -1: + return -1; - if (__setsid() == -1) - return (-1); + case 0: + break; - if (!nochdir) - (void)__chdir("/"); + default: + _exit (0); + } - if (!noclose) { - struct __stat64_t64 st; + if (__setsid () == -1) + return -1; - if ((fd = __open_nocancel(_PATH_DEVNULL, O_RDWR, 0)) != -1 - && __glibc_likely (__fstat64_time64 (fd, &st) == 0)) { - if (__builtin_expect (S_ISCHR (st.st_mode), 1) != 0 + if (!nochdir) + (void) __chdir ("/"); + + if (!noclose) + { + struct __stat64_t64 st; + + fd = __open_nocancel(_PATH_DEVNULL, O_RDWR, 0); + if (fd != -1 && __glibc_likely (__fstat64_time64 (fd, &st) == 0)) + { + if (__builtin_expect (S_ISCHR (st.st_mode), 1) != 0 #if defined DEV_NULL_MAJOR && defined DEV_NULL_MINOR - && (st.st_rdev - == makedev (DEV_NULL_MAJOR, DEV_NULL_MINOR)) + && (st.st_rdev == makedev (DEV_NULL_MAJOR, DEV_NULL_MINOR)) #endif - ) { - (void)__dup2(fd, STDIN_FILENO); - (void)__dup2(fd, STDOUT_FILENO); - (void)__dup2(fd, STDERR_FILENO); - if (fd > 2) - (void)__close (fd); - } else { - /* We must set an errno value since no - function call actually failed. */ - __close_nocancel_nostatus (fd); - __set_errno (ENODEV); - return -1; - } - } else { - __close_nocancel_nostatus (fd); - return -1; - } - } - return (0); + ) + { + (void) __dup2 (fd, STDIN_FILENO); + (void) __dup2 (fd, STDOUT_FILENO); + (void) __dup2 (fd, STDERR_FILENO); + if (fd > 2) + (void) __close (fd); + } + else + { + /* We must set an errno value since no function call + actually failed. */ + __close_nocancel_nostatus (fd); + __set_errno (ENODEV); + return -1; + } + } + else + { + __close_nocancel_nostatus (fd); + return -1; + } + } + + return 0; } From patchwork Mon Apr 17 22:58:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Bugaev X-Patchwork-Id: 1769903 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=O0FrZKZs; dkim-atps=neutral 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 ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Q0jFB6QXGz1ybC for ; Tue, 18 Apr 2023 09:00:14 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D543D3857718 for ; Mon, 17 Apr 2023 23:00:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D543D3857718 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1681772412; bh=zO86PVT5+Se/6AiVW6f2U1nxvwuo8rCc0xaNAU33C8M=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=O0FrZKZsAJZtY+tke43HhICR5QClER23aI4nH344oFM9AQOpBD14wY9BEoBTDcFfg s8mezfefv9Cru/73PGeLrypaRzsYquYj/o/Of7aTQ2Cp9GEpFohQ6yaGoB+LHCw245 fw1drAfaq53kT/BwQbBZ36Om6WyWuRXiBsUDPOeo= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lj1-x236.google.com (mail-lj1-x236.google.com [IPv6:2a00:1450:4864:20::236]) by sourceware.org (Postfix) with ESMTPS id F06F03858C5F for ; Mon, 17 Apr 2023 22:59:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F06F03858C5F Received: by mail-lj1-x236.google.com with SMTP id k15so10294003ljq.4 for ; Mon, 17 Apr 2023 15:59:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681772347; x=1684364347; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zO86PVT5+Se/6AiVW6f2U1nxvwuo8rCc0xaNAU33C8M=; b=SJE2i/q0Z17xVl9uyFsr4Pk222hRCiE6f9B33egmrQUokgsk6MSvMwxrTdHdLeVVL9 qrMlR0mZyONePm6DgplGMgD+tZpRVDPzyiUPb7UGqccGVurv3kZKFsaG+4kjLATPvHkO XlBtJcCg49kLw8T0bH7+sVQ+QOXHz3MSUWkwGuPYq3Dre+CFzxTM1DS3WwH49JHNacxh 8QVNBv5nIwr7NRyMrir6fsojJEYNWC2TrOp3tH+EDG94MZCzd3N8Yccr6cyPSXX5eDlC V8jC/p93h+LXKE5EcLl7QbGudOKIQjqY48zuoI9pq28dQhQEVVyAuqE4Ifi96hYU1+7X mhOg== X-Gm-Message-State: AAQBX9e9+38076T2IqU9PBiKy7Jp2HSNkaKoxy/o/0lyTpX3QBz6dS/e ctZV8Qc92JXXd0jq+f+WlMlC8I3Sno93Ig== X-Google-Smtp-Source: AKy350bFR40AwylSBUU0ohelo1axAFjWiaqC+PVl8pVx7ALCoZhYZoCaqw3Bfnet0YO+zu4pST7Ecg== X-Received: by 2002:a2e:9004:0:b0:2a8:adf6:b0e2 with SMTP id h4-20020a2e9004000000b002a8adf6b0e2mr128736ljg.13.1681772347119; Mon, 17 Apr 2023 15:59:07 -0700 (PDT) Received: from surface-pro-6.. ([2a00:1370:818c:4a57:d907:80f6:db70:646a]) by smtp.gmail.com with ESMTPSA id f7-20020a2ea0c7000000b002a8b5310642sm1463539ljm.5.2023.04.17.15.59.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Apr 2023 15:59:06 -0700 (PDT) To: libc-alpha@sourceware.org, bug-hurd@gnu.org Cc: Samuel Thibault , Sergey Bugaev Subject: [RFC PATCH 2/5] Use O_CLOEXEC in more places Date: Tue, 18 Apr 2023 01:58:54 +0300 Message-Id: <20230417225857.2006561-3-bugaevc@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230417225857.2006561-1-bugaevc@gmail.com> References: <20230417225857.2006561-1-bugaevc@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, 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: , X-Patchwork-Original-From: Sergey Bugaev via Libc-alpha From: Sergey Bugaev Reply-To: Sergey Bugaev Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" When opening a temporary file without O_CLOEXEC we risk leaking the file descriptor if another thread calls (fork and then) exec while we have the fd open. Fix this by consistently passing O_CLOEXEC everywhere where we open a file for internal use (and not to return it to the user, in which case the API defines whether or not the close-on-exec flag shall be set on the returned fd). Signed-off-by: Sergey Bugaev Reviewed-by: Adhemerval Zanella --- catgets/open_catalog.c | 4 ++-- elf/dl-profile.c | 3 ++- gmon/gmon.c | 7 ++++--- iconv/gconv_cache.c | 2 +- login/utmp_file.c | 2 +- sysdeps/pthread/sem_open.c | 9 ++++++--- 6 files changed, 16 insertions(+), 11 deletions(-) diff --git a/catgets/open_catalog.c b/catgets/open_catalog.c index 242709db..46c444d2 100644 --- a/catgets/open_catalog.c +++ b/catgets/open_catalog.c @@ -49,7 +49,7 @@ __open_catalog (const char *cat_name, const char *nlspath, const char *env_var, char *buf = NULL; if (strchr (cat_name, '/') != NULL || nlspath == NULL) - fd = __open_nocancel (cat_name, O_RDONLY); + fd = __open_nocancel (cat_name, O_RDONLY | O_CLOEXEC); else { const char *run_nlspath = nlspath; @@ -177,7 +177,7 @@ __open_catalog (const char *cat_name, const char *nlspath, const char *env_var, if (bufact != 0) { - fd = __open_nocancel (buf, O_RDONLY); + fd = __open_nocancel (buf, O_RDONLY | O_CLOEXEC); if (fd >= 0) break; } diff --git a/elf/dl-profile.c b/elf/dl-profile.c index 2ecac05f..d8345da2 100644 --- a/elf/dl-profile.c +++ b/elf/dl-profile.c @@ -324,7 +324,8 @@ _dl_start_profile (void) *cp++ = '/'; __stpcpy (__stpcpy (cp, GLRO(dl_profile)), ".profile"); - fd = __open64_nocancel (filename, O_RDWR|O_CREAT|O_NOFOLLOW, DEFFILEMODE); + fd = __open64_nocancel (filename, O_RDWR | O_CREAT | O_NOFOLLOW + | O_CLOEXEC, DEFFILEMODE); if (fd == -1) { char buf[400]; diff --git a/gmon/gmon.c b/gmon/gmon.c index bc0e2943..6439ed1c 100644 --- a/gmon/gmon.c +++ b/gmon/gmon.c @@ -384,13 +384,14 @@ write_gmon (void) size_t len = strlen (env); char buf[len + 20]; __snprintf (buf, sizeof (buf), "%s.%u", env, __getpid ()); - fd = __open_nocancel (buf, O_CREAT|O_TRUNC|O_WRONLY|O_NOFOLLOW, 0666); + fd = __open_nocancel (buf, O_CREAT | O_TRUNC | O_WRONLY | O_NOFOLLOW + | O_CLOEXEC, 0666); } if (fd == -1) { - fd = __open_nocancel ("gmon.out", O_CREAT|O_TRUNC|O_WRONLY|O_NOFOLLOW, - 0666); + fd = __open_nocancel ("gmon.out", O_CREAT | O_TRUNC | O_WRONLY + | O_NOFOLLOW | O_CLOEXEC, 0666); if (fd < 0) { char buf[300]; diff --git a/iconv/gconv_cache.c b/iconv/gconv_cache.c index f2100ca8..87136e24 100644 --- a/iconv/gconv_cache.c +++ b/iconv/gconv_cache.c @@ -58,7 +58,7 @@ __gconv_load_cache (void) return -1; /* See whether the cache file exists. */ - fd = __open_nocancel (GCONV_MODULES_CACHE, O_RDONLY, 0); + fd = __open_nocancel (GCONV_MODULES_CACHE, O_RDONLY | O_CLOEXEC, 0); if (__builtin_expect (fd, 0) == -1) /* Not available. */ return -1; diff --git a/login/utmp_file.c b/login/utmp_file.c index 53494595..1ef07821 100644 --- a/login/utmp_file.c +++ b/login/utmp_file.c @@ -463,7 +463,7 @@ __libc_updwtmp (const char *file, const struct utmp *utmp) int fd; /* Open WTMP file. */ - fd = __open_nocancel (file, O_WRONLY | O_LARGEFILE); + fd = __open_nocancel (file, O_WRONLY | O_LARGEFILE | O_CLOEXEC); if (fd < 0) return -1; diff --git a/sysdeps/pthread/sem_open.c b/sysdeps/pthread/sem_open.c index 2d32a135..e5db929d 100644 --- a/sysdeps/pthread/sem_open.c +++ b/sysdeps/pthread/sem_open.c @@ -36,6 +36,7 @@ sem_t * __sem_open (const char *name, int oflag, ...) { int fd; + int open_flags; sem_t *result; /* Check that shared futexes are supported. */ @@ -64,9 +65,10 @@ __sem_open (const char *name, int oflag, ...) /* If the semaphore object has to exist simply open it. */ if ((oflag & O_CREAT) == 0 || (oflag & O_EXCL) == 0) { + open_flags = O_RDWR | O_NOFOLLOW | O_CLOEXEC; + open_flags |= (oflag & ~(O_CREAT|O_ACCMODE)); try_again: - fd = __open (dirname.name, - (oflag & ~(O_CREAT|O_ACCMODE)) | O_NOFOLLOW | O_RDWR); + fd = __open (dirname.name, open_flags); if (fd == -1) { @@ -133,7 +135,8 @@ __sem_open (const char *name, int oflag, ...) } /* Open the file. Make sure we do not overwrite anything. */ - fd = __open (tmpfname, O_RDWR | O_CREAT | O_EXCL, mode); + open_flags = O_RDWR | O_CREAT | O_EXCL | O_CLOEXEC; + fd = __open (tmpfname, open_flags, mode); if (fd == -1) { if (errno == EEXIST) From patchwork Mon Apr 17 22:58:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Bugaev X-Patchwork-Id: 1769902 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=FP9U3TTh; dkim-atps=neutral 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 ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Q0jF51mSFz1ybC for ; Tue, 18 Apr 2023 09:00:09 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2FBF638560B9 for ; Mon, 17 Apr 2023 23:00:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2FBF638560B9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1681772407; bh=P2F0lLd3uq0EVIYYJXfnpMg84G+R92nUkkBKFKIsi5I=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=FP9U3TThUW4gPxbzjx8YapMHcAlhaEHNxdPqORzJ3ew3XeS2mvim1AEwpAbuI99eD /7eTHDZPR4vndQDgSmADTJs644TCaOTq4jy5K+v8Fj8gqS/nPasKRovcu037iBSOp4 0qk9VkFputalRS2BghZRMHJ1uYdI8+3wzwHl5iNA= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lj1-x230.google.com (mail-lj1-x230.google.com [IPv6:2a00:1450:4864:20::230]) by sourceware.org (Postfix) with ESMTPS id C34413858C2D for ; Mon, 17 Apr 2023 22:59:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C34413858C2D Received: by mail-lj1-x230.google.com with SMTP id by8so28054611ljb.13 for ; Mon, 17 Apr 2023 15:59:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681772348; x=1684364348; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=P2F0lLd3uq0EVIYYJXfnpMg84G+R92nUkkBKFKIsi5I=; b=Ks3oFl1+SI6iNV62V1UBoT6iHzurrXX3YDe8O6lOgInr/cBxIK4mmcCJZNd0EFDQsh 1g4fgPndnsmj8+cYf1hnc954kw4q/lFy0VcDDt7DezFKVV442AHcam4QYxRuD4LJpSDG O4XA8tkb83y4AG7ahli9HP/30BZfCfuK4H5F0c6FizxM7hU/ultzlh6/tOCe6tHWPXtl TzfttkA69lOsL989CTyHArDG61nyiZOU3jNgjAFQLTbjrACFiXIV6PEbzliDflqx2w6G wCPADQDG/M1aaeQ9ojIytOCgC5Q8dHCgcjbmPdRTOAV3k3rDlNfGNrqkuFu5VCTqr0Au FUiw== X-Gm-Message-State: AAQBX9eaNcF3p/6+cRF6CKY2z05GRXBYU7ys6zjv5/5CjvLmxrxgomuX 0ku3DpoPy8XwHnzRs0FooEVmdnh/MvPSrQ== X-Google-Smtp-Source: AKy350Zjb636pAH9H36F3QA3qaZ+ZDABt5dfDESlW71x9BPa4d/XXdyAALP4f0ypzJuLKH2+RzccOg== X-Received: by 2002:a2e:904c:0:b0:2a8:ddb0:baa6 with SMTP id n12-20020a2e904c000000b002a8ddb0baa6mr22501ljg.4.1681772348028; Mon, 17 Apr 2023 15:59:08 -0700 (PDT) Received: from surface-pro-6.. ([2a00:1370:818c:4a57:d907:80f6:db70:646a]) by smtp.gmail.com with ESMTPSA id f7-20020a2ea0c7000000b002a8b5310642sm1463539ljm.5.2023.04.17.15.59.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Apr 2023 15:59:07 -0700 (PDT) To: libc-alpha@sourceware.org, bug-hurd@gnu.org Cc: Samuel Thibault , Sergey Bugaev Subject: [RFC PATCH 3/5] hurd: Make dl-sysdep's open () cope with O_IGNORE_CTTY Date: Tue, 18 Apr 2023 01:58:55 +0300 Message-Id: <20230417225857.2006561-4-bugaevc@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230417225857.2006561-1-bugaevc@gmail.com> References: <20230417225857.2006561-1-bugaevc@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, 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: , X-Patchwork-Original-From: Sergey Bugaev via Libc-alpha From: Sergey Bugaev Reply-To: Sergey Bugaev Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" Signed-off-by: Sergey Bugaev --- sysdeps/mach/hurd/dl-sysdep.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sysdeps/mach/hurd/dl-sysdep.c b/sysdeps/mach/hurd/dl-sysdep.c index 2d595d00..6e167e12 100644 --- a/sysdeps/mach/hurd/dl-sysdep.c +++ b/sysdeps/mach/hurd/dl-sysdep.c @@ -289,8 +289,8 @@ open_file (const char *file_name, int flags, return MACH_PORT_NULL; } - assert (!(flags & ~(O_READ | O_EXEC | O_CLOEXEC))); - flags &= ~O_CLOEXEC; + assert (!(flags & ~(O_READ | O_EXEC | O_CLOEXEC | O_IGNORE_CTTY))); + flags &= ~(O_CLOEXEC | O_IGNORE_CTTY); startdir = _dl_hurd_data->portarray[file_name[0] == '/' ? INIT_PORT_CRDIR : INIT_PORT_CWDIR]; From patchwork Mon Apr 17 22:58:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Bugaev X-Patchwork-Id: 1769901 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=bzGcoPTu; dkim-atps=neutral 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 ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Q0jDN4kSMz1yZk for ; Tue, 18 Apr 2023 08:59:32 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A47B93857727 for ; Mon, 17 Apr 2023 22:59:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A47B93857727 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1681772370; bh=FvAZr72cbt13yNzoAGdXF+/5UCvJ/fObaq0qJ2h09dA=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=bzGcoPTuMrmGu3+R+E78gXn86qRriN3giYqwb9J1zy6CikQMCbZsd7ldzchl+76hi RZ4fH+1bQuRM8lb7JH7Ro4+iElWdCqRZ7oxVwk/t9XTl/Q4IdGoSvbIdo0ABfqNPpS iGG4g6Lm+meeB96EWzk41r1G87RT6U+PaE75QrGk= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by sourceware.org (Postfix) with ESMTPS id ED3023858C2F for ; Mon, 17 Apr 2023 22:59:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ED3023858C2F Received: by mail-lj1-x229.google.com with SMTP id by8so28054642ljb.13 for ; Mon, 17 Apr 2023 15:59:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681772349; x=1684364349; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FvAZr72cbt13yNzoAGdXF+/5UCvJ/fObaq0qJ2h09dA=; b=GgenqiKC9nynYeH/XQ7MQBhZ6SP/3pHYpw/9eLmMhwIKMoOiq1F/D/MCzUXMVDbHh9 T+z0xzZulpQXBXUQp4yG9oZ2gQc6ROER75oW5nU2zerQqhxnHDnl/HlI7jPw1X1AbRBS kp3z8tQEN+p1FLyZw01lFI+1jueI5xR/aQKt14t2eA2u0HhLXMLqwrVN7coi5oAoejLr V1tYa3KGeFR7eNZSIr17ZoN2qSw/Ujx9NhSbWXj18mvrcAfXyYiDix4cGRIg+As/YFKw fM5aTk4ndDBKYkZFEQCQWxS8A2xzKs3yz9gCD2TnnVTfw7DMLZE/K1thW6G0zoqUnDRk tIOg== X-Gm-Message-State: AAQBX9fuhJyNRaA+tqpdvBlP2yTaO2W7hVMmca/4Xq0bYwsv4LOtaXZC E0eko0Ur0ch7t/rFxTqb7EFb905ltkYJ2w== X-Google-Smtp-Source: AKy350Y31LS9JPbcxhPPtzLK7GGQ3KivXI+MfnhwUXMnJAF5jyY1ET11EqCDLI+1lTdCkM+ADTKPvQ== X-Received: by 2002:a2e:9bd6:0:b0:2a8:a80f:dbbc with SMTP id w22-20020a2e9bd6000000b002a8a80fdbbcmr131750ljj.9.1681772349182; Mon, 17 Apr 2023 15:59:09 -0700 (PDT) Received: from surface-pro-6.. ([2a00:1370:818c:4a57:d907:80f6:db70:646a]) by smtp.gmail.com with ESMTPSA id f7-20020a2ea0c7000000b002a8b5310642sm1463539ljm.5.2023.04.17.15.59.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Apr 2023 15:59:08 -0700 (PDT) To: libc-alpha@sourceware.org, bug-hurd@gnu.org Cc: Samuel Thibault , Sergey Bugaev Subject: [RFC PATCH 4/5] include/fcntl.h: Define O_IGNORE_CTTY Date: Tue, 18 Apr 2023 01:58:56 +0300 Message-Id: <20230417225857.2006561-5-bugaevc@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230417225857.2006561-1-bugaevc@gmail.com> References: <20230417225857.2006561-1-bugaevc@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, 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: , X-Patchwork-Original-From: Sergey Bugaev via Libc-alpha From: Sergey Bugaev Reply-To: Sergey Bugaev Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" This internal definition makes it possible to use O_IGNORE_CTTY in the glibc codebase unconditionally, no matter whether the current port provides it or not (i.e. both on Hurd and on Linux). Along with the definition, this adds a small guide on when O_IGNORE_CTTY is to be used. The following commit will actually make use of O_IGNORE_CTTY throughout the glibc codebase. Signed-off-by: Sergey Bugaev --- include/fcntl.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/include/fcntl.h b/include/fcntl.h index be435047..3de40827 100644 --- a/include/fcntl.h +++ b/include/fcntl.h @@ -33,6 +33,22 @@ extern int __openat_2 (int __fd, const char *__path, int __oflag); extern int __openat64_2 (int __fd, const char *__path, int __oflag); +/* Makes open () & friends slightly faster on the Hurd, but can only be used + (without altering user-visible behavior) when we're sure that the file + we're opening is not (at the moment) our controlling terminal. Use this + when: + - opening well-known files internally (utmp, nss db); + - opening files with user-specified names that can not reasonably be ttys + (sem_open, shm_open); + - opening new (previously unused) ttys (openpty). + Don't use this when: + - doing a general-purpose open () with a user-controlled path that could + well be "/dev/tty" (fopen). */ +#ifndef O_IGNORE_CTTY +# define O_IGNORE_CTTY 0 +#endif + + #if IS_IN (rtld) # include #endif From patchwork Mon Apr 17 22:58:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Bugaev X-Patchwork-Id: 1769904 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=M0LLni5m; dkim-atps=neutral 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 ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Q0jG10XKwz1ybC for ; Tue, 18 Apr 2023 09:00:57 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0EB9A385695E for ; Mon, 17 Apr 2023 23:00:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0EB9A385695E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1681772455; bh=49rbTMrUGBhocdTf6n0Asvz6ypdVmqQ4gnN5kYQcMU4=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=M0LLni5mg9eO/e0jxO8IEtJFaWAuAIjLQ1pSysEE84dv7DB18ysATbhdIqftwlVG3 vT5jknhjIRriCRQcQePXfmUtg3qRG1Ia+Is0F3f30Ro6lpP2aBV10hsd+VubgngEoY 2dBkJcIeGpiLIFQyHuZHPvXrZkD5dZ3ft02KIcx0= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) by sourceware.org (Postfix) with ESMTPS id 39BE03857726 for ; Mon, 17 Apr 2023 22:59:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 39BE03857726 Received: by mail-lj1-x232.google.com with SMTP id by8so28054670ljb.13 for ; Mon, 17 Apr 2023 15:59:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681772350; x=1684364350; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=49rbTMrUGBhocdTf6n0Asvz6ypdVmqQ4gnN5kYQcMU4=; b=FISBytlKHCxXhXApO8qSagv0WUhqgvveuWj/cbb795ZxufPmRySbSJkfL+E3iei/vz o+OAPEapBn3QdP0Bfy6Vh/8lXK5TyWjEfTMnswuULVfbehumCz87PXZDgzoTAMy+xc5x gE+cWk/4e5/V5LgcGNKKV0GC6NezIzGIXc7TABqkJYvCxkDvHvdyilmTr3vg83hexHwY z+JjutEZUkq04KiJr/pcGuo52t7apyCqZx+bhk41SN337WbdFxpoVO8sr4+iE6aT8R3t aZfJ+XDbSdOQ2+I85fbSkjeXE/ZCBWzK9Yww509rQ/i9UI6XpxdRa6vJfq5fGAg/Xe16 ZO1A== X-Gm-Message-State: AAQBX9dcbrv7jwFaGdpp3bmgqWpT5EPi3AWgMHs5kwzcA5T6LSz3qmN6 z3qq4ZESJHfYKnBC3r57Y/RJ7IsdAHPt9A== X-Google-Smtp-Source: AKy350Yz3VIRTeqaZ6nV2BmzgYsnEbM9731rEN2d5ROczQWorSg7rzVbutAaBxhWGTMbY78A3Zs28Q== X-Received: by 2002:a2e:944f:0:b0:2a7:78c3:a3ee with SMTP id o15-20020a2e944f000000b002a778c3a3eemr115160ljh.45.1681772350291; Mon, 17 Apr 2023 15:59:10 -0700 (PDT) Received: from surface-pro-6.. ([2a00:1370:818c:4a57:d907:80f6:db70:646a]) by smtp.gmail.com with ESMTPSA id f7-20020a2ea0c7000000b002a8b5310642sm1463539ljm.5.2023.04.17.15.59.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Apr 2023 15:59:09 -0700 (PDT) To: libc-alpha@sourceware.org, bug-hurd@gnu.org Cc: Samuel Thibault , Sergey Bugaev Subject: [RFC PATCH 5/5] Use O_IGNORE_CTTY where appropriate Date: Tue, 18 Apr 2023 01:58:57 +0300 Message-Id: <20230417225857.2006561-6-bugaevc@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230417225857.2006561-1-bugaevc@gmail.com> References: <20230417225857.2006561-1-bugaevc@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, 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: , X-Patchwork-Original-From: Sergey Bugaev via Libc-alpha From: Sergey Bugaev Reply-To: Sergey Bugaev Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" * getpt, openpty: Opening an unused pty, which can't be our ctty * shm_open, sem_open: These don't work with ttys * opendir: Directories are unlikely to be ttys Signed-off-by: Sergey Bugaev --- catgets/open_catalog.c | 4 ++-- csu/check_fds.c | 6 +++--- elf/dl-load.c | 2 +- elf/dl-misc.c | 2 +- elf/dl-profile.c | 2 +- gmon/gmon.c | 4 ++-- iconv/gconv_cache.c | 3 ++- locale/loadarchive.c | 7 ++++--- locale/loadlocale.c | 4 ++-- login/openpty.c | 2 +- login/utmp_file.c | 7 ++++--- misc/daemon.c | 2 +- nss/nss_db/db-open.c | 3 ++- rt/shm_open.c | 2 +- shadow/lckpwdf.c | 2 +- sysdeps/mach/hurd/opendir.c | 2 +- sysdeps/pthread/sem_open.c | 4 ++-- sysdeps/unix/bsd/getpt.c | 4 ++-- 18 files changed, 33 insertions(+), 29 deletions(-) diff --git a/catgets/open_catalog.c b/catgets/open_catalog.c index 46c444d2..129f4662 100644 --- a/catgets/open_catalog.c +++ b/catgets/open_catalog.c @@ -49,7 +49,7 @@ __open_catalog (const char *cat_name, const char *nlspath, const char *env_var, char *buf = NULL; if (strchr (cat_name, '/') != NULL || nlspath == NULL) - fd = __open_nocancel (cat_name, O_RDONLY | O_CLOEXEC); + fd = __open_nocancel (cat_name, O_RDONLY | O_CLOEXEC | O_IGNORE_CTTY); else { const char *run_nlspath = nlspath; @@ -177,7 +177,7 @@ __open_catalog (const char *cat_name, const char *nlspath, const char *env_var, if (bufact != 0) { - fd = __open_nocancel (buf, O_RDONLY | O_CLOEXEC); + fd = __open_nocancel (buf, O_RDONLY | O_CLOEXEC | O_IGNORE_CTTY); if (fd >= 0) break; } diff --git a/csu/check_fds.c b/csu/check_fds.c index de6dd716..636bc431 100644 --- a/csu/check_fds.c +++ b/csu/check_fds.c @@ -90,7 +90,7 @@ __libc_check_standard_fds (void) is really paranoid but some people actually are. If /dev/null should happen to be a symlink to somewhere else and not the device commonly known as "/dev/null" we bail out. */ - check_one_fd (STDIN_FILENO, O_WRONLY | O_NOFOLLOW); - check_one_fd (STDOUT_FILENO, O_RDONLY | O_NOFOLLOW); - check_one_fd (STDERR_FILENO, O_RDONLY | O_NOFOLLOW); + check_one_fd (STDIN_FILENO, O_WRONLY | O_NOFOLLOW | O_IGNORE_CTTY); + check_one_fd (STDOUT_FILENO, O_RDONLY | O_NOFOLLOW | O_IGNORE_CTTY); + check_one_fd (STDERR_FILENO, O_RDONLY | O_NOFOLLOW | O_IGNORE_CTTY); } diff --git a/elf/dl-load.c b/elf/dl-load.c index 9a0e40c0..009484f1 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -1616,7 +1616,7 @@ open_verify (const char *name, int fd, if (fd == -1) /* Open the file. We always open files read-only. */ - fd = __open64_nocancel (name, O_RDONLY | O_CLOEXEC); + fd = __open64_nocancel (name, O_RDONLY | O_CLOEXEC | O_IGNORE_CTTY); if (fd != -1) { diff --git a/elf/dl-misc.c b/elf/dl-misc.c index 5b84adc2..85931c7c 100644 --- a/elf/dl-misc.c +++ b/elf/dl-misc.c @@ -36,7 +36,7 @@ _dl_sysdep_read_whole_file (const char *file, size_t *sizep, int prot) { void *result = MAP_FAILED; struct __stat64_t64 st; - int fd = __open64_nocancel (file, O_RDONLY | O_CLOEXEC); + int fd = __open64_nocancel (file, O_RDONLY | O_CLOEXEC | O_IGNORE_CTTY); if (fd >= 0) { if (__fstat64_time64 (fd, &st) >= 0) diff --git a/elf/dl-profile.c b/elf/dl-profile.c index d8345da2..ff97b129 100644 --- a/elf/dl-profile.c +++ b/elf/dl-profile.c @@ -325,7 +325,7 @@ _dl_start_profile (void) __stpcpy (__stpcpy (cp, GLRO(dl_profile)), ".profile"); fd = __open64_nocancel (filename, O_RDWR | O_CREAT | O_NOFOLLOW - | O_CLOEXEC, DEFFILEMODE); + | O_CLOEXEC | O_IGNORE_CTTY, DEFFILEMODE); if (fd == -1) { char buf[400]; diff --git a/gmon/gmon.c b/gmon/gmon.c index 6439ed1c..ed13b3ce 100644 --- a/gmon/gmon.c +++ b/gmon/gmon.c @@ -385,13 +385,13 @@ write_gmon (void) char buf[len + 20]; __snprintf (buf, sizeof (buf), "%s.%u", env, __getpid ()); fd = __open_nocancel (buf, O_CREAT | O_TRUNC | O_WRONLY | O_NOFOLLOW - | O_CLOEXEC, 0666); + | O_CLOEXEC | O_IGNORE_CTTY, 0666); } if (fd == -1) { fd = __open_nocancel ("gmon.out", O_CREAT | O_TRUNC | O_WRONLY - | O_NOFOLLOW | O_CLOEXEC, 0666); + | O_NOFOLLOW | O_CLOEXEC | O_IGNORE_CTTY, 0666); if (fd < 0) { char buf[300]; diff --git a/iconv/gconv_cache.c b/iconv/gconv_cache.c index 87136e24..c8d972c8 100644 --- a/iconv/gconv_cache.c +++ b/iconv/gconv_cache.c @@ -58,7 +58,8 @@ __gconv_load_cache (void) return -1; /* See whether the cache file exists. */ - fd = __open_nocancel (GCONV_MODULES_CACHE, O_RDONLY | O_CLOEXEC, 0); + fd = __open_nocancel (GCONV_MODULES_CACHE, O_RDONLY + | O_CLOEXEC | O_IGNORE_CTTY, 0); if (__builtin_expect (fd, 0) == -1) /* Not available. */ return -1; diff --git a/locale/loadarchive.c b/locale/loadarchive.c index 5b857d5d..f88ff8b8 100644 --- a/locale/loadarchive.c +++ b/locale/loadarchive.c @@ -202,7 +202,8 @@ _nl_load_locale_from_archive (int category, const char **namep) archmapped = &headmap; /* The archive has never been opened. */ - fd = __open_nocancel (archfname, O_RDONLY|O_LARGEFILE|O_CLOEXEC); + fd = __open_nocancel (archfname, O_RDONLY | O_LARGEFILE + | O_CLOEXEC | O_IGNORE_CTTY); if (fd < 0) /* Cannot open the archive, for whatever reason. */ return NULL; @@ -397,8 +398,8 @@ _nl_load_locale_from_archive (int category, const char **namep) if (fd == -1) { struct __stat64_t64 st; - fd = __open_nocancel (archfname, - O_RDONLY|O_LARGEFILE|O_CLOEXEC); + fd = __open_nocancel (archfname, O_RDONLY | O_LARGEFILE + | O_CLOEXEC | O_IGNORE_CTTY); if (fd == -1) /* Cannot open the archive, for whatever reason. */ return NULL; diff --git a/locale/loadlocale.c b/locale/loadlocale.c index 671e71cf..582144ed 100644 --- a/locale/loadlocale.c +++ b/locale/loadlocale.c @@ -240,7 +240,7 @@ _nl_load_locale (struct loaded_l10nfile *file, int category) file->decided = 1; file->data = NULL; - fd = __open_nocancel (file->filename, O_RDONLY | O_CLOEXEC); + fd = __open_nocancel (file->filename, O_RDONLY | O_CLOEXEC | O_IGNORE_CTTY); if (__builtin_expect (fd, 0) < 0) /* Cannot open the file. */ return; @@ -267,7 +267,7 @@ _nl_load_locale (struct loaded_l10nfile *file, int category) "/SYS_", 5), _nl_category_names_get (category), _nl_category_name_sizes[category] + 1); - fd = __open_nocancel (newp, O_RDONLY | O_CLOEXEC); + fd = __open_nocancel (newp, O_RDONLY | O_CLOEXEC | O_IGNORE_CTTY); if (__builtin_expect (fd, 0) < 0) return; diff --git a/login/openpty.c b/login/openpty.c index 1e44852a..a89555b2 100644 --- a/login/openpty.c +++ b/login/openpty.c @@ -117,7 +117,7 @@ __openpty (int *pptmx, int *pterminal, char *name, if (pts_name (ptmx, &buf, sizeof (_buf))) goto on_error; - terminal = __open64 (buf, O_RDWR | O_NOCTTY); + terminal = __open64 (buf, O_RDWR | O_NOCTTY | O_IGNORE_CTTY); if (terminal == -1) goto on_error; } diff --git a/login/utmp_file.c b/login/utmp_file.c index 1ef07821..a7815096 100644 --- a/login/utmp_file.c +++ b/login/utmp_file.c @@ -142,7 +142,7 @@ __libc_setutent (void) file_writable = false; file_fd = __open_nocancel - (file_name, O_RDONLY | O_LARGEFILE | O_CLOEXEC); + (file_name, O_RDONLY | O_LARGEFILE | O_CLOEXEC | O_IGNORE_CTTY); if (file_fd == -1) return 0; } @@ -354,7 +354,7 @@ __libc_pututline (const struct utmp *data) const char *file_name = TRANSFORM_UTMP_FILE_NAME (__libc_utmp_file_name); int new_fd = __open_nocancel - (file_name, O_RDWR | O_LARGEFILE | O_CLOEXEC); + (file_name, O_RDWR | O_LARGEFILE | O_CLOEXEC | O_IGNORE_CTTY); if (new_fd == -1) return NULL; @@ -463,7 +463,8 @@ __libc_updwtmp (const char *file, const struct utmp *utmp) int fd; /* Open WTMP file. */ - fd = __open_nocancel (file, O_WRONLY | O_LARGEFILE | O_CLOEXEC); + fd = __open_nocancel (file, O_WRONLY | O_LARGEFILE + | O_CLOEXEC | O_IGNORE_CTTY); if (fd < 0) return -1; diff --git a/misc/daemon.c b/misc/daemon.c index 61da49b7..d5bf173f 100644 --- a/misc/daemon.c +++ b/misc/daemon.c @@ -67,7 +67,7 @@ daemon (int nochdir, int noclose) { struct __stat64_t64 st; - fd = __open_nocancel(_PATH_DEVNULL, O_RDWR, 0); + fd = __open_nocancel(_PATH_DEVNULL, O_RDWR | O_IGNORE_CTTY, 0); if (fd != -1 && __glibc_likely (__fstat64_time64 (fd, &st) == 0)) { if (__builtin_expect (S_ISCHR (st.st_mode), 1) != 0 diff --git a/nss/nss_db/db-open.c b/nss/nss_db/db-open.c index 13670600..c572d62c 100644 --- a/nss/nss_db/db-open.c +++ b/nss/nss_db/db-open.c @@ -36,7 +36,8 @@ internal_setent (const char *file, struct nss_db_map *mapping) { enum nss_status status = NSS_STATUS_UNAVAIL; - int fd = __open_nocancel (file, O_RDONLY | O_LARGEFILE | O_CLOEXEC); + int fd = __open_nocancel (file, O_RDONLY | O_LARGEFILE + | O_CLOEXEC | O_IGNORE_CTTY); if (fd != -1) { struct nss_db_header header; diff --git a/rt/shm_open.c b/rt/shm_open.c index fc1dc96b..7fd62cf3 100644 --- a/rt/shm_open.c +++ b/rt/shm_open.c @@ -37,7 +37,7 @@ __shm_open (const char *name, int oflag, mode_t mode) return -1; } - oflag |= O_NOFOLLOW | O_CLOEXEC; + oflag |= O_NOFOLLOW | O_CLOEXEC | O_IGNORE_CTTY; #if defined (SHM_ANON) && defined (O_TMPFILE) if (name == SHM_ANON) oflag |= O_TMPFILE; diff --git a/shadow/lckpwdf.c b/shadow/lckpwdf.c index 3b36b2eb..4a623c41 100644 --- a/shadow/lckpwdf.c +++ b/shadow/lckpwdf.c @@ -96,7 +96,7 @@ __lckpwdf (void) /* Prevent problems caused by multiple threads. */ __libc_lock_lock (lock); - int oflags = O_WRONLY | O_CREAT | O_CLOEXEC; + int oflags = O_WRONLY | O_CREAT | O_CLOEXEC | O_IGNORE_CTTY; lock_fd = __open (PWD_LOCKFILE, oflags, 0600); if (lock_fd == -1) /* Cannot create lock file. */ diff --git a/sysdeps/mach/hurd/opendir.c b/sysdeps/mach/hurd/opendir.c index cfba659c..a9e8f94d 100644 --- a/sysdeps/mach/hurd/opendir.c +++ b/sysdeps/mach/hurd/opendir.c @@ -79,7 +79,7 @@ __opendirat (int dfd, const char *name) return NULL; } - int flags = O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_CLOEXEC; + int flags = O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_CLOEXEC | O_IGNORE_CTTY; int fd; #if IS_IN (rtld) assert (dfd == AT_FDCWD); diff --git a/sysdeps/pthread/sem_open.c b/sysdeps/pthread/sem_open.c index e5db929d..5a248ebb 100644 --- a/sysdeps/pthread/sem_open.c +++ b/sysdeps/pthread/sem_open.c @@ -65,7 +65,7 @@ __sem_open (const char *name, int oflag, ...) /* If the semaphore object has to exist simply open it. */ if ((oflag & O_CREAT) == 0 || (oflag & O_EXCL) == 0) { - open_flags = O_RDWR | O_NOFOLLOW | O_CLOEXEC; + open_flags = O_RDWR | O_NOFOLLOW | O_CLOEXEC | O_IGNORE_CTTY; open_flags |= (oflag & ~(O_CREAT|O_ACCMODE)); try_again: fd = __open (dirname.name, open_flags); @@ -135,7 +135,7 @@ __sem_open (const char *name, int oflag, ...) } /* Open the file. Make sure we do not overwrite anything. */ - open_flags = O_RDWR | O_CREAT | O_EXCL | O_CLOEXEC; + open_flags = O_RDWR | O_CREAT | O_EXCL | O_CLOEXEC | O_IGNORE_CTTY; fd = __open (tmpfname, open_flags, mode); if (fd == -1) { diff --git a/sysdeps/unix/bsd/getpt.c b/sysdeps/unix/bsd/getpt.c index 8369f958..48f3d07a 100644 --- a/sysdeps/unix/bsd/getpt.c +++ b/sysdeps/unix/bsd/getpt.c @@ -76,7 +76,7 @@ __bsd_openpt (int oflag) int __getpt (void) { - return __bsd_openpt (O_RDWR); + return __bsd_openpt (O_RDWR | O_IGNORE_CTTY); } libc_hidden_def (__getpt) weak_alias (__getpt, getpt) @@ -84,6 +84,6 @@ weak_alias (__getpt, getpt) int __posix_openpt (int oflag) { - return __bsd_openpt (oflag); + return __bsd_openpt (oflag | O_IGNORE_CTTY); } weak_alias (__posix_openpt, posix_openpt)