* [PATCH master 1/3] test: self: ramfs: fix null pointer dereference on error
@ 2024-01-03 10:13 Ahmad Fatoum
2024-01-03 10:13 ` [PATCH master 2/3] test: self: regulator: depend on REGULATOR_FIXED for test Ahmad Fatoum
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 10:13 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
expect_success is meant for return values of functions that return
negative error codes and as such compares the first argument to be
zero or greater, which means PTR_ERR_OR_ZERO will treat NULL pointers as
valid all the same leading to NULL pointer dereferences should the test
fail instead of a descriptive error message. Fix this by translating
NULL pointer to -errno or -EFAULT if errno is unset.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
test/self/ramfs.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/test/self/ramfs.c b/test/self/ramfs.c
index bce396dc171e..1bc2b3b068f0 100644
--- a/test/self/ramfs.c
+++ b/test/self/ramfs.c
@@ -27,7 +27,16 @@ BSELFTEST_GLOBALS();
__cond; \
})
+static inline int ptr_to_err(const void *ptr)
+{
+ if (ptr)
+ return PTR_ERR_OR_ZERO(ptr);
+
+ return -errno ?: -EFAULT;
+}
+
#define expect_success(ret, ...) __expect((ret), (ret) >= 0, __VA_ARGS__)
+#define expect_ptrok(ptr, ...) expect_success(ptr_to_err(ptr), __VA_ARGS__)
#define expect_fail(ret, ...) __expect((ret), (ret) < 0, __VA_ARGS__)
static inline int get_file_count(int i)
@@ -101,7 +110,7 @@ static void test_ramfs(void)
}
dir = opendir(dname);
- if (!expect_success(PTR_ERR_OR_ZERO(dir), "opening parent directory"))
+ if (!expect_ptrok(dir, "opening parent directory"))
continue;
j = 0;
@@ -120,11 +129,11 @@ static void test_ramfs(void)
}
oldpwd = pushd(dname);
- if (!expect_success(oldpwd != NULL ? 0 : -EINVAL, "pushd()"))
+ if (!expect_ptrok(oldpwd, "pushd()"))
goto out;;
dir = opendir(".");
- if (!expect_success(PTR_ERR_OR_ZERO(dir), "opening parent directory"))
+ if (!expect_ptrok(dir, "opening parent directory"))
goto out;
i = 1;
@@ -183,7 +192,7 @@ static void test_ramfs(void)
expect_success(ret, "write_file()");
buf = read_file("test/a/b/c/d/e/f/g/h/i/j/k/l/FILE", NULL);
- if (expect_success(PTR_ERR_OR_ZERO(buf), "read_file()")) {
+ if (expect_ptrok(buf, "read_file()")) {
expect_success(memcmp(buf, ARRAY_AND_SIZE(hello)),
"read_file() content");
}
--
2.39.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH master 2/3] test: self: regulator: depend on REGULATOR_FIXED for test
2024-01-03 10:13 [PATCH master 1/3] test: self: ramfs: fix null pointer dereference on error Ahmad Fatoum
@ 2024-01-03 10:13 ` Ahmad Fatoum
2024-01-03 10:13 ` [PATCH master 3/3] test: self: mmu: fix message on skipping tests Ahmad Fatoum
2024-01-03 14:10 ` [PATCH master 1/3] test: self: ramfs: fix null pointer dereference on error Sascha Hauer
2 siblings, 0 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 10:13 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
The regulator self test requires fixed regulator support, which itself
already requires REGULATOR && OFDEVICE, which we already depend on.
Therefore, just add REGULATOR_FIXED as dependency.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
test/self/Kconfig | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/test/self/Kconfig b/test/self/Kconfig
index ace01accda7e..6b9a4bf4a6e4 100644
--- a/test/self/Kconfig
+++ b/test/self/Kconfig
@@ -41,7 +41,7 @@ config SELFTEST_ENABLE_ALL
select SELFTEST_MMU if MMU
select SELFTEST_STRING
select SELFTEST_SETJMP if ARCH_HAS_SJLJ
- select SELFTEST_REGULATOR if REGULATOR && OFDEVICE
+ select SELFTEST_REGULATOR if REGULATOR_FIXED
select SELFTEST_TEST_COMMAND if CMD_TEST
select SELFTEST_IDR
help
@@ -101,7 +101,7 @@ config SELFTEST_SETJMP
config SELFTEST_REGULATOR
bool "Regulator selftest"
- depends on REGULATOR && OFDEVICE
+ depends on REGULATOR_FIXED
select OF_OVERLAY
config SELFTEST_TEST_COMMAND
--
2.39.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH master 3/3] test: self: mmu: fix message on skipping tests
2024-01-03 10:13 [PATCH master 1/3] test: self: ramfs: fix null pointer dereference on error Ahmad Fatoum
2024-01-03 10:13 ` [PATCH master 2/3] test: self: regulator: depend on REGULATOR_FIXED for test Ahmad Fatoum
@ 2024-01-03 10:13 ` Ahmad Fatoum
2024-01-03 14:10 ` [PATCH master 1/3] test: self: ramfs: fix null pointer dereference on error Sascha Hauer
2 siblings, 0 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2024-01-03 10:13 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
The message currently reads:
"skipping CONFIG_ARCH_HAS_DATA_ABORT_MASK because test_zero_page=n\n"
when it should be the other way round. Fix that.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
test/self/mmu.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/test/self/mmu.c b/test/self/mmu.c
index 58961daaab95..dbe5004550a8 100644
--- a/test/self/mmu.c
+++ b/test/self/mmu.c
@@ -207,8 +207,8 @@ static void test_zero_page(void)
total_tests += 3;
if (!IS_ENABLED(CONFIG_ARCH_HAS_DATA_ABORT_MASK)) {
- pr_info("skipping %s because %s=n\n",
- "CONFIG_ARCH_HAS_DATA_ABORT_MASK", __func__);
+ pr_info("skipping %s because CONFIG_ARCH_HAS_DATA_ABORT_MASK=n\n",
+ __func__);
skipped_tests += 3;
return;
}
--
2.39.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH master 1/3] test: self: ramfs: fix null pointer dereference on error
2024-01-03 10:13 [PATCH master 1/3] test: self: ramfs: fix null pointer dereference on error Ahmad Fatoum
2024-01-03 10:13 ` [PATCH master 2/3] test: self: regulator: depend on REGULATOR_FIXED for test Ahmad Fatoum
2024-01-03 10:13 ` [PATCH master 3/3] test: self: mmu: fix message on skipping tests Ahmad Fatoum
@ 2024-01-03 14:10 ` Sascha Hauer
2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2024-01-03 14:10 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox
On Wed, Jan 03, 2024 at 11:13:42AM +0100, Ahmad Fatoum wrote:
> expect_success is meant for return values of functions that return
> negative error codes and as such compares the first argument to be
> zero or greater, which means PTR_ERR_OR_ZERO will treat NULL pointers as
> valid all the same leading to NULL pointer dereferences should the test
> fail instead of a descriptive error message. Fix this by translating
> NULL pointer to -errno or -EFAULT if errno is unset.
>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> test/self/ramfs.c | 17 +++++++++++++----
> 1 file changed, 13 insertions(+), 4 deletions(-)
Applied, thanks
Sascha
>
> diff --git a/test/self/ramfs.c b/test/self/ramfs.c
> index bce396dc171e..1bc2b3b068f0 100644
> --- a/test/self/ramfs.c
> +++ b/test/self/ramfs.c
> @@ -27,7 +27,16 @@ BSELFTEST_GLOBALS();
> __cond; \
> })
>
> +static inline int ptr_to_err(const void *ptr)
> +{
> + if (ptr)
> + return PTR_ERR_OR_ZERO(ptr);
> +
> + return -errno ?: -EFAULT;
> +}
> +
> #define expect_success(ret, ...) __expect((ret), (ret) >= 0, __VA_ARGS__)
> +#define expect_ptrok(ptr, ...) expect_success(ptr_to_err(ptr), __VA_ARGS__)
> #define expect_fail(ret, ...) __expect((ret), (ret) < 0, __VA_ARGS__)
>
> static inline int get_file_count(int i)
> @@ -101,7 +110,7 @@ static void test_ramfs(void)
> }
>
> dir = opendir(dname);
> - if (!expect_success(PTR_ERR_OR_ZERO(dir), "opening parent directory"))
> + if (!expect_ptrok(dir, "opening parent directory"))
> continue;
>
> j = 0;
> @@ -120,11 +129,11 @@ static void test_ramfs(void)
> }
>
> oldpwd = pushd(dname);
> - if (!expect_success(oldpwd != NULL ? 0 : -EINVAL, "pushd()"))
> + if (!expect_ptrok(oldpwd, "pushd()"))
> goto out;;
>
> dir = opendir(".");
> - if (!expect_success(PTR_ERR_OR_ZERO(dir), "opening parent directory"))
> + if (!expect_ptrok(dir, "opening parent directory"))
> goto out;
>
> i = 1;
> @@ -183,7 +192,7 @@ static void test_ramfs(void)
> expect_success(ret, "write_file()");
>
> buf = read_file("test/a/b/c/d/e/f/g/h/i/j/k/l/FILE", NULL);
> - if (expect_success(PTR_ERR_OR_ZERO(buf), "read_file()")) {
> + if (expect_ptrok(buf, "read_file()")) {
> expect_success(memcmp(buf, ARRAY_AND_SIZE(hello)),
> "read_file() content");
> }
> --
> 2.39.2
>
>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-01-03 14:11 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-03 10:13 [PATCH master 1/3] test: self: ramfs: fix null pointer dereference on error Ahmad Fatoum
2024-01-03 10:13 ` [PATCH master 2/3] test: self: regulator: depend on REGULATOR_FIXED for test Ahmad Fatoum
2024-01-03 10:13 ` [PATCH master 3/3] test: self: mmu: fix message on skipping tests Ahmad Fatoum
2024-01-03 14:10 ` [PATCH master 1/3] test: self: ramfs: fix null pointer dereference on error Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox