* [Qemu-devel] [PATCH] net: avoid segfault in case netdev_del non-host network device
@ 2012-11-01 7:48 Lei Li
2012-11-01 9:42 ` Stefan Hajnoczi
0 siblings, 1 reply; 4+ messages in thread
From: Lei Li @ 2012-11-01 7:48 UTC (permalink / raw)
To: qemu-devel; +Cc: Lei Li
netdev_del assume that remove host network device.
However, when try to remove a non-host network device
by netdev_del, it will cause a segfault.
The reson is that qmp_netdev_del is not checking for
a NULL return for qemu_find_opts_err in case find_list
did not find the netdev group to delete.
Catch this and return an error.
(qemu) host_net_add user vlan=1,name=con.1,hostfwd=udp::4111-127.0.0.1:4333
(qemu) info network
hub 1
\ con.1: type=user,net=10.0.2.0,restrict=off
hub 0
\ user.0: type=user,net=10.0.2.0,restrict=off
\ e1000.0: type=nic,model=e1000,macaddr=52:54:00:12:34:56
(qemu) netdev_del con.1
Segmentation fault (core dumped)
Signed-off-by: Lei Li <lilei@linux.vnet.ibm.com>
---
net.c | 8 +++++++-
1 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/net.c b/net.c
index ae4bc0d..cc52552 100644
--- a/net.c
+++ b/net.c
@@ -827,6 +827,7 @@ exit_err:
void qmp_netdev_del(const char *id, Error **errp)
{
NetClientState *nc;
+ QemuOptsList *opt;
nc = qemu_find_netdev(id);
if (!nc) {
@@ -835,7 +836,12 @@ void qmp_netdev_del(const char *id, Error **errp)
}
qemu_del_net_client(nc);
- qemu_opts_del(qemu_opts_find(qemu_find_opts_err("netdev", errp), id));
+ opt = qemu_find_opts_err("netdev", errp);
+ if (errp) {
+ error_setg(errp, "Failed to delete %s", id);
+ return;
+ }
+ qemu_opts_del(qemu_opts_find(opt, id));
}
void print_net_client(Monitor *mon, NetClientState *nc)
--
1.7.7.6
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] net: avoid segfault in case netdev_del non-host network device
2012-11-01 7:48 [Qemu-devel] [PATCH] net: avoid segfault in case netdev_del non-host network device Lei Li
@ 2012-11-01 9:42 ` Stefan Hajnoczi
2012-11-02 2:10 ` Lei Li
0 siblings, 1 reply; 4+ messages in thread
From: Stefan Hajnoczi @ 2012-11-01 9:42 UTC (permalink / raw)
To: Lei Li; +Cc: qemu-devel
On Thu, Nov 1, 2012 at 8:48 AM, Lei Li <lilei@linux.vnet.ibm.com> wrote:
> netdev_del assume that remove host network device.
> However, when try to remove a non-host network device
> by netdev_del, it will cause a segfault.
I recently sent a similar fix which forbids deleting non-netdev net
clients from netdev_del:
http://patchwork.ozlabs.org/patch/193759/
netdev_del should only be used on -netdev/netdev_add devices.
Therefore my patch raises an error before we call
qemu_del_net_client(nc).
Stefan
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] net: avoid segfault in case netdev_del non-host network device
2012-11-01 9:42 ` Stefan Hajnoczi
@ 2012-11-02 2:10 ` Lei Li
2012-11-02 7:38 ` Stefan Hajnoczi
0 siblings, 1 reply; 4+ messages in thread
From: Lei Li @ 2012-11-02 2:10 UTC (permalink / raw)
To: Stefan Hajnoczi; +Cc: qemu-devel
On 11/01/2012 05:42 PM, Stefan Hajnoczi wrote:
> On Thu, Nov 1, 2012 at 8:48 AM, Lei Li <lilei@linux.vnet.ibm.com> wrote:
>> netdev_del assume that remove host network device.
>> However, when try to remove a non-host network device
>> by netdev_del, it will cause a segfault.
> I recently sent a similar fix which forbids deleting non-netdev net
> clients from netdev_del:
> http://patchwork.ozlabs.org/patch/193759/
Hi Stefan,
Sorry I did not see it... Seems I miss this chance to submit a patch. :-P
BTW, I was thinking that should we add another hacking to check
if the deleting object is a netdev or a VLAN client?
>
> netdev_del should only be used on -netdev/netdev_add devices.
> Therefore my patch raises an error before we call
> qemu_del_net_client(nc).
>
> Stefan
>
--
Lei
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] net: avoid segfault in case netdev_del non-host network device
2012-11-02 2:10 ` Lei Li
@ 2012-11-02 7:38 ` Stefan Hajnoczi
0 siblings, 0 replies; 4+ messages in thread
From: Stefan Hajnoczi @ 2012-11-02 7:38 UTC (permalink / raw)
To: Lei Li; +Cc: qemu-devel
On Fri, Nov 2, 2012 at 3:10 AM, Lei Li <lilei@linux.vnet.ibm.com> wrote:
> On 11/01/2012 05:42 PM, Stefan Hajnoczi wrote:
>>
>> On Thu, Nov 1, 2012 at 8:48 AM, Lei Li <lilei@linux.vnet.ibm.com> wrote:
>>>
>>> netdev_del assume that remove host network device.
>>> However, when try to remove a non-host network device
>>> by netdev_del, it will cause a segfault.
>>
>> I recently sent a similar fix which forbids deleting non-netdev net
>> clients from netdev_del:
>> http://patchwork.ozlabs.org/patch/193759/
>
>
> Hi Stefan,
>
> Sorry I did not see it... Seems I miss this chance to submit a patch. :-P
>
> BTW, I was thinking that should we add another hacking to check
> if the deleting object is a netdev or a VLAN client?
netdev_del now only deletes -netdev or netdev_add net clients. It
refuses to delete -net clients because they are not in the "netdev"
QemuOptsList. It also refuses to delete net/hub.c ports that were
added by net_hub_add_port() because they are not in the "netdev"
QemuOptsList.
I'm not sure I understand what you are suggesting?
Stefan
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-11-02 7:38 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-01 7:48 [Qemu-devel] [PATCH] net: avoid segfault in case netdev_del non-host network device Lei Li
2012-11-01 9:42 ` Stefan Hajnoczi
2012-11-02 2:10 ` Lei Li
2012-11-02 7:38 ` Stefan Hajnoczi
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).