From patchwork Thu Aug 22 14:25:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 1975575 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=iYAiD7eO; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; 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 [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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WqQVX4ktpz1ybW for ; Fri, 23 Aug 2024 00:26:12 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 339CF3870C34 for ; Thu, 22 Aug 2024 14:26:10 +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.133.124]) by sourceware.org (Postfix) with ESMTP id D7F03386074B for ; Thu, 22 Aug 2024 14:25:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D7F03386074B 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 D7F03386074B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724336753; cv=none; b=Y2s+xHSu5osB3AJmTsCC+YRHwOlO05yRqZi7l2kUzU/p/4uB6GmfmeIHYrk71TmLDShnKRW0GZR06WGQ4LjWNX7G5EnW2hf/OpA54yqeLkCpdFWA+IaZbbSaHI54DLxGAsUvEtv4HAnP55NYi/RxBOhdNcNamH4iMJ/1HTvw1SY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724336753; c=relaxed/simple; bh=xCyIdNstXYbP1LCHsyaj0MlNFH7Nwn1RjFycSfrNDrk=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=nAt356v5sUNKvopIBlYDu9pjYpLMLpCPeRK5Xe3xLtcKcx5kIIxDHEwTj9j5mPZ/J0kcDdtUVbF5f6Bs2SEMqxEE/fDwah3kOmqgfASwkWMfWZgWRn45YbEfu4SpTxCWpd9O/o8dS0EROwEdEH0zK2Hnr20WR564ajLUM90KSnU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724336750; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=MFah3/jvGVxLJsoYCFfkztizx0SvhHueAeoXwrxDNb8=; b=iYAiD7eO8RMCwm6J2KtcapMALB/enmp8rCO90nvD11AQCtb84hn7nWnEG/RQ/nVvUptnYH 31KhYUpZo/LeXJlq2FF1P3LcDLr1lh8uKOjACwP2p+V7UqmNk/pQF58Ur8Z83ln9skSIqC 1wdt+R5AKqtJjXsQuG351ph2szJDO3E= Received: from mx-prod-mc-05.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-312-EubkEVbWNNKM4cGmCpEOYA-1; Thu, 22 Aug 2024 10:25:49 -0400 X-MC-Unique: EubkEVbWNNKM4cGmCpEOYA-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 346921956080 for ; Thu, 22 Aug 2024 14:25:48 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.2.16.22]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 175483002242 for ; Thu, 22 Aug 2024 14:25:46 +0000 (UTC) From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH] io: Add error tests for fchmod Date: Thu, 22 Aug 2024 16:25:43 +0200 Message-ID: <87y14oprbs.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 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_H4, 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 On Linux most descriptors that do not correspond to file system entities (such as anonymous pipes and sockets) have file permissions that can be changed. While it is possible to create a custom file system that returns (say) EINVAL for an fchmod attempt, testing this does not appear to be useful. --- io/Makefile | 1 + io/tst-fchmod-errors.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) base-commit: 7f04bb4e49413bd57ac3215f3480b09ae7131968 diff --git a/io/Makefile b/io/Makefile index 19932d50f7..47666a1deb 100644 --- a/io/Makefile +++ b/io/Makefile @@ -188,6 +188,7 @@ tests := \ tst-closefrom \ tst-copy_file_range \ tst-faccessat \ + tst-fchmod-errors \ tst-fchmodat \ tst-fchownat \ tst-fcntl \ diff --git a/io/tst-fchmod-errors.c b/io/tst-fchmod-errors.c new file mode 100644 index 0000000000..8ff3efcc3c --- /dev/null +++ b/io/tst-fchmod-errors.c @@ -0,0 +1,59 @@ +/* Test various fchmod error cases. + 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 + +static int +do_test (void) +{ + { + /* Permissions on /dev/null (the opened descriptor) cannot be changed. */ + int fd = xopen ("/dev/null", O_RDWR, 0); + errno = 0; + TEST_COMPARE (fchmod (fd, 0), -1); + TEST_COMPARE (errno, EPERM); + xclose (fd); + + /* Now testing an invalid file descriptor. */ + errno = 0; + TEST_COMPARE (fchmod (fd, 0600), -1); + TEST_COMPARE (errno, EBADF); + } + + errno = 0; + TEST_COMPARE (fchmod (-1, 0600), -1); + TEST_COMPARE (errno, EBADF); + + errno = 0; + TEST_COMPARE (fchmod (AT_FDCWD, 0600), -1); + TEST_COMPARE (errno, EBADF); + + /* Linux supports fchmod on pretty much all file descriptors, so + there is no check for failure on specific types of descriptors + here. */ + + return 0; +} + +#include