XSA-39 CVE-2013-021[67]: Linux netback DoS via malicious guest ring.
Subsystems (3)
v2 cover XSA-39 CVE-2013-021[67]: Linux netback DoS via malicious guest ring.
The Xen netback implementation contains a couple of flaws which can allow a guest to cause a DoS in the backend domain, potentially affecting other domains in the system.
CVE-2013-0216 is a failure to sanity check the ring producer/consumer pointers which can allow a guest to cause netback to loop for an extended period preventing other work from occurring.
CVE-2013-0217 is a memory leak on an error path which is guest triggerable.
The following series contains the fixes for these issues, as previously included in Xen Security Advisory 39:
http://lists.xen.org/archives/html/xen-announce/2013-02/msg00001.html
Changes in v2:
- Typo and block comment format fixes
- Added stable Cc
PATCH v2 1/4 xen/netback: shutdown the ring if it contains garbage.
A buggy or malicious frontend should not be able to confuse netback. If we spot anything which is not as it should be then shutdown the device and don't try to continue with the ring in a potentially hostile state. Well behaved and non-hostile frontends will not be penalised.
As well as making the existing checks for such errors fatal also add a new check that ensures that there isn't an insane number of requests on the ring (i.e. more than would fit in the ring). If the ring contains garbage then previously is was possible to loop over this insane number, getting an error each time and therefore not generating any more pending requests and therefore not exiting the loop in xen_netbk_tx_build_gops for an externded period.
Also turn various netdev_dbg calls which no precipitate a fatal error into netdev_err, they are rate limited because the device is shutdown afterwards.
This fixes at least one known DoS/softlockup of the backend domain.
---
v2: Fixup block comment style (DaveM)
--- drivers/net/xen-netback/common.h | 3 ++ drivers/net/xen-netback/interface.c | 23 ++++++++----- drivers/net/xen-netback/netback.c | 62 +++++++++++++++++++++++++--------- 3 files changed, 62 insertions(+), 26 deletions(-)
drivers/net/xen-netback/common.h +3 -0
@@ -151,6 +151,9 @@ void xen_netbk_queue_tx_skb(struct xenvif *vif, struct sk_buff *skb);/* Notify xenvif that ring now has space to send an skb to the frontend */ void xenvif_notify_tx_completion (struct xenvif *vif); +/* Prevent the device from generating any further traffic. */ +void xenvif_carrier_off (struct xenvif *vif); +/* Returns number of ring slots required to send an skb to the frontend */ unsigned int xen_netbk_count_skb_slots (struct xenvif *vif,struct sk_buff *skb);
drivers/net/xen-netback/interface.c +14 -9
@@ -343,17 +343,22 @@ err:return err; } -void xenvif_disconnect (struct xenvif *vif) +void xenvif_carrier_off (struct xenvif *vif) {struct net_device *dev = vif->dev; -if (netif_carrier_ok (dev)) { -rtnl_lock (); -netif_carrier_off (dev);/* discard queued packets */ -if (netif_running (dev)) -xenvif_down (vif); -rtnl_unlock (); -xenvif_put (vif); - } + +rtnl_lock (); +netif_carrier_off (dev);/* discard queued packets */ +if (netif_running (dev)) +xenvif_down (vif); +rtnl_unlock (); +xenvif_put (vif); +} + +void xenvif_disconnect (struct xenvif *vif) +{ +if (netif_carrier_ok (vif->dev)) +xenvif_carrier_off (vif);atomic_dec (&vif->refcnt);wait_event (vif->waiting_to_free,atomic_read (&vif->refcnt) ==0 );
drivers/net/xen-netback/netback.c +45 -17
151 lines not on this page · raw message
Signature · 1 line
1.7.2.5
PATCH v2 1/4 xen/netback: shutdown the ring if it contains garbage.
In reply to Ian CampbellA buggy or malicious frontend should not be able to confuse netback. If we spot anything which is not as it should be then shutdown the device and don't try to continue with the ring in a potentially hostile state. Well behaved and non-hostile frontends will not be penalised.
As well as making the existing checks for such errors fatal also add a new check that ensures that there isn't an insane number of requests on the ring (i.e. more than would fit in the ring). If the ring contains garbage then previously is was possible to loop over this insane number, getting an error each time and therefore not generating any more pending requests and therefore not exiting the loop in xen_netbk_tx_build_gops for an externded period.
Also turn various netdev_dbg calls which no precipitate a fatal error into netdev_err, they are rate limited because the device is shutdown afterwards.
This fixes at least one known DoS/softlockup of the backend domain.
---
v2: Fixup block comment style (DaveM)
--- drivers/net/xen-netback/common.h | 3 ++ drivers/net/xen-netback/interface.c | 23 ++++++++----- drivers/net/xen-netback/netback.c | 62 +++++++++++++++++++++++++--------- 3 files changed, 62 insertions(+), 26 deletions(-)
drivers/net/xen-netback/common.h +3 -0
@@ -151,6 +151,9 @@ void xen_netbk_queue_tx_skb(struct xenvif *vif, struct sk_buff *skb);/* Notify xenvif that ring now has space to send an skb to the frontend */ void xenvif_notify_tx_completion (struct xenvif *vif); +/* Prevent the device from generating any further traffic. */ +void xenvif_carrier_off (struct xenvif *vif); +/* Returns number of ring slots required to send an skb to the frontend */ unsigned int xen_netbk_count_skb_slots (struct xenvif *vif,struct sk_buff *skb);
drivers/net/xen-netback/interface.c +14 -9
@@ -343,17 +343,22 @@ err:return err; } -void xenvif_disconnect (struct xenvif *vif) +void xenvif_carrier_off (struct xenvif *vif) {struct net_device *dev = vif->dev; -if (netif_carrier_ok (dev)) { -rtnl_lock (); -netif_carrier_off (dev);/* discard queued packets */ -if (netif_running (dev)) -xenvif_down (vif); -rtnl_unlock (); -xenvif_put (vif); - } + +rtnl_lock (); +netif_carrier_off (dev);/* discard queued packets */ +if (netif_running (dev)) +xenvif_down (vif); +rtnl_unlock (); +xenvif_put (vif); +} + +void xenvif_disconnect (struct xenvif *vif) +{ +if (netif_carrier_ok (vif->dev)) +xenvif_carrier_off (vif);atomic_dec (&vif->refcnt);wait_event (vif->waiting_to_free,atomic_read (&vif->refcnt) ==0 );
drivers/net/xen-netback/netback.c +45 -17
151 lines not on this page · raw message
Signature · 1 line
1.7.2.5
PATCH v2 2/4 xen/netback: don't leak pages on failure in xen_netbk_tx_check_gop.
In reply to Ian CampbellFrom: Matthew Daley <[email protected]>
--- drivers/net/xen-netback/netback.c | 38 ++++++++++++------------------------ 1 files changed, 13 insertions(+), 25 deletions(-)
drivers/net/xen-netback/netback.c +13 -25
@@ -147,7 +147,8 @@ void xen_netbk_remove_xenvif(struct xenvif *vif)atomic_dec (&netbk->netfront_count); } -static void xen_netbk_idx_release (struct xen_netbk *netbk,u16 pending_idx); +static void xen_netbk_idx_release (struct xen_netbk *netbk,u16 pending_idx, +u8 status);static void make_tx_response (struct xenvif *vif,struct xen_netif_tx_request *txp,s8 st);
@@ -1007,30 +1008,20 @@ static int xen_netbk_tx_check_gop(struct xen_netbk *netbk, {struct gnttab_copy *gop = *gopp;u16 pending_idx = *((u16 *)skb->data); -struct pending_tx_info *pending_tx_info = netbk->pending_tx_info; -struct xenvif *vif = pending_tx_info[pending_idx].vif; -struct xen_netif_tx_request *txp;struct skb_shared_info *shinfo =skb_shinfo (skb);int nr_frags = shinfo->nr_frags;int i, err, start;/* Check status of header. */ err = gop->status; -if (unlikely (err)) { -pending_ring_idx_t index; - index =pending_index (netbk->pending_prod++); - txp = &pending_tx_info[pending_idx].req; -make_tx_response (vif, txp,XEN_NETIF_RSP_ERROR ); - netbk->pending_ring[index] = pending_idx; -xenvif_put (vif); - } +if (unlikely (err)) +xen_netbk_idx_release (netbk, pending_idx,XEN_NETIF_RSP_ERROR );/* Skip first skb fragment if it is on same page as header fragment. */ start = (frag_get_pending_idx (&shinfo->frags[0 ]) == pending_idx);for (i = start; i < nr_frags; i++) {int j, newerr; -pending_ring_idx_t index; pending_idx =frag_get_pending_idx (&shinfo->frags[i]);
@@ -1039,16 +1030,12 @@ static int xen_netbk_tx_check_gop(struct xen_netbk *netbk,if (likely (!newerr)) {/* Had a previous error? Invalidate this fragment. */ if (unlikely (err)) -xen_netbk_idx_release (netbk, pending_idx); +xen_netbk_idx_release (netbk, pending_idx,XEN_NETIF_RSP_OKAY );continue ; }/* Error on this fragment: respond to client with an error. */ - txp = &netbk->pending_tx_info[pending_idx].req; -make_tx_response (vif, txp,XEN_NETIF_RSP_ERROR ); - index =pending_index (netbk->pending_prod++); - netbk->pending_ring[index] = pending_idx; -xenvif_put (vif); +xen_netbk_idx_release (netbk, pending_idx,XEN_NETIF_RSP_ERROR );/* Not the first error? Preceding frags already invalidated. */ if (err)
@@ -1056,10 +1043,10 @@ static int xen_netbk_tx_check_gop(struct xen_netbk *netbk,/* First error: invalidate header and preceding fragments. */ pending_idx = *((u16 *)skb->data); -xen_netbk_idx_release (netbk, pending_idx); +xen_netbk_idx_release (netbk, pending_idx,XEN_NETIF_RSP_OKAY );for (j = start; j < i; j++) { pending_idx =frag_get_pending_idx (&shinfo->frags[j]); -xen_netbk_idx_release (netbk, pending_idx); +xen_netbk_idx_release (netbk, pending_idx,XEN_NETIF_RSP_OKAY ); }/* Remember the error: invalidate all subsequent fragments. */
@@ -1093,7 +1080,7 @@ static void xen_netbk_fill_frags(struct xen_netbk *netbk, struct sk_buff *skb)/* Take an extra reference to offset xen_netbk_idx_release */ get_page (netbk->mmap_pages[pending_idx]); -xen_netbk_idx_release (netbk, pending_idx); +xen_netbk_idx_release (netbk, pending_idx,XEN_NETIF_RSP_OKAY ); } }
@@ -1476,7 +1463,7 @@ static void xen_netbk_tx_submit(struct xen_netbk *netbk) txp->size -= data_len; }else {/* Schedule a response immediately. */ -xen_netbk_idx_release (netbk, pending_idx); +xen_netbk_idx_release (netbk, pending_idx,XEN_NETIF_RSP_OKAY ); }if (txp->flags & XEN_NETTXF_csum_blank)
@@ -1528,7 +1515,8 @@ static void xen_netbk_tx_action(struct xen_netbk *netbk)xen_netbk_tx_submit (netbk); } -static void xen_netbk_idx_release (struct xen_netbk *netbk,u16 pending_idx) +static void xen_netbk_idx_release (struct xen_netbk *netbk,u16 pending_idx, +u8 status) {struct xenvif *vif;struct pending_tx_info *pending_tx_info;
@@ -1542,7 +1530,7 @@ static void xen_netbk_idx_release(struct xen_netbk *netbk, u16 pending_idx) vif = pending_tx_info->vif; -make_tx_response (vif, &pending_tx_info->req,XEN_NETIF_RSP_OKAY ); +make_tx_response (vif, &pending_tx_info->req, status); index =pending_index (netbk->pending_prod++); netbk->pending_ring[index] = pending_idx;
Signature · 1 line
1.7.2.5
PATCH v2 2/4 xen/netback: don't leak pages on failure in xen_netbk_tx_check_gop.
In reply to Ian CampbellFrom: Matthew Daley <[email protected]>
--- drivers/net/xen-netback/netback.c | 38 ++++++++++++------------------------ 1 files changed, 13 insertions(+), 25 deletions(-)
drivers/net/xen-netback/netback.c +13 -25
@@ -147,7 +147,8 @@ void xen_netbk_remove_xenvif(struct xenvif *vif)atomic_dec (&netbk->netfront_count); } -static void xen_netbk_idx_release (struct xen_netbk *netbk,u16 pending_idx); +static void xen_netbk_idx_release (struct xen_netbk *netbk,u16 pending_idx, +u8 status);static void make_tx_response (struct xenvif *vif,struct xen_netif_tx_request *txp,s8 st);
@@ -1007,30 +1008,20 @@ static int xen_netbk_tx_check_gop(struct xen_netbk *netbk, {struct gnttab_copy *gop = *gopp;u16 pending_idx = *((u16 *)skb->data); -struct pending_tx_info *pending_tx_info = netbk->pending_tx_info; -struct xenvif *vif = pending_tx_info[pending_idx].vif; -struct xen_netif_tx_request *txp;struct skb_shared_info *shinfo =skb_shinfo (skb);int nr_frags = shinfo->nr_frags;int i, err, start;/* Check status of header. */ err = gop->status; -if (unlikely (err)) { -pending_ring_idx_t index; - index =pending_index (netbk->pending_prod++); - txp = &pending_tx_info[pending_idx].req; -make_tx_response (vif, txp,XEN_NETIF_RSP_ERROR ); - netbk->pending_ring[index] = pending_idx; -xenvif_put (vif); - } +if (unlikely (err)) +xen_netbk_idx_release (netbk, pending_idx,XEN_NETIF_RSP_ERROR );/* Skip first skb fragment if it is on same page as header fragment. */ start = (frag_get_pending_idx (&shinfo->frags[0 ]) == pending_idx);for (i = start; i < nr_frags; i++) {int j, newerr; -pending_ring_idx_t index; pending_idx =frag_get_pending_idx (&shinfo->frags[i]);
@@ -1039,16 +1030,12 @@ static int xen_netbk_tx_check_gop(struct xen_netbk *netbk,if (likely (!newerr)) {/* Had a previous error? Invalidate this fragment. */ if (unlikely (err)) -xen_netbk_idx_release (netbk, pending_idx); +xen_netbk_idx_release (netbk, pending_idx,XEN_NETIF_RSP_OKAY );continue ; }/* Error on this fragment: respond to client with an error. */ - txp = &netbk->pending_tx_info[pending_idx].req; -make_tx_response (vif, txp,XEN_NETIF_RSP_ERROR ); - index =pending_index (netbk->pending_prod++); - netbk->pending_ring[index] = pending_idx; -xenvif_put (vif); +xen_netbk_idx_release (netbk, pending_idx,XEN_NETIF_RSP_ERROR );/* Not the first error? Preceding frags already invalidated. */ if (err)
@@ -1056,10 +1043,10 @@ static int xen_netbk_tx_check_gop(struct xen_netbk *netbk,/* First error: invalidate header and preceding fragments. */ pending_idx = *((u16 *)skb->data); -xen_netbk_idx_release (netbk, pending_idx); +xen_netbk_idx_release (netbk, pending_idx,XEN_NETIF_RSP_OKAY );for (j = start; j < i; j++) { pending_idx =frag_get_pending_idx (&shinfo->frags[j]); -xen_netbk_idx_release (netbk, pending_idx); +xen_netbk_idx_release (netbk, pending_idx,XEN_NETIF_RSP_OKAY ); }/* Remember the error: invalidate all subsequent fragments. */
@@ -1093,7 +1080,7 @@ static void xen_netbk_fill_frags(struct xen_netbk *netbk, struct sk_buff *skb)/* Take an extra reference to offset xen_netbk_idx_release */ get_page (netbk->mmap_pages[pending_idx]); -xen_netbk_idx_release (netbk, pending_idx); +xen_netbk_idx_release (netbk, pending_idx,XEN_NETIF_RSP_OKAY ); } }
@@ -1476,7 +1463,7 @@ static void xen_netbk_tx_submit(struct xen_netbk *netbk) txp->size -= data_len; }else {/* Schedule a response immediately. */ -xen_netbk_idx_release (netbk, pending_idx); +xen_netbk_idx_release (netbk, pending_idx,XEN_NETIF_RSP_OKAY ); }if (txp->flags & XEN_NETTXF_csum_blank)
@@ -1528,7 +1515,8 @@ static void xen_netbk_tx_action(struct xen_netbk *netbk)xen_netbk_tx_submit (netbk); } -static void xen_netbk_idx_release (struct xen_netbk *netbk,u16 pending_idx) +static void xen_netbk_idx_release (struct xen_netbk *netbk,u16 pending_idx, +u8 status) {struct xenvif *vif;struct pending_tx_info *pending_tx_info;
@@ -1542,7 +1530,7 @@ static void xen_netbk_idx_release(struct xen_netbk *netbk, u16 pending_idx) vif = pending_tx_info->vif; -make_tx_response (vif, &pending_tx_info->req,XEN_NETIF_RSP_OKAY ); +make_tx_response (vif, &pending_tx_info->req, status); index =pending_index (netbk->pending_prod++); netbk->pending_ring[index] = pending_idx;
Signature · 1 line
1.7.2.5
PATCH v2 3/4 xen/netback: free already allocated memory on failure in xen_netbk_get_requests
In reply to Ian Campbell---
v2: s/reponses/responses/ (blp) & fixup block comment style (DaveM)
--- drivers/net/xen-netback/netback.c | 13 ++++++++++++- 1 files changed, 12 insertions(+), 1 deletions(-)
drivers/net/xen-netback/netback.c +12 -1
@@ -978,7 +978,7 @@ static struct gnttab_copy *xen_netbk_get_requests(struct xen_netbk *netbk, pending_idx = netbk->pending_ring[index]; page =xen_netbk_alloc_page (netbk, skb, pending_idx);if (!page) -return NULL ; + goto err; gop->source.u.ref = txp->gref; gop->source.domid = vif->domid;
@@ -1000,6 +1000,17 @@ static struct gnttab_copy *xen_netbk_get_requests(struct xen_netbk *netbk, }return gop; +err: +/* Unwind, freeing all pages and sending error responses. */ +while (i-- > start) { +xen_netbk_idx_release (netbk,frag_get_pending_idx (&frags[i]), +XEN_NETIF_RSP_ERROR ); + } +/* The head too, if necessary. */ +if (start) +xen_netbk_idx_release (netbk, pending_idx,XEN_NETIF_RSP_ERROR ); + +return NULL ; } static int xen_netbk_tx_check_gop(struct xen_netbk *netbk,
Signature · 1 line
1.7.2.5
PATCH v2 3/4 xen/netback: free already allocated memory on failure in xen_netbk_get_requests
In reply to Ian Campbell---
v2: s/reponses/responses/ (blp) & fixup block comment style (DaveM)
--- drivers/net/xen-netback/netback.c | 13 ++++++++++++- 1 files changed, 12 insertions(+), 1 deletions(-)
drivers/net/xen-netback/netback.c +12 -1
@@ -978,7 +978,7 @@ static struct gnttab_copy *xen_netbk_get_requests(struct xen_netbk *netbk, pending_idx = netbk->pending_ring[index]; page =xen_netbk_alloc_page (netbk, skb, pending_idx);if (!page) -return NULL ; + goto err; gop->source.u.ref = txp->gref; gop->source.domid = vif->domid;
@@ -1000,6 +1000,17 @@ static struct gnttab_copy *xen_netbk_get_requests(struct xen_netbk *netbk, }return gop; +err: +/* Unwind, freeing all pages and sending error responses. */ +while (i-- > start) { +xen_netbk_idx_release (netbk,frag_get_pending_idx (&frags[i]), +XEN_NETIF_RSP_ERROR ); + } +/* The head too, if necessary. */ +if (start) +xen_netbk_idx_release (netbk, pending_idx,XEN_NETIF_RSP_ERROR ); + +return NULL ; } static int xen_netbk_tx_check_gop(struct xen_netbk *netbk,
Signature · 1 line
1.7.2.5
PATCH v2 4/4 netback: correct netbk_tx_err to handle wrap around.
In reply to Ian Campbell--- drivers/net/xen-netback/netback.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/net/xen-netback/netback.c +1 -1
@@ -880,7 +880,7 @@ static void netbk_tx_err(struct xenvif *vif,do {make_tx_response (vif, txp,XEN_NETIF_RSP_ERROR ); -if (cons >= end) +if (cons == end)break ; txp =RING_GET_REQUEST (&vif->tx, cons++); }while (1 );
Signature · 1 line
1.7.2.5
PATCH v2 4/4 netback: correct netbk_tx_err to handle wrap around.
In reply to Ian Campbell--- drivers/net/xen-netback/netback.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/net/xen-netback/netback.c +1 -1
@@ -880,7 +880,7 @@ static void netbk_tx_err(struct xenvif *vif,do {make_tx_response (vif, txp,XEN_NETIF_RSP_ERROR ); -if (cons >= end) +if (cons == end)break ; txp =RING_GET_REQUEST (&vif->tx, cons++); }while (1 );
Signature · 1 line
1.7.2.5
From: Ian Campbell <[email protected]>
Date: Thu, 7 Feb 2013 09:41:18 +0000
Quoted 11 lines
The Xen netback implementation contains a couple of flaws which can allow a guest to cause a DoS in the backend domain, potentially affecting other domains in the system.
CVE-2013-0216 is a failure to sanity check the ring producer/consumer pointers which can allow a guest to cause netback to loop for an extended period preventing other work from occurring.
CVE-2013-0217 is a memory leak on an error path which is guest triggerable.
Quoted 7 lines
The following series contains the fixes for these issues, as previously included in Xen Security Advisory 39:
http://lists.xen.org/archives/html/xen-announce/2013-02/msg00001.htmlChanges in v2:
- Typo and block comment format fixes
- Added stable Cc
Applied, please don't add stable CC:'s to networking patches, instead ask me to queue it up to my -stable todo pile instead.
I don't like it when patches instantly be submitted to -stable when they hit Linus's tree, I'd rather it soak upstream for a week or two instead. That's why I do it this way.
Thanks.
From: Ian Campbell <[email protected]>
Date: Thu, 7 Feb 2013 09:41:18 +0000
Quoted 11 lines
The Xen netback implementation contains a couple of flaws which can allow a guest to cause a DoS in the backend domain, potentially affecting other domains in the system.
CVE-2013-0216 is a failure to sanity check the ring producer/consumer pointers which can allow a guest to cause netback to loop for an extended period preventing other work from occurring.
CVE-2013-0217 is a memory leak on an error path which is guest triggerable.
Quoted 7 lines
The following series contains the fixes for these issues, as previously included in Xen Security Advisory 39:
http://lists.xen.org/archives/html/xen-announce/2013-02/msg00001.htmlChanges in v2:
- Typo and block comment format fixes
- Added stable Cc
Applied, please don't add stable CC:'s to networking patches, instead ask me to queue it up to my -stable todo pile instead.
I don't like it when patches instantly be submitted to -stable when they hit Linus's tree, I'd rather it soak upstream for a week or two instead. That's why I do it this way.
Thanks.
Quoted 2 lines · David Miller
Applied, please don't add stable CC:'s to networking patches, instead ask me to queue it up to my -stable todo pile instead.
Thanks & Ack.
Quoted 3 lines
I don't like it when patches instantly be submitted to -stable when they hit Linus's tree, I'd rather it soak upstream for a week or two instead. That's why I do it this way.
Very reasonable.
Ian.
Quoted 2 lines · David Miller
Applied, please don't add stable CC:'s to networking patches, instead ask me to queue it up to my -stable todo pile instead.
Thanks & Ack.
Quoted 3 lines
I don't like it when patches instantly be submitted to -stable when they hit Linus's tree, I'd rather it soak upstream for a week or two instead. That's why I do it this way.
Very reasonable.
Ian.