From patchwork Thu Aug 22 10:40:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 1975432 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=MvUve0go; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WqKVg3Csjz1ybW for ; Thu, 22 Aug 2024 20:40:59 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id ADF52387100E for ; Thu, 22 Aug 2024 10:40:57 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 56ADB3870C24 for ; Thu, 22 Aug 2024 10:40:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 56ADB3870C24 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 56ADB3870C24 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724323223; cv=none; b=Z2Cf9OL5vAywDUSWdRNrPbcXs/zMcpRAsWQhgzqNbGNUOPTgD8Wbg8D6g3XasZbTBRNT5nByu1oWU2ggJc4BY2XyEoKOYbAyieT9O8mjyyG+MDbhUl4v/Y/xDpNjkjkDAvmvkM9qGlyn730lh+j9GFz9zXnrBwBf+J9vALLsvJg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724323223; c=relaxed/simple; bh=LtCqmHfD7G9VHIjJA9IuMezVRYWFkT9IVf3KEedsmqI=; h=DKIM-Signature:From:To:Subject:Message-ID:Date:MIME-Version; b=xITP+AT2k9MDQj9TQkA1mdDgx2OTckbKJaFDZ54VlhhehBoWDN5nibYkiVNvGbVu5gpMSnlcAwNlvYQyNb5zciKpokB2fOo6M9TXH9AKkUmIIFTY6JMFM5rmDbN1qIeGUrReffECP/uVTmj5MNtBPkoW2OxMnv7w4WrY+uhKfIQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724323221; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=gb+bwGMntMHWw7yxlf/ng6qeDRQy6qo76SW493Em6XU=; b=MvUve0gohdNSVAFsrLVWQhE5w7kxR3IWNlx5GL+b+82Apvmvl8tcNrwzefxUIDBJtOTKOU rvblJCzoRs5IJqatYQgAegNvIR5D/5hhhofRVdGdb9ohDAsMEGn3BGJUxC7XLcJuVyXYuE 9Le6JqMXHUL2t6NhYxNovnJTd04+XaU= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-455-PgqCjDSRP1O2G7Ka4PrL1g-1; Thu, 22 Aug 2024 06:40:20 -0400 X-MC-Unique: PgqCjDSRP1O2G7Ka4PrL1g-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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 mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3D6961955BF2 for ; Thu, 22 Aug 2024 10:40:19 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.2.16.22]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 47D801955DD6 for ; Thu, 22 Aug 2024 10:40:17 +0000 (UTC) From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH 3/3] Linux: Add FUSE-based test for fchmod In-Reply-To: Message-ID: <5b82db7afebbbc0f0fbe6b0f2931b63c9f61aea9.1724323005.git.fweimer@redhat.com> References: X-From-Line: 5b82db7afebbbc0f0fbe6b0f2931b63c9f61aea9 Mon Sep 17 00:00:00 2001 Date: Thu, 22 Aug 2024 12:40:15 +0200 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-9.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SBL_CSS, SPF_HELO_NONE, SPF_NONE, 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.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org Test all mode arguments, and that extra bits are ignored as required by POSIX. --- sysdeps/unix/sysv/linux/Makefile | 1 + sysdeps/unix/sysv/linux/tst-fchmod-fuse.c | 124 ++++++++++++++++++++++ 2 files changed, 125 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/tst-fchmod-fuse.c diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index 941e64d883..d762f9b476 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -617,6 +617,7 @@ sysdep_headers += \ tests += \ tst-fallocate \ tst-fallocate64 \ + tst-fchmod-fuse \ tst-getcwd-smallbuff \ tst-o_path-locks \ # tests diff --git a/sysdeps/unix/sysv/linux/tst-fchmod-fuse.c b/sysdeps/unix/sysv/linux/tst-fchmod-fuse.c new file mode 100644 index 0000000000..2a377ccd62 --- /dev/null +++ b/sysdeps/unix/sysv/linux/tst-fchmod-fuse.c @@ -0,0 +1,124 @@ +/* FUSE-based test for fchmod. + Copyright (C) 2024 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 +#include +#include +#include + +/* Set from do_test to indicate the expected incoming mode change request. */ +static _Atomic int expected_mode; + +static void +fuse_thread (struct support_fuse *f, void *closure) +{ + struct fuse_in_header *inh; + while ((inh = support_fuse_read (f)) != NULL) + { + if (support_fuse_handle_mountpoint (f) + || (inh->nodeid == 1 && support_fuse_handle_directory (f))) + continue; + switch (inh->opcode) + { + case FUSE_LOOKUP: + { + char *name = support_fuse_cast (LOOKUP, inh); + TEST_COMPARE_STRING (name, "file"); + struct fuse_entry_out *out + = support_fuse_prepare_entry (f, 2); + out->attr.mode = S_IFREG | 0600; + support_fuse_reply_prepared (f); + } + break; + case FUSE_OPEN: + { + TEST_COMPARE (inh->nodeid, 2); + struct fuse_open_in *p = support_fuse_cast (OPEN, inh); + TEST_COMPARE (p->flags & O_ACCMODE, O_RDWR); + struct fuse_open_out out = { 0, }; + support_fuse_reply (f, &out, sizeof (out)); + } + break; + case FUSE_SETATTR: + { + TEST_COMPARE (inh->nodeid, 2); + struct fuse_setattr_in *p = support_fuse_cast (SETATTR, inh); + TEST_COMPARE (p->valid , FATTR_MODE); + TEST_COMPARE (p->mode, S_IFREG | expected_mode); + struct fuse_attr_out *out = support_fuse_prepare_attr (f); + out->attr.mode = S_IFREG | p->mode; + support_fuse_reply_prepared (f); + } + break; + case FUSE_FLUSH: + support_fuse_reply_empty (f); + break; + default: + support_fuse_reply_error (f, EIO); + } + } +} + +/* Test all mode values with the specified extra bits. */ +static void +test_with_bits (int fd, unsigned int extra_bits) +{ + for (int do_mode = 0; do_mode <= 07777; ++do_mode) + { + expected_mode = do_mode; + TEST_COMPARE (fchmod (fd, extra_bits | do_mode), 0); + } +} + +static int +do_test (void) +{ + support_become_root (); + if (!support_enter_mount_namespace ()) + FAIL_UNSUPPORTED ("mount namespaces not supported"); + + struct support_fuse *f = support_fuse_mount (fuse_thread, NULL); + char *path = xasprintf ("%s/file", support_fuse_mountpoint (f)); + int fd = xopen (path, O_RDWR, 0600); + free (path); + + test_with_bits (fd, 0); + /* POSIX requires that the extra bits are ignored. */ + test_with_bits (fd, S_IFREG); + test_with_bits (fd, S_IFDIR); + test_with_bits (fd, ~07777); + + /* Check that AT_FDCWD produces the expected error (and not + something else from fchmodat). */ + errno = 0; + TEST_COMPARE (fchmod (AT_FDCWD, 0), -1); + TEST_COMPARE (errno, EBADF); + + xclose (fd); + support_fuse_unmount (f); + + return 0; +} + +#include