From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by sourceware.org (Postfix) with ESMTPS id E1FAD385842B for ; Wed, 29 Nov 2023 16:54:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E1FAD385842B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E1FAD385842B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::629 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701276884; cv=none; b=Hp8n7dRw9CwXmpBh8g/77QNT+9lYIVSKwzdO3YlDRyQty5+VdnCbpHfYZHPc+Vbx00C1VpLu7UZa697kmRxf934NGXIEjfglw0HyRNPHEd9eljSSK8bfeS6AeVSY2ie8JBhO0TocFn//TpTIMXvN/hN/xyNQiKeEBOkPzwOsMMU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701276884; c=relaxed/simple; bh=fywtRYE4GQdnDMxfjiHTkNrpuo6NkCDTOl7T0qp5QBg=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:From:To; b=W7RWMtco+MSMGbqh1GwIFuXPyHWCa5SOFGlJnLFL9JJuOhWdRDjmY8QUfzcAnBzdrYlFd2PF6aWV/m1eV1Kri9IFoKboozqXjMHkxIlmjUtl3RtjDULF/fObm1MhEU5XT7DkjFlY6qJ/bkUh2Ej30JyYUceRFxu7OwywflF0QVs= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1cfc1512df1so31115965ad.2 for ; Wed, 29 Nov 2023 08:54:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1701276879; x=1701881679; darn=sourceware.org; h=content-transfer-encoding:in-reply-to:organization:references:to :from:content-language:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=jBHcwEZBtQSpjk85E3L4MIiW80xAWu2PLKjPJHHv6Eo=; b=wF7VLtaBIFFoOckGD10BeGnbWStTaWZ5qCaXXKbS6RlaCP6ocWpOq1Vw/j/Jdf4A+c YQl7F6G0RkM2aKpnSySEa45TIiFWNvnBY4aSPTUY4HXp5JwP6ASGEpq8oDB11rg86bC7 hZZ7WeTvgQuAqN9C+6lYnBoqwV1b1c4J41+3PE17fZ4HOdX5FezgyadeFnSS8511cazy 5bjf3bb8ppJYoclYh5/i0Mv/UVUjq6uaixYUXpNjM9nVqN+zaYQJCUCA3tOUZYdm7JDl 1IpNJRPiaJTkArR+n++TxrN4Ztl5xaas0gh6s8njxc5SkoMjR1lS8oU/z+AnfcY3RPlc +MVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701276879; x=1701881679; h=content-transfer-encoding:in-reply-to:organization:references:to :from:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=jBHcwEZBtQSpjk85E3L4MIiW80xAWu2PLKjPJHHv6Eo=; b=Zsz1R9D1x/NANTjixmvMp+4v0p/lAoAVfRlhmTTRmPbiavg7lmd1/EeCGOVNief010 KW2oJkyPAojuEfCpIRDOQxetvxUDyaZ7pfH97mfQNslztMrG+g6VJhfEcyr8sB0uEmOe dyC0KS9/VLSv0pkxZbwBYUMvSyFBWCddD3gzdAsTx9Zf7Aq4FS7mbijOBgBC2kJBjFa+ fu7zAa7aOLVAUQQaSHO59CPZvRXh4owP1cp/qjpaEwng+45mp6vcDofYk45Qnkr5ls7Z U9xxrRvJwEZdLElNq/a5Hyyx8gXnAepxugc7SVHuyJgJK6rIM3yiSgeGAb51yPgcL7lE 0O/Q== X-Gm-Message-State: AOJu0Yz3wLbRhrGc5+Kw8Jz2CCIrnsgwogs95LFDhzte0Zv3VqNPHArX 1DinJswZcmlG8nxtLSpgS0qywgtbCfFsGdureen7Ig== X-Google-Smtp-Source: AGHT+IFlsl4JBTCyS44VrJwKEHbux/G8Vn8ehfrXu8nLi534hcV1RU/Mp8NevKctdIY3WY6jD+P8YA== X-Received: by 2002:a17:902:c1d5:b0:1cc:45df:4710 with SMTP id c21-20020a170902c1d500b001cc45df4710mr17838951plc.40.1701276878688; Wed, 29 Nov 2023 08:54:38 -0800 (PST) Received: from ?IPV6:2804:1b3:a7c2:bcdb:cd60:ab60:c05:7aa0? ([2804:1b3:a7c2:bcdb:cd60:ab60:c05:7aa0]) by smtp.gmail.com with ESMTPSA id f10-20020a170902ce8a00b001b7fd27144dsm10620132plg.40.2023.11.29.08.54.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 Nov 2023 08:54:37 -0800 (PST) Message-ID: <8abd7c2b-c519-4c96-b089-10f9f974dacc@linaro.org> Date: Wed, 29 Nov 2023 13:54:35 -0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] linux: Make fdopendir fail with O_PATH (BZ 30373) Content-Language: en-US From: Adhemerval Zanella Netto To: libc-alpha@sourceware.org, Paul Eggert References: <20230901122651.59253-1-adhemerval.zanella@linaro.org> <6629b456-24f6-4dc5-a04a-16d7daf5206f@linaro.org> Organization: Linaro In-Reply-To: <6629b456-24f6-4dc5-a04a-16d7daf5206f@linaro.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,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 List-Id: On 02/10/23 08:09, Adhemerval Zanella Netto wrote: > > > On 01/09/23 09:26, Adhemerval Zanella wrote: >> It is not strictly required by the POSIX, since O_PATH is a Linux >> extension, but it is QoI to fail early instead of at readdir. Also >> the check is free, since fdopendir already checks if the file >> descriptor is opened for read. >> >> Checked on x86_64-linux-gnu. > > Ping. Ping (x2). > >> --- >> sysdeps/unix/sysv/linux/Makefile | 1 + >> sysdeps/unix/sysv/linux/fdopendir.c | 8 +++- >> .../unix/sysv/linux/tst-fdopendir-o_path.c | 48 +++++++++++++++++++ >> 3 files changed, 56 insertions(+), 1 deletion(-) >> create mode 100644 sysdeps/unix/sysv/linux/tst-fdopendir-o_path.c >> >> diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile >> index be801e3be4..ec0ba3eb05 100644 >> --- a/sysdeps/unix/sysv/linux/Makefile >> +++ b/sysdeps/unix/sysv/linux/Makefile >> @@ -199,6 +199,7 @@ tests += \ >> tst-clone3 \ >> tst-epoll \ >> tst-fanotify \ >> + tst-fdopendir-o_path \ >> tst-getauxval \ >> tst-gettid \ >> tst-gettid-kill \ >> diff --git a/sysdeps/unix/sysv/linux/fdopendir.c b/sysdeps/unix/sysv/linux/fdopendir.c >> index 861345396c..707fb5960e 100644 >> --- a/sysdeps/unix/sysv/linux/fdopendir.c >> +++ b/sysdeps/unix/sysv/linux/fdopendir.c >> @@ -37,10 +37,16 @@ __fdopendir (int fd) >> return NULL; >> } >> >> - /* Make sure the descriptor allows for reading. */ >> int flags = __fcntl64_nocancel (fd, F_GETFL); >> if (__glibc_unlikely (flags == -1)) >> return NULL; >> + /* Fail early for descriptors opened with O_PATH. */ >> + if (__glibc_unlikely (flags & O_PATH)) >> + { >> + __set_errno (EBADF); >> + return NULL; >> + } >> + /* Make sure the descriptor allows for reading. */ >> if (__glibc_unlikely ((flags & O_ACCMODE) == O_WRONLY)) >> { >> __set_errno (EINVAL); >> diff --git a/sysdeps/unix/sysv/linux/tst-fdopendir-o_path.c b/sysdeps/unix/sysv/linux/tst-fdopendir-o_path.c >> new file mode 100644 >> index 0000000000..2531cf8ddb >> --- /dev/null >> +++ b/sysdeps/unix/sysv/linux/tst-fdopendir-o_path.c >> @@ -0,0 +1,48 @@ >> +/* Check if fdopendir fails with file descriptor opened with O_PATH (BZ 30737) >> + Copyright (C) 2023 Free Software Foundation, Inc. >> + This file is part of the GNU C Library. >> + >> + The GNU C Library is free software; you can redistribute it and/or >> + modify it under the terms of the GNU Lesser General Public >> + License as published by the Free Software Foundation; either >> + version 2.1 of the License, or (at your option) any later version. >> + >> + The GNU C Library is distributed in the hope that it will be useful, >> + but WITHOUT ANY WARRANTY; without even the implied warranty of >> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU >> + Lesser General Public License for more details. >> + >> + You should have received a copy of the GNU Lesser General Public >> + License along with the GNU C Library; if not, see >> + . */ >> + >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> + >> +static int >> +do_test (void) >> +{ >> + char *dirname = support_create_temp_directory ("tst-fdopendir-o_path"); >> + >> + { >> + int fd = xopen (dirname, O_RDONLY | O_DIRECTORY, 0600); >> + DIR *dir = fdopendir (fd); >> + TEST_VERIFY_EXIT (dir != NULL); >> + closedir (dir); >> + } >> + >> + { >> + int fd = xopen (dirname, O_RDONLY | O_PATH | O_DIRECTORY, 0600); >> + TEST_VERIFY (fdopendir (fd) == NULL); >> + TEST_COMPARE (errno, EBADF); >> + xclose (fd); >> + } >> + >> + return 0; >> +} >> + >> +#include