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

Loading…
Cancel
Save