public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 1/2] Add test for CVE 2020-25704
Date: Tue, 3 Aug 2021 16:52:44 +0200	[thread overview]
Message-ID: <YQlYPM1XuRsHVyV0@yuki> (raw)
In-Reply-To: <20210802160918.30861-1-mdoucha@suse.cz>

Hi!
> +static void run(void)
> +{
> +	struct sysinfo info1, info2;
> +	unsigned long diff, memunit;
> +	int i;
> +
> +	SAFE_SYSINFO(&info1);
> +
> +	/* leak about 100MB of RAM */
> +	for (i = 0; i < 12000000; i++)
> +		ioctl(fd, PERF_EVENT_IOC_SET_FILTER, "filter,0/0@abcd");
> +
> +	SAFE_SYSINFO(&info2);
> +	memunit = info1.mem_unit;
> +
> +	/* sysinfo(2) man page does not guarantee consistent mem_unit... */
> +	if (info1.mem_unit > info2.mem_unit) {
> +		diff = info1.mem_unit / info2.mem_unit;
> +		info2.freeram /= diff;
> +	} else if (info1.mem_unit < info2.mem_unit) {
> +		diff = info2.mem_unit / info1.mem_unit;
> +		info1.freeram /= diff;
> +		memunit = info2.mem_unit;
> +	}

I guess that SAFE_READ_MEMINFO() would be much easier to use with:

	memfree_before = SAFE_READ_MEMINFO("MemFree:");

	// do the test

	memfree_after = SAFE_READ_MEMINFO("MemFree:");

And the result is conviniently in kilobytes.

> +	if (info1.freeram > info2.freeram + 50 * 1024 * 1024 / memunit)
> +		tst_res(TFAIL, "Likely kernel memory leak detected");
> +	else
> +		tst_res(TPASS, "No memory leak found");
> +}
> +
> +static void cleanup(void)
> +{
> +	if (fd >= 0)
> +		SAFE_CLOSE(fd);
> +}
> +
> +static struct tst_test test = {
> +	.test_all = run,
> +	.setup = setup,
> +	.cleanup = cleanup,
> +	.needs_root = 1,
> +	.tags = (const struct tst_tag[]) {
> +		{"linux-git", "7bdb157cdebb"},
> +		{"CVE", "2020-25704"},
> +		{}
> +	}
> +};
> +
> +#else /* HAVE_PERF_EVENT_ATTR */
> +TST_TEST_TCONF("This system doesn't have <linux/perf_event.h> or "
> +	"struct perf_event_attr is not defined.");
> +#endif
> -- 
> 2.32.0
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz

      parent reply	other threads:[~2021-08-03 14:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-02 16:09 [LTP] [PATCH 1/2] Add test for CVE 2020-25704 Martin Doucha
2021-08-02 16:09 ` [LTP] [PATCH 2/2] perf_event_open02: Use common perf_event_open() wrapper Martin Doucha
2021-08-02 16:12 ` [LTP] [PATCH 1/2] Add test for CVE 2020-25704 Martin Doucha
2021-08-03 14:52 ` 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=YQlYPM1XuRsHVyV0@yuki \
    --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