From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH V7 19/19] syscalls: clock_settime: Add test around y2038 vulnerability
Date: Tue, 28 Jul 2020 14:11:13 +0200 [thread overview]
Message-ID: <20200728121113.GA2412@yuki.lan> (raw)
In-Reply-To: <5b16889b19e969b79fa7d46c533bb5989ace1e46.1593152309.git.viresh.kumar@linaro.org>
Hi!
> This adds a test around the y2038 vulnerability, it sets the system time
> to just before y2038 time (i.e. max value that can be stored in s32),
> and adds a timer to expire just after crossing it.
>
> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
> ---
> runtest/syscalls | 1 +
> .../kernel/syscalls/clock_settime/.gitignore | 1 +
> .../syscalls/clock_settime/clock_settime03.c | 119 ++++++++++++++++++
> 3 files changed, 121 insertions(+)
> create mode 100644 testcases/kernel/syscalls/clock_settime/clock_settime03.c
>
> diff --git a/runtest/syscalls b/runtest/syscalls
> index 2d2e24615be6..718ac1148392 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -101,6 +101,7 @@ leapsec01 leapsec01
>
> clock_settime01 clock_settime01
> clock_settime02 clock_settime02
> +clock_settime03 clock_settime03
>
> clone01 clone01
> clone02 clone02
> diff --git a/testcases/kernel/syscalls/clock_settime/.gitignore b/testcases/kernel/syscalls/clock_settime/.gitignore
> index 28121755006b..b66169b3eb7b 100644
> --- a/testcases/kernel/syscalls/clock_settime/.gitignore
> +++ b/testcases/kernel/syscalls/clock_settime/.gitignore
> @@ -1,2 +1,3 @@
> clock_settime01
> clock_settime02
> +clock_settime03
> diff --git a/testcases/kernel/syscalls/clock_settime/clock_settime03.c b/testcases/kernel/syscalls/clock_settime/clock_settime03.c
> new file mode 100644
> index 000000000000..7245863137b5
> --- /dev/null
> +++ b/testcases/kernel/syscalls/clock_settime/clock_settime03.c
> @@ -0,0 +1,119 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2020 Linaro Limited. All rights reserved.
> + * Author: Viresh Kumar<viresh.kumar@linaro.org>
> + *
> + * Check Year 2038 related vulnerabilities.
> + */
> +
> +#include <signal.h>
> +#include "config.h"
> +#include "tst_timer.h"
> +#include "tst_safe_clocks.h"
> +
> +#define TIMER_DELTA 3
> +#define ALLOWED_DELTA (50 * 1000) /* 50 ms */
> +
> +static struct tst_ts start, end;
> +static struct tst_its its;
> +
> +static struct test_variants {
> + int (*clock_gettime)(clockid_t clk_id, void *ts);
> + int (*clock_settime)(clockid_t clk_id, void *ts);
> + int (*timer_settime)(timer_t timerid, int flags, void *its,
> + void *old_its);
> + enum tst_ts_type type;
> + char *desc;
> +} variants[] = {
> +#if (__NR_clock_settime != __LTP__NR_INVALID_SYSCALL)
> + { .clock_gettime = sys_clock_gettime, .clock_settime = sys_clock_settime, .timer_settime = sys_timer_settime, .type = TST_KERN_OLD_TIMESPEC, .desc = "syscall with old kernel spec"},
> +#endif
> +
> +#if (__NR_clock_settime64 != __LTP__NR_INVALID_SYSCALL)
> + { .clock_gettime = sys_clock_gettime64, .clock_settime = sys_clock_settime64, .timer_settime = sys_timer_settime64, .type = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec"},
> +#endif
> +};
> +
> +static void setup(void)
> +{
> + struct test_variants *tv = &variants[tst_variant];
> +
> + tst_res(TINFO, "Testing variant: %s", tv->desc);
> + start.type = end.type = its.type = tv->type;
> +
> + /* Check if the kernel is y2038 safe */
> + if (tv->type != TST_KERN_OLD_TIMESPEC &&
> + sizeof(start.ts.kern_old_ts) == 8)
Huh, what exactly are we trying to assert here? First of all we make
sure we are not using KERN_OLD_TIMESPEC and then check it's size?
Shouldn't it be tv->type == TST_KERNL_OLD_TIMESPEC && sizeof(start.ts.kern_old_ts) != 8?
That way we would abort if the old timespec is not 64bit which would
make a bit more sense to me.
> + tst_brk(TFAIL, "Not Y2038 safe to run test");
The test library does not work with tst_brk(TFAIL, ) see:
https://github.com/linux-test-project/ltp/issues/462
Also shouldn't we rather return TCONF here? It's not like the old kernel
timespec will ever change on 32bit architectures, so this would
practically fail the test on any 32bit arch, or did I miss something?
> +}
> +
> +static void run(void)
> +{
> + struct test_variants *tv = &variants[tst_variant];
> + unsigned long long time = 0x7FFFFFFE; /* Time just before y2038 */
> + struct sigevent ev = {
> + .sigev_notify = SIGEV_SIGNAL,
> + .sigev_signo = SIGABRT,
> + };
> + long long diff;
> + timer_t timer;
> + sigset_t set;
> + int sig, ret;
> +
> + if (sigemptyset(&set) == -1)
> + tst_brk(TBROK, "sigemptyset() failed");
> +
> + if (sigaddset(&set, SIGABRT) == -1)
> + tst_brk(TBROK, "sigaddset() failed");
> +
> + if (sigprocmask(SIG_BLOCK, &set, NULL) == -1)
> + tst_brk(TBROK, "sigprocmask() failed");
> +
> + TEST(tst_syscall(__NR_timer_create, CLOCK_REALTIME_ALARM, &ev, &timer));
> + if (TST_RET != 0)
> + tst_brk(TBROK | TERRNO, "timer_create() failed");
> +
> + tst_ts_set_sec(&start, time);
> + tst_ts_set_nsec(&start, 0);
> +
> + ret = tv->clock_settime(CLOCK_REALTIME, tst_ts_get(&start));
> + if (ret == -1)
> + tst_brk(TBROK | TERRNO, "clock_settime() failed");
> +
> + tst_its_set_interval_sec(&its, 0);
> + tst_its_set_interval_nsec(&its, 0);
> + tst_its_set_value_sec(&its, time + TIMER_DELTA);
> + tst_its_set_value_nsec(&its, 0);
> +
> + TEST(tv->timer_settime(timer, TIMER_ABSTIME, tst_its_get(&its), NULL));
> + if (TST_RET == -1)
> + tst_brk(TBROK | TTERRNO, "timer_settime() failed");
> +
> + if (sigwait(&set, &sig) == -1)
> + tst_brk(TBROK, "sigwait() failed");
> +
> + ret = tv->clock_gettime(CLOCK_REALTIME, tst_ts_get(&end));
> + if (ret == -1)
> + tst_brk(TBROK | TERRNO, "clock_gettime() failed");
> +
> + if (sig == SIGABRT) {
> + diff = tst_ts_diff_ms(end, start);
> +
> + if (diff < TIMER_DELTA * 1000 - ALLOWED_DELTA ||
AFAIK timers must not expire sooner than requested so we can as well do just:
if (diff < TIMER_DELTA * 1000)
tst_res(TFAL, "Timer expired too soon, after %llims", diff);
> + diff > TIMER_DELTA * 1000 + ALLOWED_DELTA)
> + tst_res(TINFO, "Slept for unexpected duration, expected:%d, actual:%lld",
> + TIMER_DELTA * 1000, diff);
> + tst_res(TPASS, "clock_settime(): Y2038 test passed");
> + return;
> + }
> +
> + tst_res(TFAIL, "clock_settime(): Y2038 test failed");
I guess that it would be a bit cleaner with:
if (sig != SIGABRT) {
tst_res(TFAIL, "...");
return;
}
diff = ...
...
> +}
> +
> +static struct tst_test test = {
> + .test_all = run,
> + .test_variants = ARRAY_SIZE(variants),
> + .setup = setup,
> + .needs_root = 1,
> + .restore_wallclock = 1,
> +};
> --
> 2.25.0.rc1.19.g042ed3e048af
>
--
Cyril Hrubis
chrubis@suse.cz
next prev parent reply other threads:[~2020-07-28 12:11 UTC|newest]
Thread overview: 64+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-26 6:22 [LTP] [PATCH V7 00/19] Syscalls: Add support for time64 variants Viresh Kumar
2020-06-26 6:22 ` [LTP] [PATCH V7 01/19] tst_timer: Add new definitions Viresh Kumar
2020-06-26 9:49 ` Cyril Hrubis
2020-06-26 6:22 ` [LTP] [PATCH V7 02/19] syscalls/timer_gettime: Add support for time64 tests Viresh Kumar
2020-06-26 9:49 ` Cyril Hrubis
2020-06-26 6:22 ` [LTP] [PATCH V7 03/19] syscalls/timer_settime: " Viresh Kumar
2020-06-29 9:39 ` Cyril Hrubis
2020-06-29 11:43 ` Viresh Kumar
2020-06-26 6:22 ` [LTP] [PATCH V7 04/19] syscalls/timerfd: " Viresh Kumar
2020-07-02 12:24 ` Cyril Hrubis
2020-06-26 6:22 ` [LTP] [PATCH V7 05/19] syscalls/sched_rr_get_interval: " Viresh Kumar
2020-07-02 13:06 ` Cyril Hrubis
2020-07-03 3:15 ` Viresh Kumar
2020-07-03 5:52 ` Yang Xu
2020-07-03 7:26 ` Viresh Kumar
2020-07-03 7:38 ` [LTP] [PATCH] syscalls/sched_rr_get_interval: Validate the timeslice Viresh Kumar
2020-07-03 7:43 ` Yang Xu
2020-07-03 7:51 ` Viresh Kumar
2020-07-03 8:00 ` Yang Xu
2020-07-03 8:18 ` Viresh Kumar
2020-07-03 9:01 ` Yang Xu
2020-07-03 14:08 ` Cyril Hrubis
2020-07-06 3:31 ` [LTP] [PATCH V2] " Viresh Kumar
2020-07-06 4:41 ` Yang Xu
2020-07-07 9:30 ` Cyril Hrubis
2020-06-26 6:22 ` [LTP] [PATCH V7 06/19] syscalls/futex: Merge futex_wait_bitset tests Viresh Kumar
2020-07-03 9:15 ` Cyril Hrubis
2020-06-26 6:22 ` [LTP] [PATCH V7 07/19] syscalls/futex: Add support for time64 tests Viresh Kumar
2020-07-03 12:45 ` Cyril Hrubis
2020-07-06 10:40 ` Viresh Kumar
2020-07-06 11:36 ` Viresh Kumar
2020-07-06 11:40 ` [LTP] [PATCH V7.1 " Viresh Kumar
2020-07-23 19:44 ` Cyril Hrubis
2020-07-24 2:33 ` Viresh Kumar
2020-06-26 6:22 ` [LTP] [PATCH V7 08/19] syscalls/io_pgetevents: " Viresh Kumar
2020-07-03 14:59 ` Cyril Hrubis
2020-06-26 6:22 ` [LTP] [PATCH V7 09/19] syscalls/sigwaitinfo: Migrate to new test framework Viresh Kumar
2020-07-03 13:58 ` Cyril Hrubis
2020-07-06 2:39 ` Viresh Kumar
2020-07-07 15:16 ` Cyril Hrubis
2020-07-09 10:46 ` Viresh Kumar
2020-06-26 6:22 ` [LTP] [PATCH V7 10/19] syscalls/rt_sigtimedwait: Add support for time64 tests Viresh Kumar
2020-07-22 10:03 ` Cyril Hrubis
2020-06-26 6:22 ` [LTP] [PATCH V7 11/19] syscalls/mq_timed{send|receive}: " Viresh Kumar
2020-07-24 14:51 ` Cyril Hrubis
2020-06-26 6:22 ` [LTP] [PATCH V7 12/19] syscalls/recvmmsg: " Viresh Kumar
2020-07-24 15:13 ` Cyril Hrubis
2020-06-26 6:22 ` [LTP] [PATCH V7 13/19] syscalls/ppoll: " Viresh Kumar
2020-07-27 9:17 ` Cyril Hrubis
2020-06-26 6:22 ` [LTP] [PATCH V7 14/19] syscalls/select6: " Viresh Kumar
2020-07-27 9:40 ` Cyril Hrubis
2020-07-28 7:23 ` Viresh Kumar
2020-07-28 8:02 ` Arnd Bergmann
2020-06-26 6:22 ` [LTP] [PATCH V7 15/19] syscalls/semop: Migrate to new test framework Viresh Kumar
2020-07-27 13:46 ` Cyril Hrubis
2020-06-26 6:22 ` [LTP] [PATCH V7 16/19] syscalls/semtimedop: Add support for semtimedop and its time64 version Viresh Kumar
2020-06-26 6:22 ` [LTP] [PATCH V7 17/19] syscalls/utimensat: Migrate to new test framework Viresh Kumar
2020-07-27 15:35 ` Cyril Hrubis
2020-06-26 6:22 ` [LTP] [PATCH V7 18/19] syscalls/utimensat: Add support for time64 tests Viresh Kumar
2020-06-26 6:22 ` [LTP] [PATCH V7 19/19] syscalls: clock_settime: Add test around y2038 vulnerability Viresh Kumar
2020-07-28 12:11 ` Cyril Hrubis [this message]
2020-08-04 12:37 ` Viresh Kumar
2020-07-20 10:19 ` [LTP] [PATCH V7 00/19] Syscalls: Add support for time64 variants Viresh Kumar
2020-07-22 10:04 ` Cyril Hrubis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200728121113.GA2412@yuki.lan \
--to=chrubis@suse.cz \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox