* [PATCH] selftests/memfd/memfd_test: Fix possible NULL pointer dereference
@ 2025-01-14 3:21 liuye
2025-01-14 4:13 ` Andrew Morton
2025-01-14 11:10 ` Lorenzo Stoakes
0 siblings, 2 replies; 3+ messages in thread
From: liuye @ 2025-01-14 3:21 UTC (permalink / raw)
To: shuah
Cc: akpm, jeffxu, isaacmanjarres, lorenzo.stoakes, gthelen,
sauravshah.31, linux-kselftest, linux-kernel, liuye
If name is NULL, a NULL pointer may be accessed in printf.
Signed-off-by: liuye <liuye@kylinos.cn>
---
tools/testing/selftests/memfd/memfd_test.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/memfd/memfd_test.c b/tools/testing/selftests/memfd/memfd_test.c
index c0c53451a16d..5b993924cc3f 100644
--- a/tools/testing/selftests/memfd/memfd_test.c
+++ b/tools/testing/selftests/memfd/memfd_test.c
@@ -171,7 +171,7 @@ static void mfd_fail_new(const char *name, unsigned int flags)
r = sys_memfd_create(name, flags);
if (r >= 0) {
printf("memfd_create(\"%s\", %u) succeeded, but failure expected\n",
- name, flags);
+ name ? name : "NULL", flags);
close(r);
abort();
}
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] selftests/memfd/memfd_test: Fix possible NULL pointer dereference
2025-01-14 3:21 [PATCH] selftests/memfd/memfd_test: Fix possible NULL pointer dereference liuye
@ 2025-01-14 4:13 ` Andrew Morton
2025-01-14 11:10 ` Lorenzo Stoakes
1 sibling, 0 replies; 3+ messages in thread
From: Andrew Morton @ 2025-01-14 4:13 UTC (permalink / raw)
To: liuye
Cc: shuah, jeffxu, isaacmanjarres, lorenzo.stoakes, gthelen,
sauravshah.31, linux-kselftest, linux-kernel
On Tue, 14 Jan 2025 11:21:15 +0800 liuye <liuye@kylinos.cn> wrote:
> If name is NULL, a NULL pointer may be accessed in printf.
>
> ...
>
> --- a/tools/testing/selftests/memfd/memfd_test.c
> +++ b/tools/testing/selftests/memfd/memfd_test.c
> @@ -171,7 +171,7 @@ static void mfd_fail_new(const char *name, unsigned int flags)
> r = sys_memfd_create(name, flags);
> if (r >= 0) {
> printf("memfd_create(\"%s\", %u) succeeded, but failure expected\n",
> - name, flags);
> + name ? name : "NULL", flags);
> close(r);
> abort();
Well huh. I though printf() would emit "(null)" in this situation, but
my super-sophisticated test case says "core dumped".
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("%s\n", (char *)0);
exit(0);
}
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] selftests/memfd/memfd_test: Fix possible NULL pointer dereference
2025-01-14 3:21 [PATCH] selftests/memfd/memfd_test: Fix possible NULL pointer dereference liuye
2025-01-14 4:13 ` Andrew Morton
@ 2025-01-14 11:10 ` Lorenzo Stoakes
1 sibling, 0 replies; 3+ messages in thread
From: Lorenzo Stoakes @ 2025-01-14 11:10 UTC (permalink / raw)
To: liuye
Cc: shuah, akpm, jeffxu, isaacmanjarres, gthelen, sauravshah.31,
linux-kselftest, linux-kernel
On Tue, Jan 14, 2025 at 11:21:15AM +0800, liuye wrote:
> If name is NULL, a NULL pointer may be accessed in printf.
>
> Signed-off-by: liuye <liuye@kylinos.cn>
Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
> ---
> tools/testing/selftests/memfd/memfd_test.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/memfd/memfd_test.c b/tools/testing/selftests/memfd/memfd_test.c
> index c0c53451a16d..5b993924cc3f 100644
> --- a/tools/testing/selftests/memfd/memfd_test.c
> +++ b/tools/testing/selftests/memfd/memfd_test.c
> @@ -171,7 +171,7 @@ static void mfd_fail_new(const char *name, unsigned int flags)
> r = sys_memfd_create(name, flags);
> if (r >= 0) {
> printf("memfd_create(\"%s\", %u) succeeded, but failure expected\n",
> - name, flags);
> + name ? name : "NULL", flags);
Damn, I was going to say 'oh hey we never pass NULL' but in test_create() we
explicitly... do. Good spot!
> close(r);
> abort();
> }
> --
> 2.25.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-01-14 11:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-14 3:21 [PATCH] selftests/memfd/memfd_test: Fix possible NULL pointer dereference liuye
2025-01-14 4:13 ` Andrew Morton
2025-01-14 11:10 ` Lorenzo Stoakes
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox