qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH V2] net: tap: fix NULL dereference when passing invalid parameters to tap
@ 2013-06-04  5:18 Jason Wang
  2013-06-05 11:20 ` Stefan Hajnoczi
  0 siblings, 1 reply; 2+ messages in thread
From: Jason Wang @ 2013-06-04  5:18 UTC (permalink / raw)
  To: aliguori, stefanha, qemu-devel
  Cc: Paolo Bonzini, Jason Wang, Stefan Hajnoczi, qemu-stable,
	Laszlo Ersek

This patch forbid the following invalid parameters to tap:

1) fd and vhostfds were specified but vhostfd were not specified
2) vhostfds were specified but fds were not specified
3) fds and vhostfd were specified

For 1 and 2, net_init_tap_one() will still pass NULL as vhostfdname to
monitor_handle_fd_param(), which may crash the qemu.

Also remove the unnecessary has_fd check.

Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Stefan Hajnoczi <shajnocz@redhat.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: qemu-stable@nongnu.org
Signed-off-by: Jason Wang <jasowang@redhat.com>

---
Changes from v1:
- check vhostfds for has_helper and all other cases
- remove the unnecessary check for has_fd when fds were specified
---
 net/tap.c |   18 ++++++++++++------
 1 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/net/tap.c b/net/tap.c
index e0b7a2a..39c1cda 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -698,9 +698,10 @@ int net_init_tap(const NetClientOptions *opts, const char *name,
     if (tap->has_fd) {
         if (tap->has_ifname || tap->has_script || tap->has_downscript ||
             tap->has_vnet_hdr || tap->has_helper || tap->has_queues ||
-            tap->has_fds) {
+            tap->has_fds || tap->has_vhostfds) {
             error_report("ifname=, script=, downscript=, vnet_hdr=, "
-                         "helper=, queues=, and fds= are invalid with fd=");
+                         "helper=, queues=, fds=, and vhostfds= "
+                         "are invalid with fd=");
             return -1;
         }
 
@@ -725,9 +726,10 @@ int net_init_tap(const NetClientOptions *opts, const char *name,
 
         if (tap->has_ifname || tap->has_script || tap->has_downscript ||
             tap->has_vnet_hdr || tap->has_helper || tap->has_queues ||
-            tap->has_fd) {
+            tap->has_vhostfd) {
             error_report("ifname=, script=, downscript=, vnet_hdr=, "
-                         "helper=, queues=, and fd= are invalid with fds=");
+                         "helper=, queues=, and vhostfd= "
+                         "are invalid with fds=");
             return -1;
         }
 
@@ -765,9 +767,9 @@ int net_init_tap(const NetClientOptions *opts, const char *name,
         }
     } else if (tap->has_helper) {
         if (tap->has_ifname || tap->has_script || tap->has_downscript ||
-            tap->has_vnet_hdr || tap->has_queues || tap->has_fds) {
+            tap->has_vnet_hdr || tap->has_queues || tap->has_vhostfds) {
             error_report("ifname=, script=, downscript=, and vnet_hdr= "
-                         "queues=, and fds= are invalid with helper=");
+                         "queues=, and vhostfds= are invalid with helper=");
             return -1;
         }
 
@@ -785,6 +787,10 @@ int net_init_tap(const NetClientOptions *opts, const char *name,
             return -1;
         }
     } else {
+        if (tap->has_vhostfds) {
+            error_report("vhostfds= is invalid if fds= wasn't specified");
+            return -1;
+        }
         script = tap->has_script ? tap->script : DEFAULT_NETWORK_SCRIPT;
         downscript = tap->has_downscript ? tap->downscript :
             DEFAULT_NETWORK_DOWN_SCRIPT;
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Qemu-devel] [PATCH V2] net: tap: fix NULL dereference when passing invalid parameters to tap
  2013-06-04  5:18 [Qemu-devel] [PATCH V2] net: tap: fix NULL dereference when passing invalid parameters to tap Jason Wang
@ 2013-06-05 11:20 ` Stefan Hajnoczi
  0 siblings, 0 replies; 2+ messages in thread
From: Stefan Hajnoczi @ 2013-06-05 11:20 UTC (permalink / raw)
  To: Jason Wang
  Cc: aliguori, qemu-devel, qemu-stable, Stefan Hajnoczi, stefanha,
	Paolo Bonzini, Laszlo Ersek

On Tue, Jun 04, 2013 at 01:18:17PM +0800, Jason Wang wrote:
> This patch forbid the following invalid parameters to tap:
> 
> 1) fd and vhostfds were specified but vhostfd were not specified
> 2) vhostfds were specified but fds were not specified
> 3) fds and vhostfd were specified
> 
> For 1 and 2, net_init_tap_one() will still pass NULL as vhostfdname to
> monitor_handle_fd_param(), which may crash the qemu.
> 
> Also remove the unnecessary has_fd check.
> 
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Stefan Hajnoczi <shajnocz@redhat.com>
> Cc: Laszlo Ersek <lersek@redhat.com>
> Cc: qemu-stable@nongnu.org
> Signed-off-by: Jason Wang <jasowang@redhat.com>
> 
> ---
> Changes from v1:
> - check vhostfds for has_helper and all other cases
> - remove the unnecessary check for has_fd when fds were specified
> ---
>  net/tap.c |   18 ++++++++++++------
>  1 files changed, 12 insertions(+), 6 deletions(-)

Thanks, applied to my net tree:
https://github.com/stefanha/qemu/commits/net

Stefan

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-06-05 11:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-04  5:18 [Qemu-devel] [PATCH V2] net: tap: fix NULL dereference when passing invalid parameters to tap Jason Wang
2013-06-05 11:20 ` 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).