From patchwork Fri Aug 30 19:53:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 1979206 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=CXcoDFzw; 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 4WwTPl2yVwz1yfn for ; Sat, 31 Aug 2024 05:54:35 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 415E53865487 for ; Fri, 30 Aug 2024 19:54:33 +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 9EC073864C6A for ; Fri, 30 Aug 2024 19:53:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9EC073864C6A 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 9EC073864C6A 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=1725047611; cv=none; b=q9pGMDPn9wGR3LEGKUv8jN+j43jPfqFVEGTwazXqveWoQ1oaNjyqEGee6N4DMN4GG4h7moCFqBL9TFGS9iWon91V8Q+va7o5/MXyAsPnrJkSVRDn5rRsJ9WCsAE0/FmVEYTegiM9G34vwBW8791tR3GDnFNywwZgq1vm1z4iiCU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725047611; c=relaxed/simple; bh=mDMFGWAwF8oIBwrSZASQd3DeeV6zMGpY90s9ZQRxKJo=; h=DKIM-Signature:From:To:Subject:Message-ID:Date:MIME-Version; b=FZJxi8C8FsUUkybDdDmdiTtl9ySTwCn0G924/vnsA1VCToy4MtCuOBD29Y+RrP6RlgWes8P1aJX0SE3++J8GG71JfOD/VxK82F5KG8KKdb2A3erlsT3WW9fJJ3T0K2l8G1W5vtpK8DPaEmYgDut17nb73RqkgPhuEkuYI6rZhQI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725047609; 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=CFG4GJsQmk3P+eU/MYxOjBZKtTK0/BuJlD2Wh/7sldA=; b=CXcoDFzwCeH7DLbxr76ndorZsIpVyRiQMgpOIvIMvM6SnLJUiZvlP6CmYBFBXVL7hZBFwl 7qfJUbAaU0wRutmTFZGn+JcEtmHz9BB4vkGrjgSw62ph+t2zmlz1pBVDrXsm+LZcRyiIds rYY2AOVD8eXc4eUBfWAVxB8T+rzyjGo= Received: from mx-prod-mc-02.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-352-IIPAN5LdMLar778eq5O7rQ-1; Fri, 30 Aug 2024 15:53:28 -0400 X-MC-Unique: IIPAN5LdMLar778eq5O7rQ-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4A1C01954B02 for ; Fri, 30 Aug 2024 19:53:27 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.2.16.7]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 11C9D1955F44 for ; Fri, 30 Aug 2024 19:53:25 +0000 (UTC) From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH v4 08/13] io: Add tst-lstat-nofollow, tst-lstat-nofollow-time64 In-Reply-To: Message-ID: References: X-From-Line: d26b1cb570caf483d80b8a3e8cc4e7d8df5b1e46 Mon Sep 17 00:00:00 2001 Date: Fri, 30 Aug 2024 21:53:22 +0200 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, 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 They verify that lstat, lstat64 do not follow symbolic links. --- io/Makefile | 2 + io/tst-lstat-nofollow-time64.c | 1 + io/tst-lstat-nofollow.c | 98 ++++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 io/tst-lstat-nofollow-time64.c create mode 100644 io/tst-lstat-nofollow.c diff --git a/io/Makefile b/io/Makefile index 8987dc1375..a401ec414e 100644 --- a/io/Makefile +++ b/io/Makefile @@ -209,6 +209,7 @@ tests := \ tst-lchmod \ tst-linkat \ tst-lockf \ + tst-lstat-nofollow \ tst-lutimes \ tst-mkdirat \ tst-mkfifoat \ @@ -238,6 +239,7 @@ tests-time64 := \ tst-futimes-time64\ tst-futimesat-time64 \ tst-lchmod-time64 \ + tst-lstat-nofollow-time64 \ tst-lutimes-time64 \ tst-stat-time64 \ tst-utime-time64 \ diff --git a/io/tst-lstat-nofollow-time64.c b/io/tst-lstat-nofollow-time64.c new file mode 100644 index 0000000000..45feb3f130 --- /dev/null +++ b/io/tst-lstat-nofollow-time64.c @@ -0,0 +1 @@ +#include "tst-lstat-nofollow.c" diff --git a/io/tst-lstat-nofollow.c b/io/tst-lstat-nofollow.c new file mode 100644 index 0000000000..5bbb557c72 --- /dev/null +++ b/io/tst-lstat-nofollow.c @@ -0,0 +1,98 @@ +/* Test that lstat does not follow symbolic links. + 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 + +static void +fuse_thread (struct support_fuse *f, void *closure) +{ + struct fuse_in_header *inh; + while ((inh = support_fuse_next (f)) != NULL) + { + if (support_fuse_handle_mountpoint (f) + || (inh->nodeid == 1 && support_fuse_handle_directory (f))) + continue; + switch (inh->opcode) + { + case FUSE_LOOKUP: + { + TEST_COMPARE (inh->nodeid, 1); + TEST_COMPARE_STRING (support_fuse_cast (LOOKUP, inh), "symlink"); + struct fuse_entry_out *out = support_fuse_prepare_entry (f, 2); + out->attr.mode = S_IFLNK | 0777; + out->attr.size = strlen ("target"); + support_fuse_reply_prepared (f); + } + break; + case FUSE_GETATTR: + { + TEST_COMPARE (inh->nodeid, 2); + struct fuse_attr_out *out = support_fuse_prepare_attr (f); + out->attr.mode = S_IFLNK | 0777; + out->attr.size = strlen ("target"); + support_fuse_reply_prepared (f); + } + break; + case FUSE_READLINK: + /* The lstat operation must not attempt to look at the + symbolic link target. */ + FAIL ("attempt to obtain target of symblic link for node %llu", + (unsigned long long int) inh->nodeid); + break; + default: + FAIL ("unexpected event %s", support_fuse_opcode (inh->opcode)); + } + } +} + +static int +do_test (void) +{ + support_fuse_init (); + struct support_fuse *f = support_fuse_mount (fuse_thread, NULL); + char *symlink_path = xasprintf ("%s/symlink", support_fuse_mountpoint (f)); + + { + struct stat st = { 0, }; + TEST_COMPARE (lstat (symlink_path, &st), 0); + TEST_COMPARE (st.st_uid, getuid ()); + TEST_COMPARE (st.st_gid, getgid ()); + TEST_COMPARE (st.st_size, 6); + TEST_COMPARE (st.st_mode, S_IFLNK | 0777); + } + + { + struct stat64 st = { 0, }; + TEST_COMPARE (lstat64 (symlink_path, &st), 0); + TEST_COMPARE (st.st_uid, getuid ()); + TEST_COMPARE (st.st_gid, getgid ()); + TEST_COMPARE (st.st_size, 6); + TEST_COMPARE (st.st_mode, S_IFLNK | 0777); + } + + free (symlink_path); + support_fuse_unmount (f); + return 0; +} + +#include