From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v3 3/3] Test for CVE-2016-10044 mark AIO pseudo-fs noexec
Date: Fri, 4 Aug 2017 15:47:14 +0200 [thread overview]
Message-ID: <20170804134714.GB7915@rei> (raw)
In-Reply-To: <20170801132701.16317-3-rpalethorpe@suse.com>
Hi!
> +#include <stdio.h>
> +#include <stdint.h>
> +#include <string.h>
> +#include "lapi/syscalls.h"
> +#include "tst_test.h"
> +#include "tst_personality.h"
> +#include "tst_safe_stdio.h"
> +
> +#define CONV_STR "%*x-%*x %s7"
> +
> +static FILE *f;
> +
> +static void cleanup(void)
> +{
> + if (f != NULL)
Could be just
if (f)
SAFE_CLOSE(f);
> + SAFE_FCLOSE(f);
> +}
> +
> +static void run(void)
> +{
> + uint64_t ctx = 0;
> + pid_t pid = getpid();
> + char perms[8], line[BUFSIZ];
> + char maps_path[256];
> +
> + SAFE_PERSONALITY(READ_IMPLIES_EXEC);
> + if (tst_syscall(__NR_io_setup, 1, &ctx))
> + tst_brk(TBROK | TERRNO, "Failed to create AIO context");
> +
> + snprintf(maps_path, sizeof(maps_path), "/proc/%d/maps", pid);
You can use the "/proc/self/maps" insetad and save yourself getpid() and
snprintf().
> + f = SAFE_FOPEN(maps_path, "r");
> + while (fgets(line, BUFSIZ, f) != NULL) {
> + if (strstr(line, "/[aio]") != NULL)
> + goto found_mapping;
> + }
Here again, the != NULL is redundant.
> + tst_brk(TBROK, "Could not find mapping in %s", maps_path);
> +
> +found_mapping:
> + if (sscanf(line, CONV_STR, perms) < 0)
> + tst_brk(TBROK, "failed find permission string in %s", line);
I fail to see why is the CONV_STR defined as a macro?
It's not like we use it twice or something.
> + if (strchr(perms, (int)'x'))
> + tst_res(TFAIL, "AIO mapping is executable: %s!", perms);
> + else
> + tst_res(TPASS, "AIO mapping is not executable: %s", perms);
> +}
> +
> +static struct tst_test test = {
> + .test_all = run,
> + .cleanup = cleanup,
> + .min_kver = "2.6.8",
> +};
> --
> 2.13.3
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
--
Cyril Hrubis
chrubis@suse.cz
next prev parent reply other threads:[~2017-08-04 13:47 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-01 13:26 [LTP] [PATCH v3 1/3] lib: Add personality fallback and SAFE macro Richard Palethorpe
2017-08-01 13:27 ` [LTP] [PATCH v3 2/3] CVE-2012-0957: Use SAFE_PERSONALITY Richard Palethorpe
2017-08-01 13:27 ` [LTP] [PATCH v3 3/3] Test for CVE-2016-10044 mark AIO pseudo-fs noexec Richard Palethorpe
2017-08-04 13:47 ` Cyril Hrubis [this message]
2017-08-04 13:32 ` [LTP] [PATCH v3 1/3] lib: Add personality fallback and SAFE macro 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=20170804134714.GB7915@rei \
--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