summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ctype/ctype-info.c6
-rw-r--r--elf/tst-env-setuid.c26
-rw-r--r--iconv/Makefile6
-rw-r--r--iconv/gconv_parseconfdir.h8
-rw-r--r--iconv/gconv_simple.c8
-rwxr-xr-xiconv/tst-iconvconfig.sh48
-rw-r--r--stdio-common/tst-freopen4-main.c44
-rw-r--r--sysdeps/unix/sysv/linux/Makefile1
-rw-r--r--sysdeps/unix/sysv/linux/tst-copy_file_range-large.c239
9 files changed, 342 insertions, 44 deletions
diff --git a/ctype/ctype-info.c b/ctype/ctype-info.c
index b7d3422726..fb5acf9419 100644
--- a/ctype/ctype-info.c
+++ b/ctype/ctype-info.c
@@ -24,11 +24,11 @@
__ctype_init before user code runs, but this does not happen for
threads in secondary namespaces. With the initializers, secondary
namespaces at least get locale data from the C locale. */
-__thread const uint16_t * __libc_tsd_CTYPE_B
+__thread const uint16_t * __libc_tsd_CTYPE_B attribute_tls_model_ie
= (const uint16_t *) _nl_C_LC_CTYPE_class + 128;
-__thread const int32_t * __libc_tsd_CTYPE_TOLOWER
+__thread const int32_t * __libc_tsd_CTYPE_TOLOWER attribute_tls_model_ie
= (const int32_t *) _nl_C_LC_CTYPE_tolower + 128;
-__thread const int32_t * __libc_tsd_CTYPE_TOUPPER
+__thread const int32_t * __libc_tsd_CTYPE_TOUPPER attribute_tls_model_ie
= (const int32_t *) _nl_C_LC_CTYPE_toupper + 128;
diff --git a/elf/tst-env-setuid.c b/elf/tst-env-setuid.c
index 7209acd616..ff3eda7f91 100644
--- a/elf/tst-env-setuid.c
+++ b/elf/tst-env-setuid.c
@@ -40,6 +40,8 @@ static char SETGID_CHILD[] = "setgid-child";
# define PROFILE_LIB "tst-sonamemove-runmod2.so"
#endif
+#define LD_DEBUG_OUTPUT "/tmp/some-file"
+
struct envvar_t
{
const char *env;
@@ -61,7 +63,7 @@ static const struct envvar_t filtered_envvars[] =
{ "MALLOC_TRIM_THRESHOLD_", FILTERED_VALUE },
{ "RES_OPTIONS", FILTERED_VALUE },
{ "LD_DEBUG", "all" },
- { "LD_DEBUG_OUTPUT", "/tmp/some-file" },
+ { "LD_DEBUG_OUTPUT", LD_DEBUG_OUTPUT },
{ "LD_WARN", FILTERED_VALUE },
{ "LD_VERBOSE", FILTERED_VALUE },
{ "LD_BIND_NOW", "0" },
@@ -74,6 +76,14 @@ static const struct envvar_t unfiltered_envvars[] =
{ "LD_ASSUME_KERNEL", UNFILTERED_VALUE },
};
+static void
+unlink_ld_debug_output (pid_t pid)
+{
+ char *output = xasprintf ("%s.%d", LD_DEBUG_OUTPUT, pid);
+ unlink (output);
+ free (output);
+}
+
static int
test_child (void)
{
@@ -138,13 +148,21 @@ do_test (int argc, char **argv)
/* Setgid child process. */
if (argc == 2 && strcmp (argv[1], SETGID_CHILD) == 0)
{
+ pid_t ppid = getppid ();
+
if (getgid () == getegid ())
- /* This can happen if the file system is mounted nosuid. */
- FAIL_UNSUPPORTED ("SGID failed: GID and EGID match (%jd)\n",
- (intmax_t) getgid ());
+ {
+ /* This can happen if the file system is mounted nosuid. */
+ unlink_ld_debug_output (ppid);
+
+ FAIL_UNSUPPORTED ("SGID failed: GID and EGID match (%jd)\n",
+ (intmax_t) getgid ());
+ }
int ret = test_child ();
+ unlink_ld_debug_output (ppid);
+
if (ret != 0)
exit (1);
return 0;
diff --git a/iconv/Makefile b/iconv/Makefile
index 9a94a41ba4..672126d452 100644
--- a/iconv/Makefile
+++ b/iconv/Makefile
@@ -85,6 +85,7 @@ tests-special += \
$(objpfx)tst-iconv_prog-buffer-tiny.out \
$(objpfx)tst-iconv_prog-buffer.out \
$(objpfx)tst-iconv_prog.out \
+ $(objpfx)tst-iconvconfig.out \
$(objpfx)tst-translit-mchar.out \
# tests-special
endif
@@ -164,3 +165,8 @@ $(objpfx)tst-iconv_prog-buffer-large.out: \
tst-iconv_prog-buffer.sh $(objpfx)iconv_prog
$(BASH) $< $(common-objdir) '$(run-program-prefix)' '' '22' > $@; \
$(evaluate-test)
+
+$(objpfx)tst-iconvconfig.out: tst-iconvconfig.sh $(objpfx)iconvconfig
+ $(BASH) $< $(common-objdir) '$(test-wrapper-env)' \
+ '$(run-program-env)' > $@; \
+ $(evaluate-test)
diff --git a/iconv/gconv_parseconfdir.h b/iconv/gconv_parseconfdir.h
index a7ebfd80cc..31f8f1c421 100644
--- a/iconv/gconv_parseconfdir.h
+++ b/iconv/gconv_parseconfdir.h
@@ -33,9 +33,10 @@
# define closedir __closedir
# define mempcpy __mempcpy
# define struct_stat64 struct __stat64_t64
-# define lstat64 __lstat64_time64
+# define stat64_impl __stat64_time64
# define feof_unlocked __feof_unlocked
#else
+# define stat64_impl stat64
# define struct_stat64 struct stat64
#endif
@@ -151,7 +152,8 @@ gconv_parseconfdir (const char *prefix, const char *dir, size_t dir_len)
struct dirent64 *ent;
while ((ent = readdir64 (confdir)) != NULL)
{
- if (ent->d_type != DT_REG && ent->d_type != DT_UNKNOWN)
+ if (ent->d_type != DT_REG && ent->d_type != DT_UNKNOWN
+ && ent->d_type != DT_LNK)
continue;
size_t len = strlen (ent->d_name);
@@ -166,7 +168,7 @@ gconv_parseconfdir (const char *prefix, const char *dir, size_t dir_len)
continue;
if (ent->d_type != DT_UNKNOWN
- || (lstat64 (conf, &st) != -1 && S_ISREG (st.st_mode)))
+ || (stat64_impl (conf, &st) != -1 && S_ISREG (st.st_mode)))
found |= read_conf_file (conf, dir, dir_len);
free (conf);
diff --git a/iconv/gconv_simple.c b/iconv/gconv_simple.c
index 1e29eb1a80..0ebdccee90 100644
--- a/iconv/gconv_simple.c
+++ b/iconv/gconv_simple.c
@@ -90,7 +90,7 @@ internal_ucs4_loop (struct __gconv_step *step,
for (cnt = 0; cnt < n_convert; ++cnt, inptr += 4, outptr += 4)
{
uint32_t val = get32 (inptr);
- put32 (outptr, __builtin_bswap32 (val));
+ put32 (outptr, bswap_32 (val));
}
*inptrp = inptr;
@@ -196,7 +196,7 @@ ucs4_internal_loop (struct __gconv_step *step,
{
uint32_t inval = get32 (inptr);
#if __BYTE_ORDER == __LITTLE_ENDIAN
- inval = __builtin_bswap32 (inval);
+ inval = bswap_32 (inval);
#endif
if (__glibc_unlikely (inval > 0x7fffffff))
@@ -337,7 +337,7 @@ internal_ucs4le_loop (struct __gconv_step *step,
for (cnt = 0; cnt < n_convert; ++cnt, inptr += 4, outptr += 4)
{
uint32_t val = get32 (inptr);
- put32 (outptr, __builtin_bswap32 (val));
+ put32 (outptr, bswap_32 (val));
}
*inptrp = inptr;
@@ -442,7 +442,7 @@ ucs4le_internal_loop (struct __gconv_step *step,
{
uint32_t inval = get32 (inptr);
#if __BYTE_ORDER == __BIG_ENDIAN
- inval = __builtin_bswap32 (inval);
+ inval = bswap_32 (inval);
#endif
if (__glibc_unlikely (inval > 0x7fffffff))
diff --git a/iconv/tst-iconvconfig.sh b/iconv/tst-iconvconfig.sh
new file mode 100755
index 0000000000..0b16b17f0d
--- /dev/null
+++ b/iconv/tst-iconvconfig.sh
@@ -0,0 +1,48 @@
+#!/bin/bash
+# Check if iconvconfig correctly handle config links (BZ 32339)
+# 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/>.
+
+set -e
+
+build_dir=$1
+test_wrapper_env="$2"
+run_program_env="$3"
+
+# We have to have some directories in the library path.
+LIBPATH=$build_dir:$build_dir/iconvdata
+
+ICONVCONFIG="
+$build_dir/elf/ld.so --library-path $LIBPATH $build_dir/iconv/iconvconfig
+"
+
+ICONVCONFIG="$test_wrapper_env $run_program_env $ICONVCONFIG"
+
+TIMEOUTFACTOR=${TIMEOUTFACTOR:-1}
+
+tmpdir=$(mktemp -d $build_dir/iconv/tst-iconvconfig.XXXXXX)
+#trap 'rm -fr $tmpdir' 0 1 2 3 15 EXIT
+
+touch $tmpdir/gconv-modules-extra.conf
+mkdir $tmpdir/gconv-modules.d
+cd $tmpdir/gconv-modules.d && ln -s ../gconv-modules-extra.conf . && cd -
+
+$ICONVCONFIG --nostdlib $tmpdir -o $tmpdir/gconv-modules.cache
+
+[ ! -e $tmpdir/tmpdir/gconv-modules.cache ] || exit 1
+
+exit 0
diff --git a/stdio-common/tst-freopen4-main.c b/stdio-common/tst-freopen4-main.c
index 436da4d203..3336f5327d 100644
--- a/stdio-common/tst-freopen4-main.c
+++ b/stdio-common/tst-freopen4-main.c
@@ -28,15 +28,25 @@
#include <support/test-driver.h>
#include <support/xstdio.h>
#include <support/xunistd.h>
-#include <support/capture_subprocess.h>
-static void
-do_test_chroot (void *data)
+int
+do_test (void)
{
- char *temp_dir = (char *) data;
+ mtrace ();
+ char *temp_dir;
FILE *fp;
int ret;
+ /* These chroot tests verify that either reopening a renamed or
+ deleted file works even in the absence of /proc, or that it fails
+ (without memory leaks); thus, for example, such reopening does
+ not crash in the absence of /proc. */
+
+ support_become_root ();
+ if (!support_can_chroot ())
+ return EXIT_UNSUPPORTED;
+
+ temp_dir = support_create_temp_directory ("tst-freopen4");
xchroot (temp_dir);
/* Test freopen with NULL, renamed file. This verifies that
@@ -86,32 +96,6 @@ do_test_chroot (void *data)
puts ("freopen of deleted file failed (OK)");
free (temp_dir);
-}
-
-int
-do_test (void)
-{
- mtrace ();
- char *temp_dir;
-
- /* These chroot tests verify that either reopening a renamed or
- deleted file works even in the absence of /proc, or that it fails
- (without memory leaks); thus, for example, such reopening does
- not crash in the absence of /proc. */
-
- support_become_root ();
- if (!support_can_chroot ())
- return EXIT_UNSUPPORTED;
-
- temp_dir = support_create_temp_directory ("tst-freopen4");
-
- struct support_capture_subprocess result;
- result = support_capture_subprocess (do_test_chroot, temp_dir);
- support_capture_subprocess_check (&result, "freopen4", 0,
- sc_allow_stdout);
- fputs (result.out.buffer, stdout);
- support_capture_subprocess_free (&result);
-
return 0;
}
diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
index c47cbdf428..2c5bf42236 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/tst-copy_file_range-large.c b/sysdeps/unix/sysv/linux/tst-copy_file_range-large.c
new file mode 100644
index 0000000000..14fdf82953
--- /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>