From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 719383852744 for ; Mon, 18 Jul 2022 12:59:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 719383852744 Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-580-pKqGdFx0OPetCz1yswFy_g-1; Mon, 18 Jul 2022 08:59:19 -0400 X-MC-Unique: pKqGdFx0OPetCz1yswFy_g-1 Received: by mail-qv1-f69.google.com with SMTP id ld6-20020a056214418600b00472ffe4640eso5445335qvb.13 for ; Mon, 18 Jul 2022 05:59:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:organization:in-reply-to :content-transfer-encoding; bh=Zekktdnx0HWkwJwPGxu/ZGtkBAAXoNCIdXKP/LS8bPU=; b=0nDjoTV4l7KNKPrRIHrp/Cw29emOjYWk8hWwIHBoXElNH/G1CpMjAl8IUsfYtUo4V+ g/kSAKSxxry8IhY/brgDiE4QPsZunwwCOHgvHeH90pR9J3ULzXtFhw/asvxIrH6dgp0J PwIihovqNbZ+tljfW8lRFIf0TURHQZG8N2YhtTSbKsNKt3vboYMRCOto1pKBrOQAMHgf RtbIFfwSoOVSyRMB6k0no/vj+mc53IN1UwVkmmGpyHPtDeOCGwCINvNQMIMSWSmN1U6c LN0LVlOG1zZAD6FX9/Bp/6uFN6NeboYyciTjxw4YpUngSTZhJashjj8ezaNoqsR0Rqzx 3R7Q== X-Gm-Message-State: AJIora9WOWrMDU2bU9TBpcbnld1P4Sjr5b7E2n7IbLEMvwYLw0FAN5rN cfD/ToHCX4paHLlmLD0/bNckQ1qOxbnQOFJIPPJBg0CDfbBfYA67anJGcETzZH2jKC1DBI7h830 /ZRc2AeIK47rskJT8583K X-Received: by 2002:a05:622a:1183:b0:31e:f639:ca15 with SMTP id m3-20020a05622a118300b0031ef639ca15mr1292953qtk.462.1658149158371; Mon, 18 Jul 2022 05:59:18 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vGeS0i4VcoW49pgoXzxK2wug4hRELDDOrcWCQweAhxCSM43Qd52i08rDHXqUwF5kGlCn69lw== X-Received: by 2002:a05:622a:1183:b0:31e:f639:ca15 with SMTP id m3-20020a05622a118300b0031ef639ca15mr1292945qtk.462.1658149158103; Mon, 18 Jul 2022 05:59:18 -0700 (PDT) Received: from [192.168.0.241] (192-0-145-146.cpe.teksavvy.com. [192.0.145.146]) by smtp.gmail.com with ESMTPSA id x18-20020a05620a449200b006b5988b2ca8sm11859963qkp.40.2022.07.18.05.59.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 18 Jul 2022 05:59:17 -0700 (PDT) Message-ID: <1bdca5bc-8b4d-dc09-19ea-7bb8d9735ef7@redhat.com> Date: Mon, 18 Jul 2022 08:59:16 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH v3] linux: return UNSUPPORTED from tst-mount if entering mount namespace fails To: Michael Hudson-Doyle , libc-alpha@sourceware.org References: <20220715000657.1712606-1-michael.hudson@canonical.com> <20220717231657.1269920-1-michael.hudson@canonical.com> From: Carlos O'Donell Organization: Red Hat In-Reply-To: <20220717231657.1269920-1-michael.hudson@canonical.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP 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-List-Received-Date: Mon, 18 Jul 2022 12:59:21 -0000 On 7/17/22 19:16, Michael Hudson-Doyle via Libc-alpha wrote: > Before this the test fails if run in a chroot by a non-root user: LGTM. OK for glibc 2.36. Would you like me to push this for you? Reviewed-by: Carlos O'Donell > warning: could not become root outside namespace (Operation not permitted) > ../sysdeps/unix/sysv/linux/tst-mount.c:36: numeric comparison failure > left: 1 (0x1); from: errno > right: 19 (0x13); from: ENODEV > error: ../sysdeps/unix/sysv/linux/tst-mount.c:39: not true: fd != -1 > error: ../sysdeps/unix/sysv/linux/tst-mount.c:46: not true: r != -1 > error: ../sysdeps/unix/sysv/linux/tst-mount.c:48: not true: r != -1 > ../sysdeps/unix/sysv/linux/tst-mount.c:52: numeric comparison failure > left: 1 (0x1); from: errno > right: 9 (0x9); from: EBADF > error: ../sysdeps/unix/sysv/linux/tst-mount.c:55: not true: mfd != -1 > ../sysdeps/unix/sysv/linux/tst-mount.c:58: numeric comparison failure > left: 1 (0x1); from: errno > right: 2 (0x2); from: ENOENT > error: ../sysdeps/unix/sysv/linux/tst-mount.c:61: not true: r != -1 > ../sysdeps/unix/sysv/linux/tst-mount.c:65: numeric comparison failure > left: 1 (0x1); from: errno > right: 2 (0x2); from: ENOENT > error: ../sysdeps/unix/sysv/linux/tst-mount.c:68: not true: pfd != -1 > error: ../sysdeps/unix/sysv/linux/tst-mount.c:75: not true: fd_tree != -1 > ../sysdeps/unix/sysv/linux/tst-mount.c:88: numeric comparison failure > left: 1 (0x1); from: errno > right: 38 (0x26); from: ENOSYS > error: 12 test failures > > Checking that the test can enter a new mount namespace is more correct > than just checking the return value of support_become_root() as the test > code changes the mount namespace it runs in so running it as root on a > system that does not support mount namespaces should still skip. Agreed. > > Also change the test to remove the unnecessary fork. > --- > v3: check support_enter_mount_namespace() return value, remove fork > v2: check support_can_chroot() rather than support_become_root return > value > --- > sysdeps/unix/sysv/linux/tst-mount.c | 25 ++++++------------------- > 1 file changed, 6 insertions(+), 19 deletions(-) > > diff --git a/sysdeps/unix/sysv/linux/tst-mount.c b/sysdeps/unix/sysv/linux/tst-mount.c > index 502d7e3433..b6333a60e6 100644 > --- a/sysdeps/unix/sysv/linux/tst-mount.c > +++ b/sysdeps/unix/sysv/linux/tst-mount.c > @@ -20,15 +20,18 @@ > #include > #include > #include > -#include OK. > #include > > _Static_assert (sizeof (struct mount_attr) == MOUNT_ATTR_SIZE_VER0, > "sizeof (struct mount_attr) != MOUNT_ATTR_SIZE_VER0"); > > -static void > -subprocess (void) > +static int > +do_test (void) OK. > { > + support_become_root (); > + if (!support_enter_mount_namespace ()) > + FAIL_UNSUPPORTED ("cannot enter mount namespace, skipping test"); OK. > + > int r = fsopen ("it_should_be_not_a_valid_mount", 0); > TEST_VERIFY_EXIT (r == -1); > if (errno == ENOSYS) > @@ -100,20 +103,4 @@ subprocess (void) > _exit (0); > } > > -static int > -do_test (void) > -{ > - support_become_root (); > - > - pid_t pid = xfork (); > - if (pid == 0) > - subprocess (); > - > - int status; > - xwaitpid (pid, &status, 0); > - TEST_VERIFY (WIFEXITED (status)); > - > - return 0; > -} > - > #include -- Cheers, Carlos.