* [PATCH] softmmu/physmem.c: Check return value from realpath()
@ 2021-08-12 15:15 Peter Maydell
2021-08-13 7:24 ` Liu, Jingqi
2021-08-13 12:29 ` Paolo Bonzini
0 siblings, 2 replies; 3+ messages in thread
From: Peter Maydell @ 2021-08-12 15:15 UTC (permalink / raw)
To: qemu-devel; +Cc: Paolo Bonzini, Jingqi Liu
The realpath() function can return NULL on error, so we need to check
for it to avoid crashing when we try to strstr() into it.
This can happen if we run out of memory, or if /sys/ is not mounted,
among other situations.
Fixes: Coverity 1459913, 1460474
Fixes: ce317be98db0 ("exec: fetch the alignment of Linux devdax pmem character device nodes")
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
softmmu/physmem.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/softmmu/physmem.c b/softmmu/physmem.c
index c47cb6da2e4..eb0595d57c4 100644
--- a/softmmu/physmem.c
+++ b/softmmu/physmem.c
@@ -1451,6 +1451,9 @@ static int64_t get_file_align(int fd)
path = g_strdup_printf("/sys/dev/char/%d:%d",
major(st.st_rdev), minor(st.st_rdev));
rpath = realpath(path, NULL);
+ if (!rpath) {
+ return -errno;
+ }
rc = daxctl_new(&ctx);
if (rc) {
--
2.20.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] softmmu/physmem.c: Check return value from realpath()
2021-08-12 15:15 [PATCH] softmmu/physmem.c: Check return value from realpath() Peter Maydell
@ 2021-08-13 7:24 ` Liu, Jingqi
2021-08-13 12:29 ` Paolo Bonzini
1 sibling, 0 replies; 3+ messages in thread
From: Liu, Jingqi @ 2021-08-13 7:24 UTC (permalink / raw)
To: Peter Maydell, qemu-devel; +Cc: Paolo Bonzini
On 8/12/2021 11:15 PM, Peter Maydell wrote:
> The realpath() function can return NULL on error, so we need to check
> for it to avoid crashing when we try to strstr() into it.
> This can happen if we run out of memory, or if /sys/ is not mounted,
> among other situations.
>
> Fixes: Coverity 1459913, 1460474
> Fixes: ce317be98db0 ("exec: fetch the alignment of Linux devdax pmem character device nodes")
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> softmmu/physmem.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/softmmu/physmem.c b/softmmu/physmem.c
> index c47cb6da2e4..eb0595d57c4 100644
> --- a/softmmu/physmem.c
> +++ b/softmmu/physmem.c
> @@ -1451,6 +1451,9 @@ static int64_t get_file_align(int fd)
> path = g_strdup_printf("/sys/dev/char/%d:%d",
> major(st.st_rdev), minor(st.st_rdev));
> rpath = realpath(path, NULL);
> + if (!rpath) {
> + return -errno;
> + }
Good find!
Reviewed-by: Jingqi Liu <jingqi.liu@intel.com>
Thanks,
Jingqi
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] softmmu/physmem.c: Check return value from realpath()
2021-08-12 15:15 [PATCH] softmmu/physmem.c: Check return value from realpath() Peter Maydell
2021-08-13 7:24 ` Liu, Jingqi
@ 2021-08-13 12:29 ` Paolo Bonzini
1 sibling, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2021-08-13 12:29 UTC (permalink / raw)
To: Peter Maydell, qemu-devel; +Cc: Jingqi Liu
On 12/08/21 17:15, Peter Maydell wrote:
> The realpath() function can return NULL on error, so we need to check
> for it to avoid crashing when we try to strstr() into it.
> This can happen if we run out of memory, or if /sys/ is not mounted,
> among other situations.
>
> Fixes: Coverity 1459913, 1460474
> Fixes: ce317be98db0 ("exec: fetch the alignment of Linux devdax pmem character device nodes")
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> softmmu/physmem.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/softmmu/physmem.c b/softmmu/physmem.c
> index c47cb6da2e4..eb0595d57c4 100644
> --- a/softmmu/physmem.c
> +++ b/softmmu/physmem.c
> @@ -1451,6 +1451,9 @@ static int64_t get_file_align(int fd)
> path = g_strdup_printf("/sys/dev/char/%d:%d",
> major(st.st_rdev), minor(st.st_rdev));
> rpath = realpath(path, NULL);
> + if (!rpath) {
> + return -errno;
> + }
>
> rc = daxctl_new(&ctx);
> if (rc) {
>
Queued, thanks.
Paolo
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-08-13 12:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-12 15:15 [PATCH] softmmu/physmem.c: Check return value from realpath() Peter Maydell
2021-08-13 7:24 ` Liu, Jingqi
2021-08-13 12:29 ` Paolo Bonzini
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.