From: Cyril Hrubis <chrubis@suse.cz>
To: Tudor Cretu <tudor.cretu@arm.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH 4/4] syscalls/statfs: Avoid dereferencing invalid buf in libc
Date: Wed, 17 Aug 2022 16:40:32 +0200 [thread overview]
Message-ID: <Yvz94MEujALdeDRE@yuki> (raw)
In-Reply-To: <20220817133946.234985-5-tudor.cretu@arm.com>
Hi!
> The [f]statfs02 testsuites check that [f]statfs returns EFUALT when the
> provided buf parameter is invalid. There are cases in which the supported
> libcs don't exhibit this behaviour.
>
> glibc versions newer than 2.34 and on systems that support [f]statfs64,
> call the syscall with a local struct statfs and then copy the result
> into buf. This throws a segfault for an invalid buf. musl dereferences buf
> before the syscall is called and, similarly, throws a segfault.
>
> To avoid dereferencing an invalid buf in libc, bypass the [f]statfs wrapper
> and call the syscall directly. Consistently with the libc wrappers,
> choose [f]statfs64 instead of [f]statfs if the target supports it.
Another solution that we used in the past would be installing a signal
handler for segfault and treat that signal as a PASS for the EFAULT
test.
> Signed-off-by: Tudor Cretu <tudor.cretu@arm.com>
> ---
> testcases/kernel/syscalls/fstatfs/fstatfs02.c | 7 ++++++-
> testcases/kernel/syscalls/statfs/statfs02.c | 7 ++++++-
> 2 files changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/testcases/kernel/syscalls/fstatfs/fstatfs02.c b/testcases/kernel/syscalls/fstatfs/fstatfs02.c
> index db2230f82..c1af07070 100644
> --- a/testcases/kernel/syscalls/fstatfs/fstatfs02.c
> +++ b/testcases/kernel/syscalls/fstatfs/fstatfs02.c
> @@ -25,6 +25,7 @@
> #include <sys/types.h>
> #include <sys/statfs.h>
> #include <errno.h>
> +#include "lapi/syscalls.h"
> #include "test.h"
> #include "safe_macros.h"
>
> @@ -68,7 +69,11 @@ int main(int ac, char **av)
>
> for (i = 0; i < TST_TOTAL; i++) {
>
> - TEST(fstatfs(TC[i].fd, TC[i].sbuf));
> +#if __NR_fstatfs64 != __LTP__NR_INVALID_SYSCALL
> + TEST(tst_syscall(__NR_fstatfs64, TC[i].fd, TC[i].sbuf));
> +#else
> + TEST(tst_syscall(__NR_fstatfs, TC[i].fd, TC[i].sbuf));
> +#endif
Even if we wanted to go with this version this should be put into an
header in lapi/ and not added into each test that calls statfs().
> if (TEST_RETURN != -1) {
> tst_resm(TFAIL, "call succeeded unexpectedly");
> diff --git a/testcases/kernel/syscalls/statfs/statfs02.c b/testcases/kernel/syscalls/statfs/statfs02.c
> index 279665f86..e1afbda39 100644
> --- a/testcases/kernel/syscalls/statfs/statfs02.c
> +++ b/testcases/kernel/syscalls/statfs/statfs02.c
> @@ -39,6 +39,7 @@
> #include <sys/vfs.h>
> #include <sys/mman.h>
> #include <errno.h>
> +#include "lapi/syscalls.h"
> #include "test.h"
> #include "safe_macros.h"
>
> @@ -116,7 +117,11 @@ static void setup(void)
>
> static void statfs_verify(const struct test_case_t *test)
> {
> - TEST(statfs(test->path, test->buf));
> +#if __NR_statfs64 != __LTP__NR_INVALID_SYSCALL
> + TEST(tst_syscall(__NR_statfs64, test->path, test->buf));
> +#else
> + TEST(tst_syscall(__NR_statfs, test->path, test->buf));
> +#endif
>
> if (TEST_RETURN != -1) {
> tst_resm(TFAIL, "call succeeded unexpectedly");
> --
> 2.25.1
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
prev parent reply other threads:[~2022-08-17 14:38 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-17 13:39 [LTP] [PATCH 0/4] syscalls: Fix various syscalls tests when compiled with Musl Tudor Cretu
2022-08-17 13:39 ` [LTP] [PATCH 1/4] lib: Fix initialization of recursive mutex Tudor Cretu
2022-08-17 14:13 ` Cyril Hrubis
2022-08-17 13:39 ` [LTP] [PATCH 2/4] syscalls/mprotect01: Invoke the syscall directly instead of the libc wrapper Tudor Cretu
2022-08-17 14:29 ` Cyril Hrubis
2022-08-17 13:39 ` [LTP] [PATCH 3/4] syscalls/prctl04: Allow rt_sigprocmask in the syscall filter Tudor Cretu
2022-08-17 14:42 ` Cyril Hrubis
2022-08-17 13:39 ` [LTP] [PATCH 4/4] syscalls/statfs: Avoid dereferencing invalid buf in libc Tudor Cretu
2022-08-17 14:40 ` Cyril Hrubis [this message]
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=Yvz94MEujALdeDRE@yuki \
--to=chrubis@suse.cz \
--cc=ltp@lists.linux.it \
--cc=tudor.cretu@arm.com \
/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