From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS3215 2.6.0.0/16 X-Spam-Status: No, score=-4.2 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 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 dcvr.yhbt.net (Postfix) with ESMTPS id E02AF1F8C6 for ; Wed, 25 Aug 2021 08:41:59 +0000 (UTC) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2F0843857416 for ; Wed, 25 Aug 2021 08:41:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2F0843857416 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1629880918; bh=lszEshaPhprVywkmXpOR5suTewv/uCI200OzDv9tGXk=; h=References:In-Reply-To:Date:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=b7VevX+QmbaNjevqA02i+qpCR0y4JbPcrShEVg2SWfIYC4DrYk/G6GnmhegkuSgQL whew8lA1BCe3YdxJz2484CG7NfnROwdx/uKvWGjlzMgz+Kvo9n2xzpG2jLHBd0rIUT O7x0gWeW5XlwprTtYSNdntnFrXTx39tAm+5e01g8= Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) by sourceware.org (Postfix) with ESMTPS id 5E8A33858432 for ; Wed, 25 Aug 2021 08:40:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5E8A33858432 Received: from mail-pj1-f71.google.com (mail-pj1-f71.google.com [209.85.216.71]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 60C583F22C for ; Wed, 25 Aug 2021 08:40:26 +0000 (UTC) Received: by mail-pj1-f71.google.com with SMTP id h9-20020a17090a470900b001791c0352aaso8272314pjg.2 for ; Wed, 25 Aug 2021 01:40:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=UY+d2paVJHWPjOWyga+TX/gu+FikVyIKlUBDSaCckUc=; b=dndGRe13b86XjtGcP8icxIm1oEjZZ9WXy/SWsTmSuiaAZa/8C6B/4UvU2oHHQZyeP1 Owh5HHsc1zv0afj+UMwUv/VgRxqeAEFMk/OYe2QO0W2VhKHdiONAVcm4jDChXu0F2z41 QDJ7e6/BP3GxbexdqHpTPQZ2Kx0lbwBH75onOA7W/30FRqNoUynyMo1SkuaGoQFWZuYD KQbyix2JLVq2auKeXnfnohubZMnjRFF7ovSOy4JC/Ny0Z+GP1taJgVIrc03PxaFaI1p5 fmrB6fopmuboTDmZqd9DEvBfz9VYLTc9OiyHewThn+ROA7h77rtGa8X3RXiFXEF29OX/ XymQ== X-Gm-Message-State: AOAM532iooZ5Qimr9a9F8su8EuKQg3nA4LmpMg9vtALXOa5xpsuO2MAq cIlGDZBOxogOptCciAFR0zbadsgJE+jrAaYvNXR1EbNzN9XJ3GiGTxiTKuq8nwmHWtOEQLKF6wG xyq0HAnqZcCcqW0HKlIBHq2dGWUuIOqGcVUcdqgL/ysd3fFKOohBZzw== X-Received: by 2002:a62:1888:0:b029:3c9:7957:519b with SMTP id 130-20020a6218880000b02903c97957519bmr43334831pfy.17.1629880824401; Wed, 25 Aug 2021 01:40:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxCezmSgLkcWZtTrbc2PYIHdNNWbJxGyZykE3E9cHOAtJ80yJKQhDeeGcADep8vq7xUFNnA26WAnWXAWEsfTOU= X-Received: by 2002:a62:1888:0:b029:3c9:7957:519b with SMTP id 130-20020a6218880000b02903c97957519bmr43334808pfy.17.1629880824008; Wed, 25 Aug 2021 01:40:24 -0700 (PDT) MIME-Version: 1.0 References: <20210824192858.681680-1-adhemerval.zanella@linaro.org> <20210824192858.681680-3-adhemerval.zanella@linaro.org> In-Reply-To: Date: Wed, 25 Aug 2021 20:40:12 +1200 Message-ID: Subject: Re: [PATCH 2/2] Use support_open_dev_null_range io/tst-closefrom, misc/tst-close_range, and posix/tst-spawn5 (BZ #28260) To: Adhemerval Zanella Content-Type: multipart/mixed; boundary="0000000000008ac81b05ca5e334c" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 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: , From: Michael Hudson-Doyle via Libc-alpha Reply-To: Michael Hudson-Doyle Cc: libc-alpha@sourceware.org Errors-To: libc-alpha-bounces+e=80x24.org@sourceware.org Sender: "Libc-alpha" --0000000000008ac81b05ca5e334c Content-Type: text/plain; charset="UTF-8" I found some more problems, updated patch attached. On Wed, 25 Aug 2021 at 15:41, Michael Hudson-Doyle < michael.hudson@canonical.com> wrote: > > > On Wed, 25 Aug 2021 at 15:15, Michael Hudson-Doyle < > michael.hudson@canonical.com> wrote: > >> Hi, thanks for looking at this. >> >> On Wed, 25 Aug 2021 at 07:29, Adhemerval Zanella via Libc-alpha < >> libc-alpha@sourceware.org> wrote: >> >>> It ensures a continuous range of file descriptor and avoid hitting >>> the RLIMIT_NOFILE. >>> >>> Checked on x86_64-linux-gnu. >>> --- >>> io/tst-closefrom.c | 15 +++----------- >>> posix/tst-spawn5.c | 13 +----------- >>> sysdeps/unix/sysv/linux/tst-close_range.c | 25 +++++++---------------- >>> 3 files changed, 11 insertions(+), 42 deletions(-) >>> >>> diff --git a/io/tst-closefrom.c b/io/tst-closefrom.c >>> index d4c187073c..0800e19f3f 100644 >>> --- a/io/tst-closefrom.c >>> +++ b/io/tst-closefrom.c >>> @@ -24,29 +24,20 @@ >>> #include >>> #include >>> #include >>> +#include >>> >>> #include >>> >>> #define NFDS 100 >>> >>> -static int >>> -open_multiple_temp_files (void) >>> -{ >>> - /* Check if the temporary file descriptor has no no gaps. */ >>> - int lowfd = xopen ("/dev/null", O_RDONLY, 0600); >>> - for (int i = 1; i <= NFDS; i++) >>> - TEST_COMPARE (xopen ("/dev/null", O_RDONLY, 0600), lowfd + i); >>> - return lowfd; >>> -} >>> - >>> static int >>> closefrom_test (void) >>> { >>> struct support_descriptors *descrs = support_descriptors_list (); >>> >>> - int lowfd = open_multiple_temp_files (); >>> + int lowfd = support_open_dev_null_range (NFDS, O_RDONLY, 0600); >>> >>> - const int maximum_fd = lowfd + NFDS; >>> + const int maximum_fd = lowfd + NFDS - 1; >>> const int half_fd = lowfd + NFDS / 2; >>> const int gap = maximum_fd / 4; >>> >> >> There are two for loops in this function that iterate from 0: >> >> for (int i = 0; i < half_fd; i++) >> TEST_VERIFY (fcntl (i, F_GETFL) > -1); >> >> for (int i = 0; i < gap; i++) >> TEST_VERIFY (fcntl (i, F_GETFL) > -1); >> >> These should both iterate from i = lowfd I think? (And maybe should have >> done before this change?) Certainly they fail in the cases this patch is >> trying to fix. >> >> diff --git a/posix/tst-spawn5.c b/posix/tst-spawn5.c >>> index ac66738004..a95199af6b 100644 >>> --- a/posix/tst-spawn5.c >>> +++ b/posix/tst-spawn5.c >>> @@ -47,17 +47,6 @@ static int initial_argv_count; >>> >>> #define NFDS 100 >>> >>> -static int >>> -open_multiple_temp_files (void) >>> -{ >>> - /* Check if the temporary file descriptor has no no gaps. */ >>> - int lowfd = xopen ("/dev/null", O_RDONLY, 0600); >>> - for (int i = 1; i <= NFDS; i++) >>> - TEST_COMPARE (xopen ("/dev/null", O_RDONLY, 0600), >>> - lowfd + i); >>> - return lowfd; >>> -} >>> - >>> static int >>> parse_fd (const char *str) >>> { >>> @@ -185,7 +174,7 @@ spawn_closefrom_test (posix_spawn_file_actions_t >>> *fa, int lowfd, int highfd, >>> static void >>> do_test_closefrom (void) >>> { >>> - int lowfd = open_multiple_temp_files (); >>> + int lowfd = support_open_dev_null_range (NFDS, O_RDONLY, 0600); >>> const int half_fd = lowfd + NFDS / 2; >>> >>> /* Close half of the descriptors and check result. */ >>> diff --git a/sysdeps/unix/sysv/linux/tst-close_range.c >>> b/sysdeps/unix/sysv/linux/tst-close_range.c >>> index dccb6189c5..3548b10363 100644 >>> --- a/sysdeps/unix/sysv/linux/tst-close_range.c >>> +++ b/sysdeps/unix/sysv/linux/tst-close_range.c >>> >> >> This for look in close_range_unshare_test in this file needs to change >> too: >> >> for (int i = 0; i < NFDS; i++) >> TEST_VERIFY (fcntl (i, F_GETFL) > -1); >> >> (presumably to iterate from low_fd to lowfd + NFDS). >> >> >>> @@ -36,23 +36,12 @@ >>> >>> #define NFDS 100 >>> >>> -static int >>> -open_multiple_temp_files (void) >>> -{ >>> - /* Check if the temporary file descriptor has no no gaps. */ >>> - int lowfd = xopen ("/dev/null", O_RDONLY, 0600); >>> - for (int i = 1; i <= NFDS; i++) >>> - TEST_COMPARE (xopen ("/dev/null", O_RDONLY, 0600), >>> - lowfd + i); >>> - return lowfd; >>> -} >>> - >>> static void >>> close_range_test_max_upper_limit (void) >>> { >>> struct support_descriptors *descrs = support_descriptors_list (); >>> >>> - int lowfd = open_multiple_temp_files (); >>> + int lowfd = support_open_dev_null_range (NFDS, O_RDONLY, 0600); >>> >>> { >>> int r = close_range (lowfd, ~0U, 0); >>> @@ -68,7 +57,7 @@ close_range_test_max_upper_limit (void) >>> static void >>> close_range_test_common (int lowfd, unsigned int flags) >>> { >>> - const int maximum_fd = lowfd + NFDS; >>> + const int maximum_fd = lowfd + NFDS - 1; >>> const int half_fd = lowfd + NFDS / 2; >>> const int gap_1 = maximum_fd - 8; >>> >>> @@ -121,7 +110,7 @@ close_range_test (void) >>> struct support_descriptors *descrs = support_descriptors_list (); >>> >>> /* Check if the temporary file descriptor has no no gaps. */ >>> - int lowfd = open_multiple_temp_files (); >>> + int lowfd = support_open_dev_null_range (NFDS, O_RDONLY, 0600); >>> >>> close_range_test_common (lowfd, 0); >>> >>> @@ -146,7 +135,7 @@ close_range_test_subprocess (void) >>> struct support_descriptors *descrs = support_descriptors_list (); >>> >>> /* Check if the temporary file descriptor has no no gaps. */ >>> - int lowfd = open_multiple_temp_files (); >>> + int lowfd = support_open_dev_null_range (NFDS, O_RDONLY, 0600); >>> >>> struct support_stack stack = support_stack_alloc (4096); >>> >>> @@ -184,7 +173,7 @@ close_range_unshare_test (void) >>> struct support_descriptors *descrs1 = support_descriptors_list (); >>> >>> /* Check if the temporary file descriptor has no no gaps. */ >>> - int lowfd = open_multiple_temp_files (); >>> + int lowfd = support_open_dev_null_range (NFDS, O_RDONLY, 0600); >>> >>> struct support_descriptors *descrs2 = support_descriptors_list (); >>> >>> @@ -226,9 +215,9 @@ static void >>> close_range_cloexec_test (void) >>> { >>> /* Check if the temporary file descriptor has no no gaps. */ >>> - const int lowfd = open_multiple_temp_files (); >>> + int lowfd = support_open_dev_null_range (NFDS, O_RDONLY, 0600); >>> >>> - const int maximum_fd = lowfd + NFDS; >>> + const int maximum_fd = lowfd + NFDS - 1; >>> const int half_fd = lowfd + NFDS / 2; >>> const int gap_1 = maximum_fd - 8; >>> >>> -- >>> 2.30.2 >>> >> >> Cheers, >> mwh >> > > I'm attaching a patch which when applied on top of this one makes these > tests pass my hackish way of reproducing the issue: > > mwhudson@anduril:~/src/pkg/build-glibc$ bash -c 'exec 40 LD_LIBRARY_PATH=. ./elf/ld-linux-x86-64.so.2 ./misc/tst-close_range' > mwhudson@anduril:~/src/pkg/build-glibc$ bash -c 'exec 40 LD_LIBRARY_PATH=. ./elf/ld-linux-x86-64.so.2 ./io/tst-closefrom' > > Cheers, > mwh > --0000000000008ac81b05ca5e334c Content-Type: text/x-patch; charset="US-ASCII"; name="mwhudson.patch" Content-Disposition: attachment; filename="mwhudson.patch" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_ksr8y93y0 LS0tIGEvaW8vdHN0LWNsb3NlZnJvbS5jCisrKyBiL2lvL3RzdC1jbG9zZWZyb20uYwpAQCAtMzks NyArMzksNyBAQAogCiAgIGNvbnN0IGludCBtYXhpbXVtX2ZkID0gbG93ZmQgKyBORkRTIC0gMTsK ICAgY29uc3QgaW50IGhhbGZfZmQgPSBsb3dmZCArIE5GRFMgLyAyOwotICBjb25zdCBpbnQgZ2Fw ID0gbWF4aW11bV9mZCAvIDQ7CisgIGNvbnN0IGludCBnYXAgPSBsb3dmZCArIE5GRFMgLyA0Owog CiAgIC8qIENsb3NlIGhhbGYgb2YgdGhlIGRlc2NyaXB0b3JzIGFuZCBjaGVjayByZXN1bHQuICAq LwogICBjbG9zZWZyb20gKGhhbGZfZmQpOwpAQCAtNDksNyArNDksNyBAQAogICAgICAgVEVTVF9D T01QQVJFIChmY250bCAoaSwgRl9HRVRGTCksIC0xKTsKICAgICAgIFRFU1RfQ09NUEFSRSAoZXJy bm8sIEVCQURGKTsKICAgICB9Ci0gIGZvciAoaW50IGkgPSAwOyBpIDwgaGFsZl9mZDsgaSsrKQor ICBmb3IgKGludCBpID0gbG93ZmQ7IGkgPCBoYWxmX2ZkOyBpKyspCiAgICAgVEVTVF9WRVJJRlkg KGZjbnRsIChpLCBGX0dFVEZMKSA+IC0xKTsKIAogICAvKiBDcmVhdGUgc29tZSBnYXBzLCBjbG9z ZSB1cCB0byBhIHRocmVzaG9sZCwgYW5kIGNoZWNrIHJlc3VsdC4gICovCkBAIC02NSw3ICs2NSw3 IEBACiAgICAgIC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