Skip to content

Commit 699dfec

Browse files
Wei LiuJiri Slaby
Wei Liu
authored and
Jiri Slaby
committed
xen-netback: disable rogue vif in kthread context
[ Upstream commit e9d8b2c ] When netback discovers frontend is sending malformed packet it will disables the interface which serves that frontend. However disabling a network interface involving taking a mutex which cannot be done in softirq context, so we need to defer this process to kthread context. This patch does the following: 1. introduce a flag to indicate the interface is disabled. 2. check that flag in TX path, don't do any work if it's true. 3. check that flag in RX path, turn off that interface if it's true. The reason to disable it in RX path is because RX uses kthread. After this change the behavior of netback is still consistent -- it won't do any TX work for a rogue frontend, and the interface will be eventually turned off. Also change a "continue" to "break" after xenvif_fatal_tx_err, as it doesn't make sense to continue processing packets if frontend is rogue. This is a fix for XSA-90. Reported-by: Török Edwin <[email protected]> Signed-off-by: Wei Liu <[email protected]> Cc: Ian Campbell <[email protected]> Reviewed-by: David Vrabel <[email protected]> Acked-by: Ian Campbell <[email protected]> Signed-off-by: David S. Miller <[email protected]> Signed-off-by: Jiri Slaby <[email protected]>
1 parent 066bde3 commit 699dfec

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

drivers/net/xen-netback/common.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ struct xenvif {
102102
domid_t domid;
103103
unsigned int handle;
104104

105+
/* Is this interface disabled? True when backend discovers
106+
* frontend is rogue.
107+
*/
108+
bool disabled;
109+
105110
/* Use NAPI for guest TX */
106111
struct napi_struct napi;
107112
/* When feature-split-event-channels = 0, tx_irq = rx_irq. */

drivers/net/xen-netback/interface.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ static int xenvif_poll(struct napi_struct *napi, int budget)
6666
struct xenvif *vif = container_of(napi, struct xenvif, napi);
6767
int work_done;
6868

69+
/* This vif is rogue, we pretend we've there is nothing to do
70+
* for this vif to deschedule it from NAPI. But this interface
71+
* will be turned off in thread context later.
72+
*/
73+
if (unlikely(vif->disabled)) {
74+
napi_complete(napi);
75+
return 0;
76+
}
77+
6978
work_done = xenvif_tx_action(vif, budget);
7079

7180
if (work_done < budget) {
@@ -309,6 +318,8 @@ struct xenvif *xenvif_alloc(struct device *parent, domid_t domid,
309318
vif->csum = 1;
310319
vif->dev = dev;
311320

321+
vif->disabled = false;
322+
312323
vif->credit_bytes = vif->remaining_credit = ~0UL;
313324
vif->credit_usec = 0UL;
314325
init_timer(&vif->credit_timeout);

drivers/net/xen-netback/netback.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,8 @@ static void xenvif_tx_err(struct xenvif *vif,
731731
static void xenvif_fatal_tx_err(struct xenvif *vif)
732732
{
733733
netdev_err(vif->dev, "fatal error; disabling device\n");
734-
xenvif_carrier_off(vif);
734+
vif->disabled = true;
735+
xenvif_kick_thread(vif);
735736
}
736737

737738
static int xenvif_count_requests(struct xenvif *vif,
@@ -1242,7 +1243,7 @@ static unsigned xenvif_tx_build_gops(struct xenvif *vif)
12421243
vif->tx.sring->req_prod, vif->tx.req_cons,
12431244
XEN_NETIF_TX_RING_SIZE);
12441245
xenvif_fatal_tx_err(vif);
1245-
continue;
1246+
break;
12461247
}
12471248

12481249
RING_FINAL_CHECK_FOR_REQUESTS(&vif->tx, work_to_do);
@@ -1642,7 +1643,18 @@ int xenvif_kthread(void *data)
16421643
while (!kthread_should_stop()) {
16431644
wait_event_interruptible(vif->wq,
16441645
rx_work_todo(vif) ||
1646+
vif->disabled ||
16451647
kthread_should_stop());
1648+
1649+
/* This frontend is found to be rogue, disable it in
1650+
* kthread context. Currently this is only set when
1651+
* netback finds out frontend sends malformed packet,
1652+
* but we cannot disable the interface in softirq
1653+
* context so we defer it here.
1654+
*/
1655+
if (unlikely(vif->disabled && netif_carrier_ok(vif->dev)))
1656+
xenvif_carrier_off(vif);
1657+
16461658
if (kthread_should_stop())
16471659
break;
16481660

0 commit comments

Comments
 (0)