Browse Source

[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>
tags/v1.20.1
Michael Brown 6 years ago
parent
commit
306465bef3
1 changed files with 4 additions and 1 deletions
  1. 4
    1
      src/drivers/linux/tap.c

+ 4
- 1
src/drivers/linux/tap.c View File

@@ -40,6 +40,7 @@
40 40
 #include <linux/if_tun.h>
41 41
 
42 42
 #define RX_BUF_SIZE 1536
43
+#define RX_QUOTA 4
43 44
 
44 45
 /** @file
45 46
  *
@@ -127,6 +128,7 @@ static void tap_poll(struct net_device *netdev)
127 128
 	struct tap_nic * nic = netdev->priv;
128 129
 	struct pollfd pfd;
129 130
 	struct io_buffer * iobuf;
131
+	unsigned int quota = RX_QUOTA;
130 132
 	int r;
131 133
 
132 134
 	pfd.fd = nic->fd;
@@ -144,7 +146,8 @@ static void tap_poll(struct net_device *netdev)
144 146
 	if (! iobuf)
145 147
 		goto allocfail;
146 148
 
147
-	while ((r = linux_read(nic->fd, iobuf->data, RX_BUF_SIZE)) > 0) {
149
+	while (quota-- &&
150
+	       ((r = linux_read(nic->fd, iobuf->data, RX_BUF_SIZE)) > 0)) {
148 151
 		DBGC2(nic, "tap %p read %d bytes\n", nic, r);
149 152
 
150 153
 		iob_put(iobuf, r);

Loading…
Cancel
Save