CVE-2013-0216 (C, published 2013-02-18T04:41Z)
Description: value: The Xen netback functionality in the Linux kernel before 3.7.8 allows guest OS users to cause a denial of service (loop) by triggering ring pointer corruption.
Severity: MEDIUM (CVSS v3 base score: )
Weakness: CWE-20 \u2014 Improper Input Validation
The product receives input or data, but it does
        not validate or incorrectly validates that the input has the
        properties that are required to process the data safely and
        correctly.
Repository: https://github.com/torvalds/linux
Files changed:
drivers/net/xen-netback/common.h
drivers/net/xen-netback/interface.c
drivers/net/xen-netback/netback.c
Commit message: 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.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Acked-by: Jan Beulich <JBeulich@suse.com>
Signed-off-by: David S. Miller <davem@davemloft.net>


Vulnerable code:
void xenvif_disconnect(struct xenvif *vif)
	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);
	}
			netdev_dbg(vif->dev, "Need more frags\n");
			netdev_dbg(vif->dev, "Too many frags\n");
			netdev_dbg(vif->dev, "Frags galore\n");
			netdev_dbg(vif->dev, "txp->offset: %x, size: %u\n",
			netdev_dbg(vif->dev, "Missing extra info\n");
			netdev_dbg(vif->dev,
		netdev_dbg(vif->dev, "GSO size must not be zero.\n");
		netdev_dbg(vif->dev, "Bad GSO type %d.\n", gso->u.gso.type);
			if (unlikely(work_to_do < 0)) {
				netbk_tx_err(vif, &txreq, idx);
			}
		if (unlikely(ret < 0)) {
			netbk_tx_err(vif, &txreq, idx - ret);
		}
			netdev_dbg(vif->dev,
			netbk_tx_err(vif, &txreq, idx);
				netbk_tx_err(vif, &txreq, idx);

Fixed code:
/* Prevent the device from generating any further traffic. */
void xenvif_carrier_off(struct xenvif *vif);

void xenvif_carrier_off(struct xenvif *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);
static void netbk_fatal_tx_err(struct xenvif *vif)
{
	netdev_err(vif->dev, "fatal error; disabling device\n");
	xenvif_carrier_off(vif);
	xenvif_put(vif);
}

			netdev_err(vif->dev, "Need more frags\n");
			netbk_fatal_tx_err(vif);
			netdev_err(vif->dev, "Too many frags\n");
			netbk_fatal_tx_err(vif);
			netdev_err(vif->dev, "Frag is bigger than frame.\n");
			netbk_fatal_tx_err(vif);
			netdev_err(vif->dev, "txp->offset: %x, size: %u\n",
			netbk_fatal_tx_err(vif);
			netdev_err(vif->dev, "Missing extra info\n");
			netbk_fatal_tx_err(vif);
			netdev_err(vif->dev,
			netbk_fatal_tx_err(vif);
		netdev_err(vif->dev, "GSO size must not be zero.\n");
		netbk_fatal_tx_err(vif);
		netdev_err(vif->dev, "Bad GSO type %d.\n", gso->u.gso.type);
		netbk_fatal_tx_err(vif);
		/* This can sometimes happen because the test of
		 * list_empty(net_schedule_list) at the top of the
		 * loop is unlocked.  Just go back and have another
		 * look.
		 */
		if (vif->tx.sring->req_prod - vif->tx.req_cons >
		    XEN_NETIF_TX_RING_SIZE) {
			netdev_err(vif->dev,
				   "Impossible number of requests. "
				   "req_prod %d, req_cons %d, size %ld\n",
				   vif->tx.sring->req_prod, vif->tx.req_cons,
				   XEN_NETIF_TX_RING_SIZE);
			netbk_fatal_tx_err(vif);
			continue;
		}

			if (unlikely(work_to_do < 0))
		if (unlikely(ret < 0))

			netdev_err(vif->dev,
			netbk_fatal_tx_err(vif);
				/* Failure in netbk_set_skb_gso is fatal. */