Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F178065909
D62060.1795883239.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None
D62060.1795883239.diff
View Options
diff --git a/usr.sbin/bhyve/net_backend_slirp.c b/usr.sbin/bhyve/net_backend_slirp.c
--- a/usr.sbin/bhyve/net_backend_slirp.c
+++ b/usr.sbin/bhyve/net_backend_slirp.c
@@ -50,6 +50,8 @@
#include <sys/socket.h>
#include <sys/wait.h>
+#include <net/ethernet.h>
+
#include <assert.h>
#include <errno.h>
#include <signal.h>
@@ -72,7 +74,7 @@
int s;
pid_t helper;
struct mevent *mevp;
- size_t mtu;
+ size_t bufsize;
uint8_t *buf;
};
@@ -139,10 +141,14 @@
} else {
mtu = DEFAULT_MTU;
}
+ if (mtu > SIZE_MAX - ETHER_HDR_LEN) {
+ EPRINTLN("MTU too large");
+ goto err;
+ }
nvlist_add_number(config, "mtui", mtu);
- priv->mtu = mtu;
- priv->buf = malloc(mtu);
+ priv->bufsize = mtu + ETHER_HDR_LEN;
+ priv->buf = malloc(priv->bufsize);
if (priv->buf == NULL) {
EPRINTLN("Could not allocate buffer");
goto err;
@@ -217,7 +223,7 @@
* Copying into the buffer is totally unnecessary, but we don't
* implement MSG_TRUNC for SEQPACKET sockets.
*/
- n = recv(priv->s, priv->buf, priv->mtu, MSG_PEEK | MSG_DONTWAIT);
+ n = recv(priv->s, priv->buf, priv->bufsize, MSG_PEEK | MSG_DONTWAIT);
if (n < 0)
return (errno == EWOULDBLOCK ? 0 : -1);
return (n);
@@ -243,7 +249,7 @@
return (0);
return (-1);
}
- assert((size_t)n <= priv->mtu);
+ assert((size_t)n <= priv->bufsize);
return (n);
}
diff --git a/usr.sbin/bhyve/slirp/slirp-helper.c b/usr.sbin/bhyve/slirp/slirp-helper.c
--- a/usr.sbin/bhyve/slirp/slirp-helper.c
+++ b/usr.sbin/bhyve/slirp/slirp-helper.c
@@ -21,6 +21,8 @@
#include <sys/nv.h>
#include <sys/socket.h>
+#include <net/ethernet.h>
+
#include <assert.h>
#include <capsicum_helpers.h>
#include <dlfcn.h>
@@ -45,7 +47,7 @@
struct pollfd *pollfds;
size_t npollfds;
size_t lastpollfd;
- size_t mtu;
+ size_t bufsize;
uint8_t *buf;
};
@@ -104,7 +106,7 @@
priv = param;
- assert(len <= priv->mtu);
+ assert(len <= priv->bufsize);
n = send(priv->sock, buf, len, MSG_EOR);
if (n < 0) {
warn("slirp_cb_send_packet: send");
@@ -289,7 +291,7 @@
ssize_t n;
do {
- n = recv(priv->sock, priv->buf, priv->mtu,
+ n = recv(priv->sock, priv->buf, priv->bufsize,
MSG_DONTWAIT);
if (n < 0) {
if (errno == EWOULDBLOCK)
@@ -515,8 +517,10 @@
err(1, "nvlist_recv");
mtu = nvlist_get_number(config, "mtui");
- priv.mtu = mtu;
- priv.buf = malloc(mtu);
+ if (mtu > SIZE_MAX - ETHER_HDR_LEN)
+ errx(1, "MTU too large");
+ priv.bufsize = mtu + ETHER_HDR_LEN;
+ priv.buf = malloc(priv.bufsize);
if (priv.buf == NULL)
err(1, "malloc");
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 28, 4:27 PM (19 h, 27 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
42029177
Default Alt Text
D62060.1795883239.diff (2 KB)
Attached To
Mode
D62060: bhyve: slirp: fix MTU handling
Attached
Detach File
Event Timeline