Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[linux] Impose receive quota on tap driver
The tap driver can retrieve a potentially unlimited number of packets
in a single poll.  This can lead to heap exhaustion under heavy load.

Fix by imposing an artificial receive quota (as already used in other
drivers without natural receive limits).

Signed-off-by: Michael Brown <mcb30@ipxe.org>
  • Loading branch information
mcb30 committed Sep 4, 2017
1 parent 42eedb0 commit 306465b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/drivers/linux/tap.c
Expand Up @@ -40,6 +40,7 @@
#include <linux/if_tun.h>

#define RX_BUF_SIZE 1536
#define RX_QUOTA 4

/** @file
*
Expand Down Expand Up @@ -127,6 +128,7 @@ static void tap_poll(struct net_device *netdev)
struct tap_nic * nic = netdev->priv;
struct pollfd pfd;
struct io_buffer * iobuf;
unsigned int quota = RX_QUOTA;
int r;

pfd.fd = nic->fd;
Expand All @@ -144,7 +146,8 @@ static void tap_poll(struct net_device *netdev)
if (! iobuf)
goto allocfail;

while ((r = linux_read(nic->fd, iobuf->data, RX_BUF_SIZE)) > 0) {
while (quota-- &&
((r = linux_read(nic->fd, iobuf->data, RX_BUF_SIZE)) > 0)) {
DBGC2(nic, "tap %p read %d bytes\n", nic, r);

iob_put(iobuf, r);
Expand Down

0 comments on commit 306465b

Please sign in to comment.