virtio-net: fix wild pointer when remove virtio-net queues
PATCH 1/1 virtio-net: fix wild pointer when remove virtio-net queues
The tx_bh or tx_timer will free in virtio_net_del_queue() function, when removing virtio-net queues if the guest doesn't support multiqueue. But it might be still referenced by virtio_net_set_status(), which needs to be set NULL. And also the tx_waiting needs to be set zero to prevent virtio_net_set_status() accessing tx_bh or tx_timer.
--- hw/net/virtio-net.c | 3 +++ 1 file changed, 3 insertions(+)
hw/net/virtio-net.c +3 -0
@@ -1522,9 +1522,12 @@ static void virtio_net_del_queue(VirtIONet *n, int index)if (q->tx_timer) {timer_del (q->tx_timer);timer_free (q->tx_timer); + q->tx_timer =NULL ; }else {qemu_bh_delete (q->tx_bh); + q->tx_bh =NULL ; } + q->tx_waiting =0 ;virtio_del_queue (vdev, index *2 +1 ); }
Signature · 1 line
1.8.3.1
Quoted 18 lines · Yunjian Wang
The
tx_bhortx_timerwill free invirtio_net_del_queue()function, when removing virtio-net queues if the guest doesn't support multiqueue. But it might be still referenced byvirtio_net_set_status(), which needs to be set NULL. And also thetx_waitingneeds to be set zero to preventvirtio_net_set_status()accessingtx_bhortx_timer.Signed-off-by Yunjian Wang <[email protected]>--- hw/net/virtio-net.c | 3 +++ 1 file changed, 3 insertions(+)hw/net/virtio-net.c +0
-0@@ -1522,9 +1522,12 @@ static void virtio_net_del_queue(VirtIONet *n, int index)if (q->tx_timer) {timer_del (q->tx_timer);
hw/net/virtio-net.c static void virtio_net_del_queue(VirtIONet *n, int index) · line 1533
Quoted 10 lines
hw/net/virtio-net.c +3
-0timer_free (q->tx_timer); + q->tx_timer =NULL ; }else {qemu_bh_delete (q->tx_bh); + q->tx_bh =NULL ; } + q->tx_waiting =0 ;virtio_del_queue (vdev, index *2 +1 ); }
Thanks for the patch.
It looks to me that clearing tx_waiting is sufficient or is there any other reason that you need set tx_timer/tx_bh to NULL?
Thanks
Quoted 42 lines
-----Original Message-----
From: Jason Wang [mailto:[email protected]]
Sent: Wednesday, April 26, 2017 5:18 PM
To: wangyunjian <[email protected]>; [email protected]; [email protected]
Cc: caihe <[email protected]>
Subject: Re: [Qemu-devel] [PATCH] virtio-net: fix wild pointer when remove virtio-net queuesQuoted 19 lines · Yunjian Wang
The
tx_bhortx_timerwill free invirtio_net_del_queue()function, when removing virtio-net queues if the guest doesn't support multiqueue. But it might be still referenced byvirtio_net_set_status(), which needs to be set NULL. And also thetx_waitingneeds to be set zero to preventvirtio_net_set_status()accessingtx_bhortx_timer.Signed-off-by Yunjian Wang <[email protected]>--- hw/net/virtio-net.c | 3 +++ 1 file changed, 3 insertions(+)hw/net/virtio-net.c index renamed from hw/net/virtio-net.c +0
-07d091c9..98bd683 100644
hw/net/virtio-net.c +0
-0@@ -1522,9 +1522,12 @@ static void virtio_net_del_queue(VirtIONet *n, int index)if (q->tx_timer) {timer_del (q->tx_timer);hw/net/virtio-net.c static void virtio_net_del_queue(VirtIONet *n, int index) · line 1533
Quoted 10 lines
hw/net/virtio-net.c +3
-0timer_free (q->tx_timer); + q->tx_timer =NULL ; }else {qemu_bh_delete (q->tx_bh); + q->tx_bh =NULL ; } + q->tx_waiting =0 ;virtio_del_queue (vdev, index *2 +1 ); }Thanks for the patch.
Quoted 2 lines
It looks to me that clearing
tx_waitingis sufficient or is there any other reason that youneed set tx_timer/tx_bh to NULL?
It's just coding habit to avoid access wild pointer, such as used-after-free porblem, it hard to locate the code that cause the bug.
Thanks
Quoted 2 lines
Thanks
Quoted 41 lines · wangyunjian
Quoted 41 lines
-----Original Message-----
From: Jason Wang [mailto:[email protected]]
Sent: Wednesday, April 26, 2017 5:18 PM
To: wangyunjian <[email protected]>; [email protected]; [email protected]
Cc: caihe <[email protected]>
Subject: Re: [Qemu-devel] [PATCH] virtio-net: fix wild pointer when remove virtio-net queuesQuoted 19 lines · Yunjian Wang
The
tx_bhortx_timerwill free invirtio_net_del_queue()function, when removing virtio-net queues if the guest doesn't support multiqueue. But it might be still referenced byvirtio_net_set_status(), which needs to be set NULL. And also thetx_waitingneeds to be set zero to preventvirtio_net_set_status()accessingtx_bhortx_timer.Signed-off-by Yunjian Wang <[email protected]>--- hw/net/virtio-net.c | 3 +++ 1 file changed, 3 insertions(+)hw/net/virtio-net.c index renamed from hw/net/virtio-net.c +0
-07d091c9..98bd683 100644
hw/net/virtio-net.c +0
-0@@ -1522,9 +1522,12 @@ static void virtio_net_del_queue(VirtIONet *n, int index)if (q->tx_timer) {timer_del (q->tx_timer);hw/net/virtio-net.c static void virtio_net_del_queue(VirtIONet *n, int index) · line 1533
Quoted 10 lines
hw/net/virtio-net.c +3
-0timer_free (q->tx_timer); + q->tx_timer =NULL ; }else {qemu_bh_delete (q->tx_bh); + q->tx_bh =NULL ; } + q->tx_waiting =0 ;virtio_del_queue (vdev, index *2 +1 ); }Thanks for the patch.
Quoted 6 lines
Quoted 2 lines
It looks to me that clearing
tx_waitingis sufficient or is there any other reason that youneed set tx_timer/tx_bh to NULL?It's just coding habit to avoid access wild pointer, such as used-after-free porblem, it hard to locate the code that cause the bug.
Thanks
Applied and queued for -stable.
Thanks
Quoted 1 line
Quoted 1 line
Thanks