* [PATCH] vhost-user-scsi: avoid unlink(NULL) with fd passing
@ 2022-04-27 10:01 Stefan Hajnoczi
2022-04-30 3:44 ` Raphael Norwitz
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Stefan Hajnoczi @ 2022-04-27 10:01 UTC (permalink / raw)
To: qemu-devel; +Cc: Raphael Norwitz, Stefan Hajnoczi, Michael S. Tsirkin
Commit 747421e949fc1eb3ba66b5fcccdb7ba051918241 ("Implements Backend
Program conventions for vhost-user-scsi") introduced fd-passing support
as part of implementing the vhost-user backend program conventions.
When fd passing is used the UNIX domain socket path is NULL and we must
not call unlink(2).
Fixes: Coverity CID 1488353
Fixes: 747421e949fc1eb3ba66b5fcccdb7ba051918241 ("Implements Backend Program conventions for vhost-user-scsi")
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
contrib/vhost-user-scsi/vhost-user-scsi.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/contrib/vhost-user-scsi/vhost-user-scsi.c b/contrib/vhost-user-scsi/vhost-user-scsi.c
index b2c0f98253..08335d4b2b 100644
--- a/contrib/vhost-user-scsi/vhost-user-scsi.c
+++ b/contrib/vhost-user-scsi/vhost-user-scsi.c
@@ -433,7 +433,9 @@ out:
if (vdev_scsi) {
g_main_loop_unref(vdev_scsi->loop);
g_free(vdev_scsi);
- unlink(opt_socket_path);
+ if (opt_socket_path) {
+ unlink(opt_socket_path);
+ }
}
if (csock >= 0) {
close(csock);
--
2.35.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] vhost-user-scsi: avoid unlink(NULL) with fd passing
2022-04-27 10:01 [PATCH] vhost-user-scsi: avoid unlink(NULL) with fd passing Stefan Hajnoczi
@ 2022-04-30 3:44 ` Raphael Norwitz
2022-05-09 12:18 ` Philippe Mathieu-Daudé via
2022-05-12 15:57 ` Peter Maydell
2 siblings, 0 replies; 6+ messages in thread
From: Raphael Norwitz @ 2022-04-30 3:44 UTC (permalink / raw)
To: Stefan Hajnoczi; +Cc: Raphael Norwitz, qemu-devel, Michael S. Tsirkin
On Wed, Apr 27, 2022 at 11:01:16AM +0100, Stefan Hajnoczi wrote:
> Commit 747421e949fc1eb3ba66b5fcccdb7ba051918241 ("Implements Backend
> Program conventions for vhost-user-scsi") introduced fd-passing support
> as part of implementing the vhost-user backend program conventions.
>
> When fd passing is used the UNIX domain socket path is NULL and we must
> not call unlink(2).
>
> Fixes: Coverity CID 1488353
> Fixes: 747421e949fc1eb3ba66b5fcccdb7ba051918241 ("Implements Backend Program conventions for vhost-user-scsi")
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Raphael Norwitz <raphael.norwitz@nutanix.com>
> ---
> contrib/vhost-user-scsi/vhost-user-scsi.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/contrib/vhost-user-scsi/vhost-user-scsi.c b/contrib/vhost-user-scsi/vhost-user-scsi.c
> index b2c0f98253..08335d4b2b 100644
> --- a/contrib/vhost-user-scsi/vhost-user-scsi.c
> +++ b/contrib/vhost-user-scsi/vhost-user-scsi.c
> @@ -433,7 +433,9 @@ out:
> if (vdev_scsi) {
> g_main_loop_unref(vdev_scsi->loop);
> g_free(vdev_scsi);
> - unlink(opt_socket_path);
> + if (opt_socket_path) {
> + unlink(opt_socket_path);
> + }
> }
> if (csock >= 0) {
> close(csock);
> --
> 2.35.1
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] vhost-user-scsi: avoid unlink(NULL) with fd passing
2022-04-27 10:01 [PATCH] vhost-user-scsi: avoid unlink(NULL) with fd passing Stefan Hajnoczi
2022-04-30 3:44 ` Raphael Norwitz
@ 2022-05-09 12:18 ` Philippe Mathieu-Daudé via
2022-05-12 15:57 ` Peter Maydell
2 siblings, 0 replies; 6+ messages in thread
From: Philippe Mathieu-Daudé via @ 2022-05-09 12:18 UTC (permalink / raw)
To: Stefan Hajnoczi, qemu-devel; +Cc: Raphael Norwitz, Michael S. Tsirkin
On 27/4/22 12:01, Stefan Hajnoczi wrote:
> Commit 747421e949fc1eb3ba66b5fcccdb7ba051918241 ("Implements Backend
> Program conventions for vhost-user-scsi") introduced fd-passing support
> as part of implementing the vhost-user backend program conventions.
>
> When fd passing is used the UNIX domain socket path is NULL and we must
> not call unlink(2).
>
> Fixes: Coverity CID 1488353
> Fixes: 747421e949fc1eb3ba66b5fcccdb7ba051918241 ("Implements Backend Program conventions for vhost-user-scsi")
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
> contrib/vhost-user-scsi/vhost-user-scsi.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] vhost-user-scsi: avoid unlink(NULL) with fd passing
2022-04-27 10:01 [PATCH] vhost-user-scsi: avoid unlink(NULL) with fd passing Stefan Hajnoczi
2022-04-30 3:44 ` Raphael Norwitz
2022-05-09 12:18 ` Philippe Mathieu-Daudé via
@ 2022-05-12 15:57 ` Peter Maydell
2022-05-13 11:16 ` Michael S. Tsirkin
2022-05-16 15:57 ` Stefan Hajnoczi
2 siblings, 2 replies; 6+ messages in thread
From: Peter Maydell @ 2022-05-12 15:57 UTC (permalink / raw)
To: Stefan Hajnoczi; +Cc: qemu-devel, Raphael Norwitz, Michael S. Tsirkin
On Wed, 27 Apr 2022 at 11:04, Stefan Hajnoczi <stefanha@redhat.com> wrote:
>
> Commit 747421e949fc1eb3ba66b5fcccdb7ba051918241 ("Implements Backend
> Program conventions for vhost-user-scsi") introduced fd-passing support
> as part of implementing the vhost-user backend program conventions.
>
> When fd passing is used the UNIX domain socket path is NULL and we must
> not call unlink(2).
>
> Fixes: Coverity CID 1488353
> Fixes: 747421e949fc1eb3ba66b5fcccdb7ba051918241 ("Implements Backend Program conventions for vhost-user-scsi")
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
> contrib/vhost-user-scsi/vhost-user-scsi.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/contrib/vhost-user-scsi/vhost-user-scsi.c b/contrib/vhost-user-scsi/vhost-user-scsi.c
> index b2c0f98253..08335d4b2b 100644
> --- a/contrib/vhost-user-scsi/vhost-user-scsi.c
> +++ b/contrib/vhost-user-scsi/vhost-user-scsi.c
> @@ -433,7 +433,9 @@ out:
> if (vdev_scsi) {
> g_main_loop_unref(vdev_scsi->loop);
> g_free(vdev_scsi);
> - unlink(opt_socket_path);
> + if (opt_socket_path) {
> + unlink(opt_socket_path);
> + }
> }
Shouldn't this check-and-unlink be one level up, outside the
"if (vdev_scsi)" ? There are error exit paths which get us to
the 'out:' label where we have called unix_sock_new() but
not yet done the g_new0() of vdev_scsi(). The only thing
that needs to be guarded by "if (vdev_scsi)" is the
g_main_loop_unref() (the g_free of vdev_scsi itself could
be inside or outside, since g_free(NULL) is a nop).
thanks
-- PMM
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] vhost-user-scsi: avoid unlink(NULL) with fd passing
2022-05-12 15:57 ` Peter Maydell
@ 2022-05-13 11:16 ` Michael S. Tsirkin
2022-05-16 15:57 ` Stefan Hajnoczi
1 sibling, 0 replies; 6+ messages in thread
From: Michael S. Tsirkin @ 2022-05-13 11:16 UTC (permalink / raw)
To: Peter Maydell; +Cc: Stefan Hajnoczi, qemu-devel, Raphael Norwitz
On Thu, May 12, 2022 at 04:57:13PM +0100, Peter Maydell wrote:
> On Wed, 27 Apr 2022 at 11:04, Stefan Hajnoczi <stefanha@redhat.com> wrote:
> >
> > Commit 747421e949fc1eb3ba66b5fcccdb7ba051918241 ("Implements Backend
> > Program conventions for vhost-user-scsi") introduced fd-passing support
> > as part of implementing the vhost-user backend program conventions.
> >
> > When fd passing is used the UNIX domain socket path is NULL and we must
> > not call unlink(2).
> >
> > Fixes: Coverity CID 1488353
> > Fixes: 747421e949fc1eb3ba66b5fcccdb7ba051918241 ("Implements Backend Program conventions for vhost-user-scsi")
> > Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> > ---
> > contrib/vhost-user-scsi/vhost-user-scsi.c | 4 +++-
> > 1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/contrib/vhost-user-scsi/vhost-user-scsi.c b/contrib/vhost-user-scsi/vhost-user-scsi.c
> > index b2c0f98253..08335d4b2b 100644
> > --- a/contrib/vhost-user-scsi/vhost-user-scsi.c
> > +++ b/contrib/vhost-user-scsi/vhost-user-scsi.c
> > @@ -433,7 +433,9 @@ out:
> > if (vdev_scsi) {
> > g_main_loop_unref(vdev_scsi->loop);
> > g_free(vdev_scsi);
> > - unlink(opt_socket_path);
> > + if (opt_socket_path) {
> > + unlink(opt_socket_path);
> > + }
> > }
>
> Shouldn't this check-and-unlink be one level up, outside the
> "if (vdev_scsi)" ? There are error exit paths which get us to
> the 'out:' label where we have called unix_sock_new() but
> not yet done the g_new0() of vdev_scsi(). The only thing
> that needs to be guarded by "if (vdev_scsi)" is the
> g_main_loop_unref() (the g_free of vdev_scsi itself could
> be inside or outside, since g_free(NULL) is a nop).
>
> thanks
> -- PMM
Stefan, want to respond?
--
MST
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] vhost-user-scsi: avoid unlink(NULL) with fd passing
2022-05-12 15:57 ` Peter Maydell
2022-05-13 11:16 ` Michael S. Tsirkin
@ 2022-05-16 15:57 ` Stefan Hajnoczi
1 sibling, 0 replies; 6+ messages in thread
From: Stefan Hajnoczi @ 2022-05-16 15:57 UTC (permalink / raw)
To: Peter Maydell; +Cc: qemu-devel, Raphael Norwitz, Michael S. Tsirkin
[-- Attachment #1: Type: text/plain, Size: 1900 bytes --]
On Thu, May 12, 2022 at 04:57:13PM +0100, Peter Maydell wrote:
> On Wed, 27 Apr 2022 at 11:04, Stefan Hajnoczi <stefanha@redhat.com> wrote:
> >
> > Commit 747421e949fc1eb3ba66b5fcccdb7ba051918241 ("Implements Backend
> > Program conventions for vhost-user-scsi") introduced fd-passing support
> > as part of implementing the vhost-user backend program conventions.
> >
> > When fd passing is used the UNIX domain socket path is NULL and we must
> > not call unlink(2).
> >
> > Fixes: Coverity CID 1488353
> > Fixes: 747421e949fc1eb3ba66b5fcccdb7ba051918241 ("Implements Backend Program conventions for vhost-user-scsi")
> > Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> > ---
> > contrib/vhost-user-scsi/vhost-user-scsi.c | 4 +++-
> > 1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/contrib/vhost-user-scsi/vhost-user-scsi.c b/contrib/vhost-user-scsi/vhost-user-scsi.c
> > index b2c0f98253..08335d4b2b 100644
> > --- a/contrib/vhost-user-scsi/vhost-user-scsi.c
> > +++ b/contrib/vhost-user-scsi/vhost-user-scsi.c
> > @@ -433,7 +433,9 @@ out:
> > if (vdev_scsi) {
> > g_main_loop_unref(vdev_scsi->loop);
> > g_free(vdev_scsi);
> > - unlink(opt_socket_path);
> > + if (opt_socket_path) {
> > + unlink(opt_socket_path);
> > + }
> > }
>
> Shouldn't this check-and-unlink be one level up, outside the
> "if (vdev_scsi)" ? There are error exit paths which get us to
> the 'out:' label where we have called unix_sock_new() but
> not yet done the g_new0() of vdev_scsi(). The only thing
> that needs to be guarded by "if (vdev_scsi)" is the
> g_main_loop_unref() (the g_free of vdev_scsi itself could
> be inside or outside, since g_free(NULL) is a nop).
Sorry, I was offline last week due to illness. Now I'm back and agree
with what you found. I have sent a v2.
Stefan
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-05-16 16:21 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-27 10:01 [PATCH] vhost-user-scsi: avoid unlink(NULL) with fd passing Stefan Hajnoczi
2022-04-30 3:44 ` Raphael Norwitz
2022-05-09 12:18 ` Philippe Mathieu-Daudé via
2022-05-12 15:57 ` Peter Maydell
2022-05-13 11:16 ` Michael S. Tsirkin
2022-05-16 15:57 ` Stefan Hajnoczi
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.