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: AS17314 8.43.84.0/22 X-Spam-Status: No, score=-3.7 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RDNS_DYNAMIC,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (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 240791F8C6 for ; Wed, 25 Aug 2021 03:42:02 +0000 (UTC) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E670B385841E for ; Wed, 25 Aug 2021 03:42:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E670B385841E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1629862920; bh=Iew+LGIOFxWGjoIw5Y+0BxTWKvNUd/evTK87lKkA6Bw=; 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=Ckbw85Zpf1oSEbmZVZqHSfxZdpuRLkP6L9hZR2chq3t4xd2AKo6x+UPy77PTyBANt pgCCOXLU5FdVI3WegfOuKZ5M4V+/7KLxnSgOUQD3ohc2BPFvWeUdEDG/Gk6kaFi/5O idJpyp1YumJPsyBEnAxtTdoPYlInoE2tI1Wa/qP4= 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 8F5083858401 for ; Wed, 25 Aug 2021 03:41:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8F5083858401 Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) (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 8C494406F4 for ; Wed, 25 Aug 2021 03:41:30 +0000 (UTC) Received: by mail-pf1-f198.google.com with SMTP id x18-20020a056a000bd200b003e14701b71dso11166781pfu.21 for ; Tue, 24 Aug 2021 20:41:30 -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=HmzaNYkE+fW+lJH6qV+G9JcgkmkrvHOiLN/VdBdBY7w=; b=YfacwzBDx9tPfYUvPzDADzqw+2KFKcyVozLVSDwd4owqLpv/o8i+7hFqC29wfsB0Is /gBxIiTlORtRUoOFtskPTIgJWupfwz9u9o+xum51gKILmZ3w+u08xPGj3em4Hu72kM2/ AtX1ZSNxkxwR/onDGNiCMe+qIjTNZbfrBMCNjeP2pjAj6hcmk3WecmnVvqfj55Csm4EV a4O/YicxGJe5GnUaKos0dNwZAq1vpD2ymuZzzLw0KaMJAeiaF2MoFA7BfzELTd8tGGtj q0OeIeXKCqWi7wpao+KQnARBA8Vuny017NwZsGb39zhVwFQcgU4IJbgMtsrZAyI8CLr5 D4Jg== X-Gm-Message-State: AOAM532oCAgXwzhSnDhuqzkWU3OwHWep6HuGFKw/gJclD1itUWCnT2eg jayo/k0jt7Xx5vh+etScjPHiOL+QHFnaZ0BXTVgcQP4Y4bIIT63yYa7/BIMfjzvvTXq+Eijk0Dp OEQB3uHkiFOU4cGzHZTnBLs0IRfOhmDiV2XOv6RBU5IR6FDq0bckulA== X-Received: by 2002:a63:131f:: with SMTP id i31mr39874897pgl.207.1629862888441; Tue, 24 Aug 2021 20:41:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyLfT9LeK8+sVheWNXnQQT2xwi28ALkTfYUaJeMNSRFE8Mz5l+oTK8qg2r2OiJFLavtnHb4T5SM2jJqt+Pr5e0= X-Received: by 2002:a63:131f:: with SMTP id i31mr39874881pgl.207.1629862888069; Tue, 24 Aug 2021 20:41:28 -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 15:41:16 +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="0000000000007a27f605ca5a065d" 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" --0000000000007a27f605ca5a065d Content-Type: text/plain; charset="UTF-8" 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 X-Attachment-Id: f_ksqy9bgk0 LS0tIGEvaW8vdHN0LWNsb3NlZnJvbS5jCisrKyBiL2lvL3RzdC1jbG9zZWZyb20uYwpAQCAtMzks NyArMzksNyBAQAogCiAgIGNvbnN0IGludCBtYXhpbXVtX2ZkID0gbG93ZmQgKyBORkRTIC0gMTsK ICAgY29uc3QgaW50IGhhbGZfZmQgPSBsb3dmZCArIE5GRFMgLyAyOwotICBjb25zdCBpbnQgZ2Fw ID0gbWF4aW11bV9mZCAvIDQ7CisgIGNvbnN0IGludCBnYXAgPSBsb3dmZCArIE5GRFMgLyA0Owog CiAgIC8qIENsb3NlIGhhbGYgb2YgdGhlI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