commit: afa38c053de48152beef9d8bf6726a4710bcba58 Author: Mike Frysinger <vapier <AT> gentoo <DOT> org> AuthorDate: Sat Oct 23 07:25:25 2021 +0000 Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org> CommitDate: Sat Oct 23 22:18:03 2021 +0000 URL: https://gitweb.gentoo.org/proj/sandbox.git/commit/?id=afa38c05
libsandbox: add 64-bit time_t wrappers This intercepts the C library 64-bit time_t interfaces. The syscall trace side will need more work first. Bug: https://bugs.gentoo.org/751241 Signed-off-by: Mike Frysinger <vapier <AT> gentoo.org> libsandbox/symbols.h.in | 5 +++++ libsandbox/wrapper-funcs/__futimesat64.c | 13 +++++++++++++ libsandbox/wrapper-funcs/__lutimes64.c | 13 +++++++++++++ libsandbox/wrapper-funcs/__utime64.c | 13 +++++++++++++ libsandbox/wrapper-funcs/__utimensat64.c | 13 +++++++++++++ libsandbox/wrapper-funcs/__utimes64.c | 13 +++++++++++++ libsandbox/wrapper-funcs/futimesat.c | 4 +++- libsandbox/wrapper-funcs/lutimes.c | 4 +++- libsandbox/wrapper-funcs/utime.c | 4 +++- libsandbox/wrapper-funcs/utimensat.c | 4 +++- libsandbox/wrapper-funcs/utimes.c | 4 +++- tests/local.mk | 2 ++ tests/test-skel-0.c | 4 ++-- tests/utimensat64-0.c | 3 +++ tests/utimensat64-1.sh | 9 +++++++++ tests/utimensat64.at | 1 + tests/utimensat64_static-0.c | 1 + tests/utimensat64_static-1.sh | 10 ++++++++++ tests/utimensat64_static.at | 1 + 19 files changed, 114 insertions(+), 7 deletions(-) diff --git a/libsandbox/symbols.h.in b/libsandbox/symbols.h.in index 0fe6eca..40c04e3 100644 --- a/libsandbox/symbols.h.in +++ b/libsandbox/symbols.h.in @@ -74,9 +74,14 @@ lremovexattr setxattr lsetxattr utime +__utime64 utimes +__utimes64 utimensat +__utimensat64 futimesat +__futimesat64 lutimes +__lutimes64 fork vfork diff --git a/libsandbox/wrapper-funcs/__futimesat64.c b/libsandbox/wrapper-funcs/__futimesat64.c new file mode 100644 index 0000000..9ad791e --- /dev/null +++ b/libsandbox/wrapper-funcs/__futimesat64.c @@ -0,0 +1,13 @@ +/* + * __futimesat64() wrapper. + * + * Copyright 1999-2021 Gentoo Foundation + * Licensed under the GPL-2 + */ + +/* + * NB: Reusing the 32-bit time interface isn't entirely correct as the 64-bit time interface uses a + * different structure, but we never decode the time values in sandbox, so it doesn't matter to use. + */ +#define WRAPPER_SAFE() _SB_SAFE_AT(SB_NR_FUTIMESAT, STRING_NAME, dirfd, filename, 0) +#include "futimesat.c" diff --git a/libsandbox/wrapper-funcs/__lutimes64.c b/libsandbox/wrapper-funcs/__lutimes64.c new file mode 100644 index 0000000..edab47c --- /dev/null +++ b/libsandbox/wrapper-funcs/__lutimes64.c @@ -0,0 +1,13 @@ +/* + * __lutimes64() wrapper. + * + * Copyright 1999-2021 Gentoo Foundation + * Licensed under the GPL-2 + */ + +/* + * NB: Reusing the 32-bit time interface isn't entirely correct as the 64-bit time interface uses a + * different structure, but we never decode the time values in sandbox, so it doesn't matter to use. + */ +#define WRAPPER_SAFE() _SB_SAFE(SB_NR_LUTIMES, STRING_NAME, filename) +#include "lutimes.c" diff --git a/libsandbox/wrapper-funcs/__utime64.c b/libsandbox/wrapper-funcs/__utime64.c new file mode 100644 index 0000000..4e1b573 --- /dev/null +++ b/libsandbox/wrapper-funcs/__utime64.c @@ -0,0 +1,13 @@ +/* + * __utime64() wrapper. + * + * Copyright 1999-2021 Gentoo Foundation + * Licensed under the GPL-2 + */ + +/* + * NB: Reusing the 32-bit time interface isn't entirely correct as the 64-bit time interface uses a + * different structure, but we never decode the time values in sandbox, so it doesn't matter to use. + */ +#define WRAPPER_SAFE() _SB_SAFE(SB_NR_UTIME, STRING_NAME, filename) +#include "utime.c" diff --git a/libsandbox/wrapper-funcs/__utimensat64.c b/libsandbox/wrapper-funcs/__utimensat64.c new file mode 100644 index 0000000..4ef1c69 --- /dev/null +++ b/libsandbox/wrapper-funcs/__utimensat64.c @@ -0,0 +1,13 @@ +/* + * __utimensat64() wrapper. + * + * Copyright 1999-2021 Gentoo Foundation + * Licensed under the GPL-2 + */ + +/* + * NB: Reusing the 32-bit time interface isn't entirely correct as the 64-bit time interface uses a + * different structure, but we never decode the time values in sandbox, so it doesn't matter to use. + */ +#define WRAPPER_SAFE() _SB_SAFE_AT(SB_NR_UTIMENSAT, STRING_NAME, dirfd, filename, flags) +#include "utimensat.c" diff --git a/libsandbox/wrapper-funcs/__utimes64.c b/libsandbox/wrapper-funcs/__utimes64.c new file mode 100644 index 0000000..3fa6688 --- /dev/null +++ b/libsandbox/wrapper-funcs/__utimes64.c @@ -0,0 +1,13 @@ +/* + * __utimes64() wrapper. + * + * Copyright 1999-2021 Gentoo Foundation + * Licensed under the GPL-2 + */ + +/* + * NB: Reusing the 32-bit time interface isn't entirely correct as the 64-bit time interface uses a + * different structure, but we never decode the time values in sandbox, so it doesn't matter to use. + */ +#define WRAPPER_SAFE() _SB_SAFE(SB_NR_UTIMES, STRING_NAME, filename) +#include "utimes.c" diff --git a/libsandbox/wrapper-funcs/futimesat.c b/libsandbox/wrapper-funcs/futimesat.c index 6f6481b..bc1a966 100644 --- a/libsandbox/wrapper-funcs/futimesat.c +++ b/libsandbox/wrapper-funcs/futimesat.c @@ -7,5 +7,7 @@ #define WRAPPER_ARGS_PROTO int dirfd, const char *filename, const struct timeval times[2] #define WRAPPER_ARGS dirfd, filename, times -#define WRAPPER_SAFE() SB_SAFE_AT(dirfd, filename, 0) +#ifndef WRAPPER_SAFE +# define WRAPPER_SAFE() SB_SAFE_AT(dirfd, filename, 0) +#endif #include "__wrapper_simple.c" diff --git a/libsandbox/wrapper-funcs/lutimes.c b/libsandbox/wrapper-funcs/lutimes.c index 3192a33..fb9ae68 100644 --- a/libsandbox/wrapper-funcs/lutimes.c +++ b/libsandbox/wrapper-funcs/lutimes.c @@ -7,5 +7,7 @@ #define WRAPPER_ARGS_PROTO const char *filename, const struct timeval times[2] #define WRAPPER_ARGS filename, times -#define WRAPPER_SAFE() SB_SAFE(filename) +#ifndef WRAPPER_SAFE +# define WRAPPER_SAFE() SB_SAFE(filename) +#endif #include "__wrapper_simple.c" diff --git a/libsandbox/wrapper-funcs/utime.c b/libsandbox/wrapper-funcs/utime.c index f0a6814..4bbf374 100644 --- a/libsandbox/wrapper-funcs/utime.c +++ b/libsandbox/wrapper-funcs/utime.c @@ -7,5 +7,7 @@ #define WRAPPER_ARGS_PROTO const char *filename, const struct utimbuf *times #define WRAPPER_ARGS filename, times -#define WRAPPER_SAFE() SB_SAFE(filename) +#ifndef WRAPPER_SAFE +# define WRAPPER_SAFE() SB_SAFE(filename) +#endif #include "__wrapper_simple.c" diff --git a/libsandbox/wrapper-funcs/utimensat.c b/libsandbox/wrapper-funcs/utimensat.c index 840ff18..3baf89c 100644 --- a/libsandbox/wrapper-funcs/utimensat.c +++ b/libsandbox/wrapper-funcs/utimensat.c @@ -7,5 +7,7 @@ #define WRAPPER_ARGS_PROTO int dirfd, const char *filename, const struct timespec times[2], int flags #define WRAPPER_ARGS dirfd, filename, times, flags -#define WRAPPER_SAFE() SB_SAFE_AT(dirfd, filename, flags) +#ifndef WRAPPER_SAFE +# define WRAPPER_SAFE() SB_SAFE_AT(dirfd, filename, flags) +#endif #include "__wrapper_simple.c" diff --git a/libsandbox/wrapper-funcs/utimes.c b/libsandbox/wrapper-funcs/utimes.c index b117895..902c6f5 100644 --- a/libsandbox/wrapper-funcs/utimes.c +++ b/libsandbox/wrapper-funcs/utimes.c @@ -7,5 +7,7 @@ #define WRAPPER_ARGS_PROTO const char *filename, const struct timeval times[2] #define WRAPPER_ARGS filename, times -#define WRAPPER_SAFE() SB_SAFE(filename) +#ifndef WRAPPER_SAFE +# define WRAPPER_SAFE() SB_SAFE(filename) +#endif #include "__wrapper_simple.c" diff --git a/tests/local.mk b/tests/local.mk index aa2acac..86a8a65 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -81,7 +81,9 @@ check_PROGRAMS += \ %D%/unlinkat-0 \ %D%/utime-0 \ %D%/utimensat-0 \ + %D%/utimensat64-0 \ %D%/utimensat_static-0 \ + %D%/utimensat64_static-0 \ %D%/utimes-0 \ %D%/vfork-0 \ \ diff --git a/tests/test-skel-0.c b/tests/test-skel-0.c index 96e42ae..de88cf4 100644 --- a/tests/test-skel-0.c +++ b/tests/test-skel-0.c @@ -144,8 +144,8 @@ struct timespec *parse_timespec(const char *s) if (!strcmp(s, "NOW")) { times->tv_sec = time(0); } else { - long sec = 0, nsec = 0; - sscanf(s, "%li,%li", &sec, &nsec); + int64_t sec = 0, nsec = 0; + sscanf(s, "%" PRIi64 ",%" PRIi64, &sec, &nsec); times->tv_sec = sec; times->tv_nsec = nsec; } diff --git a/tests/utimensat64-0.c b/tests/utimensat64-0.c new file mode 100644 index 0000000..bbacef5 --- /dev/null +++ b/tests/utimensat64-0.c @@ -0,0 +1,3 @@ +#define _TIME_BITS 64 +#define _FILE_OFFSET_BITS 64 +#include "utimensat-0.c" diff --git a/tests/utimensat64-1.sh b/tests/utimensat64-1.sh new file mode 100755 index 0000000..2aebc5f --- /dev/null +++ b/tests/utimensat64-1.sh @@ -0,0 +1,9 @@ +#!/bin/sh +# basic functionality check + +addwrite $PWD + +touch -r / file || exit 1 +utimensat64-0 0 AT_FDCWD . NULL 0 || exit 1 +utimensat64-0 0 AT_FDCWD file NULL 0 || exit 1 +[ file -nt / ] diff --git a/tests/utimensat64.at b/tests/utimensat64.at new file mode 100644 index 0000000..081d7d2 --- /dev/null +++ b/tests/utimensat64.at @@ -0,0 +1 @@ +SB_CHECK(1) diff --git a/tests/utimensat64_static-0.c b/tests/utimensat64_static-0.c new file mode 100644 index 0000000..73e7602 --- /dev/null +++ b/tests/utimensat64_static-0.c @@ -0,0 +1 @@ +#include "utimensat64-0.c" diff --git a/tests/utimensat64_static-1.sh b/tests/utimensat64_static-1.sh new file mode 100755 index 0000000..7b0355c --- /dev/null +++ b/tests/utimensat64_static-1.sh @@ -0,0 +1,10 @@ +#!/bin/sh +# basic functionality check +[ "${at_xfail}" = "yes" ] && exit 77 # see trace-0 + +addwrite $PWD + +touch -r / file || exit 1 +utimensat64_static-0 0 AT_FDCWD . NULL 0 || exit 1 +utimensat64_static-0 0 AT_FDCWD file NULL 0 || exit 1 +[ file -nt / ] diff --git a/tests/utimensat64_static.at b/tests/utimensat64_static.at new file mode 100644 index 0000000..081d7d2 --- /dev/null +++ b/tests/utimensat64_static.at @@ -0,0 +1 @@ +SB_CHECK(1)
