diff options
Diffstat (limited to 'sysdeps/unix/sysv/linux')
-rw-r--r-- | sysdeps/unix/sysv/linux/Makefile | 1 | ||||
-rw-r--r-- | sysdeps/unix/sysv/linux/dl-execstack.c | 3 | ||||
-rw-r--r-- | sysdeps/unix/sysv/linux/i386/____longjmp_chk.S | 2 | ||||
-rw-r--r-- | sysdeps/unix/sysv/linux/machine-sp.h | 2 | ||||
-rw-r--r-- | sysdeps/unix/sysv/linux/spawni.c | 5 | ||||
-rw-r--r-- | sysdeps/unix/sysv/linux/tst-copy_file_range-large.c | 239 | ||||
-rw-r--r-- | sysdeps/unix/sysv/linux/x86_64/64/Implies | 1 | ||||
-rw-r--r-- | sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S | 2 |
8 files changed, 248 insertions, 7 deletions
diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index c47cbdf..2c5bf42 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -192,6 +192,7 @@ tests += \ tst-clone \ tst-clone2 \ tst-clone3 \ + tst-copy_file_range-large \ tst-epoll \ tst-epoll-ioctls \ tst-fanotify \ diff --git a/sysdeps/unix/sysv/linux/dl-execstack.c b/sysdeps/unix/sysv/linux/dl-execstack.c index 6db9601..a59bd56 100644 --- a/sysdeps/unix/sysv/linux/dl-execstack.c +++ b/sysdeps/unix/sysv/linux/dl-execstack.c @@ -17,6 +17,7 @@ <https://www.gnu.org/licenses/>. */ #include <ldsodefs.h> +#include <stackinfo.h> int _dl_make_stack_executable (const void *stack_endp) @@ -36,7 +37,7 @@ _dl_make_stack_executable (const void *stack_endp) return errno; /* Remember that we changed the permission. */ - GL(dl_stack_flags) |= PF_X; + GL(dl_stack_prot_flags) |= PROT_EXEC; return 0; } diff --git a/sysdeps/unix/sysv/linux/i386/____longjmp_chk.S b/sysdeps/unix/sysv/linux/i386/____longjmp_chk.S index e468d34..3e09f15 100644 --- a/sysdeps/unix/sysv/linux/i386/____longjmp_chk.S +++ b/sysdeps/unix/sysv/linux/i386/____longjmp_chk.S @@ -67,7 +67,7 @@ ENTRY (____longjmp_chk) /* Without working sigaltstack we cannot perform the test. */ test %eax, %eax jne .Lok2 - testl $1, 4(%esp) + testb $1, 4(%esp) jz .Lfail movl (%esp), %eax diff --git a/sysdeps/unix/sysv/linux/machine-sp.h b/sysdeps/unix/sysv/linux/machine-sp.h index 6ab3ca6..bda90fe 100644 --- a/sysdeps/unix/sysv/linux/machine-sp.h +++ b/sysdeps/unix/sysv/linux/machine-sp.h @@ -19,6 +19,8 @@ #ifndef _MACHINE_SP_H #define _MACHINE_SP_H +#include <stackinfo.h> + /* Return the current stack pointer. */ static inline uintptr_t __thread_stack_pointer (void) diff --git a/sysdeps/unix/sysv/linux/spawni.c b/sysdeps/unix/sysv/linux/spawni.c index eca1a84..bc8476f 100644 --- a/sysdeps/unix/sysv/linux/spawni.c +++ b/sysdeps/unix/sysv/linux/spawni.c @@ -348,9 +348,6 @@ __spawnix (int *pid, const char *file, return errno; } - int prot = (PROT_READ | PROT_WRITE - | ((GL (dl_stack_flags) & PF_X) ? PROT_EXEC : 0)); - /* Add a slack area for child's stack. */ size_t argv_size = (argc * sizeof (void *)) + 512; /* We need at least a few pages in case the compiler's stack checking is @@ -361,7 +358,7 @@ __spawnix (int *pid, const char *file, where it might use about 1k extra stack space). */ argv_size += (32 * 1024); size_t stack_size = ALIGN_UP (argv_size, GLRO(dl_pagesize)); - void *stack = __mmap (NULL, stack_size, prot, + void *stack = __mmap (NULL, stack_size, GL (dl_stack_prot_flags), MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, -1, 0); if (__glibc_unlikely (stack == MAP_FAILED)) return errno; diff --git a/sysdeps/unix/sysv/linux/tst-copy_file_range-large.c b/sysdeps/unix/sysv/linux/tst-copy_file_range-large.c new file mode 100644 index 0000000..14fdf82 --- /dev/null +++ b/sysdeps/unix/sysv/linux/tst-copy_file_range-large.c @@ -0,0 +1,239 @@ +/* Test for copy_file_range with large sizes (bug 33245). + Copyright (C) 2025 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 + <https://www.gnu.org/licenses/>. */ + +/* This test exercises copy_file_range with various large file sizes + on FUSE filesystems to verify proper handling of system call return + values. No data is actually copied. */ + +#include <dirent.h> +#include <errno.h> +#include <fcntl.h> +#include <limits.h> +#include <stdio.h> +#include <string.h> +#include <support/check.h> +#include <support/fuse.h> +#include <support/support.h> +#include <support/test-driver.h> +#include <support/xthread.h> +#include <support/xunistd.h> +#include <sys/stat.h> +#include <unistd.h> + +static void +fuse_thread (struct support_fuse *f, void *closure) +{ + /* Node IDs for our test files. */ + enum { NODE_SOURCE = 2, NODE_DEST = 3 }; + /* A large size, so that the kernel does not fail the + copy_file_range attempt before performing the FUSE callback. + Only the source file size matters to the kernel, but both files + use the same size for simplicity. */ + const uint64_t file_size = 1LLU << 61; + + 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: + { + char *name = support_fuse_cast (LOOKUP, inh); + int node = 0; + if (inh->nodeid == 1 && strcmp (name, "source") == 0) + node = NODE_SOURCE; + else if (inh->nodeid == 1 && strcmp (name, "dest") == 0) + node = NODE_DEST; + + if (node != 0) + { + struct fuse_entry_out *out + = support_fuse_prepare_entry (f, node); + out->attr.mode = S_IFREG | 0600; + out->attr.size = file_size; + support_fuse_reply_prepared (f); + } + else + support_fuse_reply_error (f, ENOENT); + } + break; + + case FUSE_OPEN: + /* File open */ + { + if (inh->nodeid == NODE_SOURCE || inh->nodeid == NODE_DEST) + { + struct fuse_open_out out = { .fh = inh->nodeid }; + support_fuse_reply (f, &out, sizeof (out)); + } + else + support_fuse_reply_error (f, ENOENT); + } + break; + + case FUSE_GETATTR: + /* Get file attributes */ + if (inh->nodeid == NODE_SOURCE || inh->nodeid == NODE_DEST) + { + struct fuse_attr_out *out = support_fuse_prepare_attr (f); + out->attr.mode = S_IFREG | 0600; + out->attr.size = file_size; + support_fuse_reply_prepared (f); + } + else + support_fuse_reply_error (f, ENOENT); + break; + + case FUSE_COPY_FILE_RANGE: + { + struct fuse_copy_file_range_in *p + = support_fuse_cast (COPY_FILE_RANGE, inh); + + /* Verify this is a copy from source to dest, starting at + offset 0. */ + TEST_COMPARE (p->fh_in, NODE_SOURCE); + TEST_COMPARE (p->nodeid_out, NODE_DEST); + TEST_COMPARE (p->off_in, 0); + TEST_COMPARE (p->off_out, 0); + TEST_VERIFY (p->len > 0); + TEST_VERIFY (p->len <= file_size); + + /* Pretend the copy succeeded. */ + struct fuse_write_out out = { .size = p->len }; + support_fuse_reply (f, &out, sizeof (out)); + } + break; + + case FUSE_FLUSH: + support_fuse_reply_empty (f); + break; + + default: + support_fuse_reply_error (f, EIO); + } + } +} + +static void +test_size (struct support_fuse *f, off64_t size) +{ + /* On 32-bit targets, not all possible return values from + copy_file_range are representable. The current (Linux 6.5.18) + kernel FUSE implementation can produce negative non-error results + from copy_file_range in the range [1UL << 31, UINT_MAX - 4095], + but this seems to be a FUSE bug. */ + if (size != (ssize_t) size) + { + printf ("info:%s size 0x%llx is too large for ssize_t\n", + test_verbose ? " " : "", (unsigned long long int) size); + return; + } + + verbose_printf ("info: testing copy size 0x%llx\n", + (unsigned long long int) size); + + const char *mountpoint = support_fuse_mountpoint (f); + char *source_path = xasprintf ("%s/source", mountpoint); + char *dest_path = xasprintf ("%s/dest", mountpoint); + + int source_fd = xopen (source_path, O_RDONLY, 0); + int dest_fd = xopen (dest_path, O_WRONLY, 0); + + ssize_t copied = copy_file_range (source_fd, NULL, dest_fd, NULL, size, 0); + /* Avoid FAIL_UNSUPPORTED if it is likely bogus due to previous + copy_file_range successes. */ + if (copied == -1 && errno == ENOSYS) + { + /* Unmounting avoids a test hang on exit. */ + xclose (dest_fd); + xclose (source_fd); + support_fuse_unmount (f); + FAIL_UNSUPPORTED ("copy_file_range not supported"); + } + + TEST_COMPARE (copied, size); + + xclose (dest_fd); + xclose (source_fd); + free (dest_path); + free (source_path); +} + +static void +test_all_sizes (struct support_fuse *f) +{ + test_size (f, 0); /* Not actually handled by the callback. */ + test_size (f, 20); + test_size (f, 1 << 30); + test_size (f, INT_MAX); + for (int i = 0; i <= 5; ++i) + test_size (f, (1U << 31) + i); + for (int i = -4100; i <= -4090; ++i) + test_size (f, UINT_MAX + i); + for (int i = -100; i <= 0; ++i) + test_size (f, UINT_MAX + i); + + /* We would like to test larger values than UINT_MAX here, but they + do not work because the FUSE protocol uses uint32_t for the + copy_file_range result in struct fuse_write_out. */ +} + +static void * +test_cancel_state_variants (void *f_ptr) +{ + struct support_fuse *f = (struct support_fuse *) f_ptr; + + verbose_printf ("info: testing default cancellation settings\n"); + test_all_sizes (f); + + verbose_printf ("info: testing with cancellation disabled\n"); + TEST_COMPARE (pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, NULL), 0); + test_all_sizes (f); + + verbose_printf ("info: testing with cancellation enabled\n"); + TEST_COMPARE (pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL), 0); + test_all_sizes (f); + + return NULL; +} + +static int +do_test (void) +{ + support_fuse_init (); + struct support_fuse *f = support_fuse_mount (fuse_thread, NULL); + + verbose_printf ("info: testing on main thread\n"); + test_cancel_state_variants (f); + + verbose_printf ("info: testing on secondary thread\n"); + TEST_VERIFY (xpthread_join (xpthread_create + (NULL, test_cancel_state_variants, f)) + == NULL); + + verbose_printf ("info: testing on separate thread\n"); + + support_fuse_unmount (f); + return 0; +} + +#include <support/test-driver.c> diff --git a/sysdeps/unix/sysv/linux/x86_64/64/Implies b/sysdeps/unix/sysv/linux/x86_64/64/Implies new file mode 100644 index 0000000..f379d95 --- /dev/null +++ b/sysdeps/unix/sysv/linux/x86_64/64/Implies @@ -0,0 +1 @@ +x86_64/64/nptl diff --git a/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S b/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S index b73a18b..3bcdd6a 100644 --- a/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S +++ b/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S @@ -44,7 +44,7 @@ longjmp_msg: /* Without working sigaltstack we cannot perform the test. */ \ testl %eax, %eax; \ jne .Lok2; \ - testl $1, (-sizeSS + oSS_FLAGS)(%rsp); \ + testb $1, (-sizeSS + oSS_FLAGS)(%rsp); \ jz .Lfail; \ mov (-sizeSS + oSS_SP)(%rsp), %RAX_LP; \ add (-sizeSS + oSS_SIZE)(%rsp), %RAX_LP; \ |