* [Qemu-devel] [PATCH] monitor: properly handle invalid fd/vhostfd from command line @ 2010-09-27 7:52 Jason Wang 2010-09-27 10:49 ` [Qemu-devel] " Michael S. Tsirkin 2010-09-28 14:53 ` [Qemu-devel] " Luiz Capitulino 0 siblings, 2 replies; 8+ messages in thread From: Jason Wang @ 2010-09-27 7:52 UTC (permalink / raw) To: qemu-devel, anthony, mst monitor_get_fd() may also be used to parse fd or vhostfd from command line, so we need to check whether the pointer of mon is NULL to avoid segmentation fault when user pass invalid name of fd or vhostfd. Signed-off-by: Jason Wang <jasowang@redhat.com> --- monitor.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/monitor.c b/monitor.c index e602480..5bb4ff0 100644 --- a/monitor.c +++ b/monitor.c @@ -2345,6 +2345,10 @@ int monitor_get_fd(Monitor *mon, const char *fdname) { mon_fd_t *monfd; + if (mon == NULL) { + return -1; + } + QLIST_FOREACH(monfd, &mon->fds, next) { int fd; ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [Qemu-devel] Re: [PATCH] monitor: properly handle invalid fd/vhostfd from command line 2010-09-27 7:52 [Qemu-devel] [PATCH] monitor: properly handle invalid fd/vhostfd from command line Jason Wang @ 2010-09-27 10:49 ` Michael S. Tsirkin 2010-09-28 14:53 ` [Qemu-devel] " Luiz Capitulino 1 sibling, 0 replies; 8+ messages in thread From: Michael S. Tsirkin @ 2010-09-27 10:49 UTC (permalink / raw) To: Jason Wang; +Cc: qemu-devel On Mon, Sep 27, 2010 at 03:52:44PM +0800, Jason Wang wrote: > monitor_get_fd() may also be used to parse fd or vhostfd from command line, so > we need to check whether the pointer of mon is NULL to avoid segmentation fault > when user pass invalid name of fd or vhostfd. > > Signed-off-by: Jason Wang <jasowang@redhat.com> Acked-by: Michael S. Tsirkin <mst@redhat.com> > --- > monitor.c | 4 ++++ > 1 files changed, 4 insertions(+), 0 deletions(-) > > diff --git a/monitor.c b/monitor.c > index e602480..5bb4ff0 100644 > --- a/monitor.c > +++ b/monitor.c > @@ -2345,6 +2345,10 @@ int monitor_get_fd(Monitor *mon, const char *fdname) > { > mon_fd_t *monfd; > > + if (mon == NULL) { > + return -1; > + } > + > QLIST_FOREACH(monfd, &mon->fds, next) { > int fd; > > ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH] monitor: properly handle invalid fd/vhostfd from command line 2010-09-27 7:52 [Qemu-devel] [PATCH] monitor: properly handle invalid fd/vhostfd from command line Jason Wang 2010-09-27 10:49 ` [Qemu-devel] " Michael S. Tsirkin @ 2010-09-28 14:53 ` Luiz Capitulino 2010-09-28 14:57 ` Michael S. Tsirkin 1 sibling, 1 reply; 8+ messages in thread From: Luiz Capitulino @ 2010-09-28 14:53 UTC (permalink / raw) To: Jason Wang; +Cc: qemu-devel, mst On Mon, 27 Sep 2010 15:52:44 +0800 Jason Wang <jasowang@redhat.com> wrote: > monitor_get_fd() may also be used to parse fd or vhostfd from command line, so > we need to check whether the pointer of mon is NULL to avoid segmentation fault > when user pass invalid name of fd or vhostfd. Invalid fdname is handled just fine, I have the impression this patch fixes something else. Could you elaborate on the real problem here and/or show to reproduce? > Signed-off-by: Jason Wang <jasowang@redhat.com> > --- > monitor.c | 4 ++++ > 1 files changed, 4 insertions(+), 0 deletions(-) > > diff --git a/monitor.c b/monitor.c > index e602480..5bb4ff0 100644 > --- a/monitor.c > +++ b/monitor.c > @@ -2345,6 +2345,10 @@ int monitor_get_fd(Monitor *mon, const char *fdname) > { > mon_fd_t *monfd; > > + if (mon == NULL) { > + return -1; > + } > + > QLIST_FOREACH(monfd, &mon->fds, next) { > int fd; > > > ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH] monitor: properly handle invalid fd/vhostfd from command line 2010-09-28 14:53 ` [Qemu-devel] " Luiz Capitulino @ 2010-09-28 14:57 ` Michael S. Tsirkin 2010-10-08 17:40 ` Luiz Capitulino 0 siblings, 1 reply; 8+ messages in thread From: Michael S. Tsirkin @ 2010-09-28 14:57 UTC (permalink / raw) To: Luiz Capitulino; +Cc: Jason Wang, qemu-devel On Tue, Sep 28, 2010 at 11:53:43AM -0300, Luiz Capitulino wrote: > On Mon, 27 Sep 2010 15:52:44 +0800 > Jason Wang <jasowang@redhat.com> wrote: > > > monitor_get_fd() may also be used to parse fd or vhostfd from command line, so > > we need to check whether the pointer of mon is NULL to avoid segmentation fault > > when user pass invalid name of fd or vhostfd. > > Invalid fdname is handled just fine, I have the impression this patch fixes > something else. > > Could you elaborate on the real problem here and/or show to reproduce? Try pasing fd= (no value) as a parameter, and see what happens. > > Signed-off-by: Jason Wang <jasowang@redhat.com> > > --- > > monitor.c | 4 ++++ > > 1 files changed, 4 insertions(+), 0 deletions(-) > > > > diff --git a/monitor.c b/monitor.c > > index e602480..5bb4ff0 100644 > > --- a/monitor.c > > +++ b/monitor.c > > @@ -2345,6 +2345,10 @@ int monitor_get_fd(Monitor *mon, const char *fdname) > > { > > mon_fd_t *monfd; > > > > + if (mon == NULL) { > > + return -1; > > + } > > + > > QLIST_FOREACH(monfd, &mon->fds, next) { > > int fd; > > > > > > ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH] monitor: properly handle invalid fd/vhostfd from command line 2010-09-28 14:57 ` Michael S. Tsirkin @ 2010-10-08 17:40 ` Luiz Capitulino 2010-10-12 6:32 ` jason wang 0 siblings, 1 reply; 8+ messages in thread From: Luiz Capitulino @ 2010-10-08 17:40 UTC (permalink / raw) To: Michael S. Tsirkin; +Cc: Jason Wang, qemu-devel On Tue, 28 Sep 2010 16:57:44 +0200 "Michael S. Tsirkin" <mst@redhat.com> wrote: > On Tue, Sep 28, 2010 at 11:53:43AM -0300, Luiz Capitulino wrote: > > On Mon, 27 Sep 2010 15:52:44 +0800 > > Jason Wang <jasowang@redhat.com> wrote: > > > > > monitor_get_fd() may also be used to parse fd or vhostfd from command line, so > > > we need to check whether the pointer of mon is NULL to avoid segmentation fault > > > when user pass invalid name of fd or vhostfd. > > > > Invalid fdname is handled just fine, I have the impression this patch fixes > > something else. > > > > Could you elaborate on the real problem here and/or show to reproduce? > > Try pasing fd= (no value) as a parameter, and see what happens. Sorry for the delay on this one. If I'm reading this code correctly, we have two kinds of fd passing being handled by net_handle_fd_param(): fds passed via SCM_RIGHTS (handled by the monitor) and -net fds, passed via the command-line. In this case, we don't want the fd passed via SCM_RIGHTS, so net_handle_fd_param() has to be fixed to check for !mon and also check strtol()'s return: diff --git a/net.c b/net.c index 3d0fde7..6aaa653 100644 --- a/net.c +++ b/net.c @@ -739,9 +739,9 @@ int qemu_find_nic_model(NICInfo *nd, const char * const *models, int net_handle_fd_param(Monitor *mon, const char *param) { - if (!qemu_isdigit(param[0])) { - int fd; + int fd; + if (!qemu_isdigit(param[0]) && mon) { fd = monitor_get_fd(mon, param); if (fd == -1) { error_report("No file descriptor named %s found", param); @@ -750,7 +750,13 @@ int net_handle_fd_param(Monitor *mon, const char *param) return fd; } else { - return strtol(param, NULL, 0); + char *endptr = NULL; + + fd = strtol(param, &endptr, 10); + if (*endptr || (fd == 0 && param == endptr)) { + return -1; + } + return fd; } } There's more: qemu doesn't exit when an invalid fd is passed: """ ~/stuff/virt/ ./qemu-qmp -hda disks/test.img -enable-kvm -m 1G -snapshot -net tap,fd=40 qemu-qmp: -net tap,fd=40: TUNGETIFF ioctl() failed: Bad file descriptor TUNSETOFFLOAD ioctl() failed: Bad file descriptor Warning: vlan 0 with no nics """ And QEMU is up and running... > > > > Signed-off-by: Jason Wang <jasowang@redhat.com> > > > --- > > > monitor.c | 4 ++++ > > > 1 files changed, 4 insertions(+), 0 deletions(-) > > > > > > diff --git a/monitor.c b/monitor.c > > > index e602480..5bb4ff0 100644 > > > --- a/monitor.c > > > +++ b/monitor.c > > > @@ -2345,6 +2345,10 @@ int monitor_get_fd(Monitor *mon, const char *fdname) > > > { > > > mon_fd_t *monfd; > > > > > > + if (mon == NULL) { > > > + return -1; > > > + } > > > + > > > QLIST_FOREACH(monfd, &mon->fds, next) { > > > int fd; > > > > > > > > > > ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH] monitor: properly handle invalid fd/vhostfd from command line 2010-10-08 17:40 ` Luiz Capitulino @ 2010-10-12 6:32 ` jason wang 2010-10-13 13:35 ` Luiz Capitulino 0 siblings, 1 reply; 8+ messages in thread From: jason wang @ 2010-10-12 6:32 UTC (permalink / raw) To: Luiz Capitulino; +Cc: qemu-devel, Michael S. Tsirkin [-- Attachment #1: Type: text/plain, Size: 3243 bytes --] On 10/09/2010 01:40 AM, Luiz Capitulino wrote: > On Tue, 28 Sep 2010 16:57:44 +0200 > "Michael S. Tsirkin"<mst@redhat.com> wrote: > > >> On Tue, Sep 28, 2010 at 11:53:43AM -0300, Luiz Capitulino wrote: >> >>> On Mon, 27 Sep 2010 15:52:44 +0800 >>> Jason Wang<jasowang@redhat.com> wrote: >>> >>> >>>> monitor_get_fd() may also be used to parse fd or vhostfd from command line, so >>>> we need to check whether the pointer of mon is NULL to avoid segmentation fault >>>> when user pass invalid name of fd or vhostfd. >>>> >>> Invalid fdname is handled just fine, I have the impression this patch fixes >>> something else. >>> >>> Could you elaborate on the real problem here and/or show to reproduce? >>> >> Try pasing fd= (no value) as a parameter, and see what happens. >> > Sorry for the delay on this one. > > If I'm reading this code correctly, we have two kinds of fd passing being > handled by net_handle_fd_param(): fds passed via SCM_RIGHTS (handled by > the monitor) and -net fds, passed via the command-line. > > In this case, we don't want the fd passed via SCM_RIGHTS, so > net_handle_fd_param() has to be fixed to check for !mon and also check > strtol()'s return: > Yes, it's better to check strtol()'s return which was missed in the original patch. > diff --git a/net.c b/net.c > index 3d0fde7..6aaa653 100644 > --- a/net.c > +++ b/net.c > @@ -739,9 +739,9 @@ int qemu_find_nic_model(NICInfo *nd, const char * const *models, > > int net_handle_fd_param(Monitor *mon, const char *param) > { > - if (!qemu_isdigit(param[0])) { > - int fd; > + int fd; > > + if (!qemu_isdigit(param[0])&& mon) { > fd = monitor_get_fd(mon, param); > if (fd == -1) { > error_report("No file descriptor named %s found", param); > @@ -750,7 +750,13 @@ int net_handle_fd_param(Monitor *mon, const char *param) > > return fd; > } else { > - return strtol(param, NULL, 0); > + char *endptr = NULL; > + > + fd = strtol(param,&endptr, 10); > + if (*endptr || (fd == 0&& param == endptr)) { > + return -1; > + } > + return fd; > } > } > This looks good for me. > There's more: qemu doesn't exit when an invalid fd is passed: > > """ > ~/stuff/virt/ ./qemu-qmp -hda disks/test.img -enable-kvm -m 1G -snapshot -net tap,fd=40 > qemu-qmp: -net tap,fd=40: TUNGETIFF ioctl() failed: Bad file descriptor > TUNSETOFFLOAD ioctl() failed: Bad file descriptor > Warning: vlan 0 with no nics > """ > > And QEMU is up and running...// > Anthony have proposed a patch for this. // > > >> >>>> Signed-off-by: Jason Wang<jasowang@redhat.com> >>>> --- >>>> monitor.c | 4 ++++ >>>> 1 files changed, 4 insertions(+), 0 deletions(-) >>>> >>>> diff --git a/monitor.c b/monitor.c >>>> index e602480..5bb4ff0 100644 >>>> --- a/monitor.c >>>> +++ b/monitor.c >>>> @@ -2345,6 +2345,10 @@ int monitor_get_fd(Monitor *mon, const char *fdname) >>>> { >>>> mon_fd_t *monfd; >>>> >>>> + if (mon == NULL) { >>>> + return -1; >>>> + } >>>> + >>>> QLIST_FOREACH(monfd,&mon->fds, next) { >>>> int fd; >>>> >>>> >>>> >>>> >> > > [-- Attachment #2: Type: text/html, Size: 4389 bytes --] ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH] monitor: properly handle invalid fd/vhostfd from command line 2010-10-12 6:32 ` jason wang @ 2010-10-13 13:35 ` Luiz Capitulino 2010-10-14 2:21 ` Jason Wang 0 siblings, 1 reply; 8+ messages in thread From: Luiz Capitulino @ 2010-10-13 13:35 UTC (permalink / raw) To: jason wang; +Cc: qemu-devel, Michael S. Tsirkin On Tue, 12 Oct 2010 14:32:25 +0800 jason wang <jasowang@redhat.com> wrote: > On 10/09/2010 01:40 AM, Luiz Capitulino wrote: > > On Tue, 28 Sep 2010 16:57:44 +0200 > > "Michael S. Tsirkin"<mst@redhat.com> wrote: > > > > > >> On Tue, Sep 28, 2010 at 11:53:43AM -0300, Luiz Capitulino wrote: > >> > >>> On Mon, 27 Sep 2010 15:52:44 +0800 > >>> Jason Wang<jasowang@redhat.com> wrote: > >>> > >>> > >>>> monitor_get_fd() may also be used to parse fd or vhostfd from command line, so > >>>> we need to check whether the pointer of mon is NULL to avoid segmentation fault > >>>> when user pass invalid name of fd or vhostfd. > >>>> > >>> Invalid fdname is handled just fine, I have the impression this patch fixes > >>> something else. > >>> > >>> Could you elaborate on the real problem here and/or show to reproduce? > >>> > >> Try pasing fd= (no value) as a parameter, and see what happens. > >> > > Sorry for the delay on this one. > > > > If I'm reading this code correctly, we have two kinds of fd passing being > > handled by net_handle_fd_param(): fds passed via SCM_RIGHTS (handled by > > the monitor) and -net fds, passed via the command-line. > > > > In this case, we don't want the fd passed via SCM_RIGHTS, so > > net_handle_fd_param() has to be fixed to check for !mon and also check > > strtol()'s return: > > > Yes, it's better to check strtol()'s return which was missed in the > original patch. > > diff --git a/net.c b/net.c > > index 3d0fde7..6aaa653 100644 > > --- a/net.c > > +++ b/net.c > > @@ -739,9 +739,9 @@ int qemu_find_nic_model(NICInfo *nd, const char * const *models, > > > > int net_handle_fd_param(Monitor *mon, const char *param) > > { > > - if (!qemu_isdigit(param[0])) { > > - int fd; > > + int fd; > > > > + if (!qemu_isdigit(param[0])&& mon) { > > fd = monitor_get_fd(mon, param); > > if (fd == -1) { > > error_report("No file descriptor named %s found", param); > > @@ -750,7 +750,13 @@ int net_handle_fd_param(Monitor *mon, const char *param) > > > > return fd; > > } else { > > - return strtol(param, NULL, 0); > > + char *endptr = NULL; > > + > > + fd = strtol(param,&endptr, 10); > > + if (*endptr || (fd == 0&& param == endptr)) { > > + return -1; > > + } > > + return fd; > > } > > } > > > This looks good for me. Would you mind taking care of this one? I mean, I didn't even test this much :-) So, you could test it more and submit it again as a proper patch. Thanks. > > There's more: qemu doesn't exit when an invalid fd is passed: > > > > """ > > ~/stuff/virt/ ./qemu-qmp -hda disks/test.img -enable-kvm -m 1G -snapshot -net tap,fd=40 > > qemu-qmp: -net tap,fd=40: TUNGETIFF ioctl() failed: Bad file descriptor > > TUNSETOFFLOAD ioctl() failed: Bad file descriptor > > Warning: vlan 0 with no nics > > """ > > > > And QEMU is up and running...// > > > Anthony have proposed a patch for this. > // > > > > > >> > >>>> Signed-off-by: Jason Wang<jasowang@redhat.com> > >>>> --- > >>>> monitor.c | 4 ++++ > >>>> 1 files changed, 4 insertions(+), 0 deletions(-) > >>>> > >>>> diff --git a/monitor.c b/monitor.c > >>>> index e602480..5bb4ff0 100644 > >>>> --- a/monitor.c > >>>> +++ b/monitor.c > >>>> @@ -2345,6 +2345,10 @@ int monitor_get_fd(Monitor *mon, const char *fdname) > >>>> { > >>>> mon_fd_t *monfd; > >>>> > >>>> + if (mon == NULL) { > >>>> + return -1; > >>>> + } > >>>> + > >>>> QLIST_FOREACH(monfd,&mon->fds, next) { > >>>> int fd; > >>>> > >>>> > >>>> > >>>> > >> > > > > > ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH] monitor: properly handle invalid fd/vhostfd from command line 2010-10-13 13:35 ` Luiz Capitulino @ 2010-10-14 2:21 ` Jason Wang 0 siblings, 0 replies; 8+ messages in thread From: Jason Wang @ 2010-10-14 2:21 UTC (permalink / raw) To: Luiz Capitulino; +Cc: qemu-devel, Michael S. Tsirkin ----- "Luiz Capitulino" <lcapitulino@redhat.com> wrote: > On Tue, 12 Oct 2010 14:32:25 +0800 > jason wang <jasowang@redhat.com> wrote: > > > On 10/09/2010 01:40 AM, Luiz Capitulino wrote: > > > On Tue, 28 Sep 2010 16:57:44 +0200 > > > "Michael S. Tsirkin"<mst@redhat.com> wrote: > > > > > > > > >> On Tue, Sep 28, 2010 at 11:53:43AM -0300, Luiz Capitulino wrote: > > >> > > >>> On Mon, 27 Sep 2010 15:52:44 +0800 > > >>> Jason Wang<jasowang@redhat.com> wrote: > > >>> > > >>> > > >>>> monitor_get_fd() may also be used to parse fd or vhostfd from > command line, so > > >>>> we need to check whether the pointer of mon is NULL to avoid > segmentation fault > > >>>> when user pass invalid name of fd or vhostfd. > > >>>> > > >>> Invalid fdname is handled just fine, I have the impression this > patch fixes > > >>> something else. > > >>> > > >>> Could you elaborate on the real problem here and/or show to > reproduce? > > >>> > > >> Try pasing fd= (no value) as a parameter, and see what happens. > > >> > > > Sorry for the delay on this one. > > > > > > If I'm reading this code correctly, we have two kinds of fd > passing being > > > handled by net_handle_fd_param(): fds passed via SCM_RIGHTS > (handled by > > > the monitor) and -net fds, passed via the command-line. > > > > > > In this case, we don't want the fd passed via SCM_RIGHTS, so > > > net_handle_fd_param() has to be fixed to check for !mon and also > check > > > strtol()'s return: > > > > > Yes, it's better to check strtol()'s return which was missed in the > > > original patch. > > > diff --git a/net.c b/net.c > > > index 3d0fde7..6aaa653 100644 > > > --- a/net.c > > > +++ b/net.c > > > @@ -739,9 +739,9 @@ int qemu_find_nic_model(NICInfo *nd, const > char * const *models, > > > > > > int net_handle_fd_param(Monitor *mon, const char *param) > > > { > > > - if (!qemu_isdigit(param[0])) { > > > - int fd; > > > + int fd; > > > > > > + if (!qemu_isdigit(param[0])&& mon) { > > > fd = monitor_get_fd(mon, param); > > > if (fd == -1) { > > > error_report("No file descriptor named %s found", > param); > > > @@ -750,7 +750,13 @@ int net_handle_fd_param(Monitor *mon, const > char *param) > > > > > > return fd; > > > } else { > > > - return strtol(param, NULL, 0); > > > + char *endptr = NULL; > > > + > > > + fd = strtol(param,&endptr, 10); > > > + if (*endptr || (fd == 0&& param == endptr)) { > > > + return -1; > > > + } > > > + return fd; > > > } > > > } > > > > > This looks good for me. > > Would you mind taking care of this one? I mean, I didn't even test > this much :-) > > So, you could test it more and submit it again as a proper patch. > > Thanks. Sure, would post this later. > > > > There's more: qemu doesn't exit when an invalid fd is passed: > > > > > > """ > > > ~/stuff/virt/ ./qemu-qmp -hda disks/test.img -enable-kvm -m 1G > -snapshot -net tap,fd=40 > > > qemu-qmp: -net tap,fd=40: TUNGETIFF ioctl() failed: Bad file > descriptor > > > TUNSETOFFLOAD ioctl() failed: Bad file descriptor > > > Warning: vlan 0 with no nics > > > """ > > > > > > And QEMU is up and running...// > > > > > Anthony have proposed a patch for this. > > // > > > > > > > > >> > > >>>> Signed-off-by: Jason Wang<jasowang@redhat.com> > > >>>> --- > > >>>> monitor.c | 4 ++++ > > >>>> 1 files changed, 4 insertions(+), 0 deletions(-) > > >>>> > > >>>> diff --git a/monitor.c b/monitor.c > > >>>> index e602480..5bb4ff0 100644 > > >>>> --- a/monitor.c > > >>>> +++ b/monitor.c > > >>>> @@ -2345,6 +2345,10 @@ int monitor_get_fd(Monitor *mon, const > char *fdname) > > >>>> { > > >>>> mon_fd_t *monfd; > > >>>> > > >>>> + if (mon == NULL) { > > >>>> + return -1; > > >>>> + } > > >>>> + > > >>>> QLIST_FOREACH(monfd,&mon->fds, next) { > > >>>> int fd; > > >>>> > > >>>> > > >>>> > > >>>> > > >> > > > > > > > > ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2010-10-14 2:21 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2010-09-27 7:52 [Qemu-devel] [PATCH] monitor: properly handle invalid fd/vhostfd from command line Jason Wang 2010-09-27 10:49 ` [Qemu-devel] " Michael S. Tsirkin 2010-09-28 14:53 ` [Qemu-devel] " Luiz Capitulino 2010-09-28 14:57 ` Michael S. Tsirkin 2010-10-08 17:40 ` Luiz Capitulino 2010-10-12 6:32 ` jason wang 2010-10-13 13:35 ` Luiz Capitulino 2010-10-14 2:21 ` Jason Wang
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).