lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20230907185507.7928b589@gandalf.local.home>
Date:   Thu, 7 Sep 2023 18:55:07 -0400
From:   Steven Rostedt <rostedt@...dmis.org>
To:     Beau Belgrave <beaub@...ux.microsoft.com>
Cc:     shuah@...nel.org, mhiramat@...nel.org,
        linux-kernel@...r.kernel.org, linux-kselftest@...r.kernel.org,
        broonie@...nel.org, naresh.kamboju@...aro.org,
        anders.roxell@...aro.org, arnd@...db.de
Subject: Re: [PATCH] selftests/user_events: Fix failures when user_events is
 not installed

On Thu,  7 Sep 2023 22:35:36 +0000
Beau Belgrave <beaub@...ux.microsoft.com> wrote:

> diff --git a/tools/testing/selftests/user_events/user_events_selftests.h b/tools/testing/selftests/user_events/user_events_selftests.h
> new file mode 100644
> index 000000000000..72692e62c709
> --- /dev/null
> +++ b/tools/testing/selftests/user_events/user_events_selftests.h
> @@ -0,0 +1,103 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +
> +#ifndef _USER_EVENTS_SELFTESTS_H
> +#define _USER_EVENTS_SELFTESTS_H
> +
> +#include <sys/types.h>
> +#include <sys/mount.h>
> +#include <unistd.h>
> +#include <errno.h>
> +
> +#include "../kselftest.h"
> +
> +static inline bool tracefs_enabled(char **message, bool *fail)
> +{
> +	int fd;
> +
> +	*message = "";
> +	*fail = false;
> +
> +	/* Ensure tracefs is installed */
> +	fd = open("/sys/kernel/tracing", O_RDONLY);

Instead of opening the directory, I believe that "stat()" is the preferred
method of testing existence.

> +
> +	if (fd == -1) {
> +		*message = "Tracefs is not installed";
> +		return false;
> +	}
> +
> +	close(fd);
> +
> +	/* Ensure mounted tracefs */
> +	fd = open("/sys/kernel/tracing/README", O_RDONLY);
> +
> +	if (fd == -1 && errno == ENOENT) {
> +		if (mount(NULL, "/sys/kernel/tracing", "tracefs", 0, NULL) != 0) {
> +			*message = "Cannot mount tracefs";
> +			*fail = true;
> +			return false;
> +		}
> +
> +		fd = open("/sys/kernel/tracing/README", O_RDONLY);

Same here, unless you want to make sure you can also read it.

> +	}
> +
> +	if (fd == -1) {
> +		*message = "Cannot access tracefs";
> +		*fail = true;
> +		return false;
> +	}
> +
> +	close(fd);
> +
> +	return true;
> +}
> +
> +static inline bool user_events_enabled(char **message, bool *fail)
> +{
> +	int fd;
> +
> +	*message = "";
> +	*fail = false;
> +
> +	if (getuid() != 0) {
> +		*message = "Must be run as root";
> +		*fail = true;
> +		return false;
> +	}
> +
> +	if (!tracefs_enabled(message, fail))
> +		return false;
> +
> +	/* Ensure user_events is installed */
> +	fd = open("/sys/kernel/tracing/user_events_data", O_RDONLY);

ditto.

-- Steve

> +
> +	if (fd == -1) {
> +		switch (errno) {
> +		case ENOENT:
> +			*message = "user_events is not installed";
> +			return false;
> +
> +		default:
> +			*message = "Cannot access user_events_data";
> +			*fail = true;
> +			return false;
> +		}
> +	}
> +
> +	close(fd);
> +
> +	return true;
> +}
> +
> +#define USER_EVENT_FIXTURE_SETUP(statement) do { \
> +	char *message; \
> +	bool fail; \
> +	if (!user_events_enabled(&message, &fail)) { \
> +		if (fail) { \
> +			TH_LOG("Setup failed due to: %s", message); \
> +			ASSERT_FALSE(fail); \
> +		} \
> +		SKIP(statement, "Skipping due to: %s", message); \
> +	} \
> +} while (0)
> +
> +#endif /* _USER_EVENTS_SELFTESTS_H */
> 
> base-commit: 9b1db732866bee060b9bca9493e5ebf5e8874c48

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ