Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F173835200
D58633.id183399.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D58633.id183399.diff
View Options
diff --git a/contrib/lib9p/connection.c b/contrib/lib9p/connection.c
--- a/contrib/lib9p/connection.c
+++ b/contrib/lib9p/connection.c
@@ -85,7 +85,7 @@
free(conn);
}
-void
+int
l9p_connection_recv(struct l9p_connection *conn, const struct iovec *iov,
const size_t niov, void *aux)
{
@@ -106,7 +106,7 @@
L9P_LOG(L9P_WARNING, "cannot unpack received message");
l9p_freefcall(&req->lr_req);
free(req);
- return;
+ return (1);
}
if (ht_add(&conn->lc_requests, req->lr_req.hdr.tag, req)) {
@@ -114,7 +114,7 @@
req->lr_req.hdr.tag);
l9p_freefcall(&req->lr_req);
free(req);
- return;
+ return (1);
}
error = conn->lc_lt.lt_get_response_buffer(req,
@@ -126,7 +126,7 @@
ht_remove(&conn->lc_requests, req->lr_req.hdr.tag);
l9p_freefcall(&req->lr_req);
free(req);
- return;
+ return (1);
}
/*
@@ -135,6 +135,8 @@
* (it must do the latter for Tflush requests).
*/
l9p_threadpool_run(&conn->lc_tp, req);
+
+ return (0);
}
void
diff --git a/contrib/lib9p/lib9p.h b/contrib/lib9p/lib9p.h
--- a/contrib/lib9p/lib9p.h
+++ b/contrib/lib9p/lib9p.h
@@ -223,7 +223,7 @@
int l9p_connection_init(struct l9p_server *server,
struct l9p_connection **connp);
void l9p_connection_free(struct l9p_connection *conn);
-void l9p_connection_recv(struct l9p_connection *conn, const struct iovec *iov,
+int l9p_connection_recv(struct l9p_connection *conn, const struct iovec *iov,
size_t niov, void *aux);
void l9p_connection_close(struct l9p_connection *conn);
struct l9p_fid *l9p_connection_alloc_fid(struct l9p_connection *conn,
diff --git a/contrib/lib9p/transport/socket.c b/contrib/lib9p/transport/socket.c
--- a/contrib/lib9p/transport/socket.c
+++ b/contrib/lib9p/transport/socket.c
@@ -204,8 +204,8 @@
iov.iov_base = buf;
iov.iov_len = length;
- l9p_connection_recv(sc->ls_conn, &iov, 1, NULL);
- free(buf);
+ if (l9p_connection_recv(sc->ls_conn, &iov, 1, buf) != 0)
+ free(buf);
}
L9P_LOG(L9P_INFO, "connection closed");
@@ -230,6 +230,7 @@
ret = xread(fd, buffer, sizeof(uint32_t));
if (ret < 0) {
L9P_LOG(L9P_ERROR, "read(): %s", strerror(errno));
+ free(buffer);
return (-1);
}
@@ -240,6 +241,7 @@
L9P_LOG(L9P_ERROR,
"short read: %zd bytes of %zd expected",
ret, sizeof(uint32_t));
+ free(buffer);
return (-1);
}
@@ -250,12 +252,14 @@
ret = xread(fd, (char *)buffer + sizeof(uint32_t), toread);
if (ret < 0) {
L9P_LOG(L9P_ERROR, "read(): %s", strerror(errno));
+ free(buffer);
return (-1);
}
if (ret != (ssize_t)toread) {
L9P_LOG(L9P_ERROR, "short read: %zd bytes of %zd expected",
ret, toread);
+ free(buffer);
return (-1);
}
@@ -283,7 +287,7 @@
}
static int
-l9p_socket_send_response(struct l9p_request *req __unused,
+l9p_socket_send_response(struct l9p_request *req,
const struct iovec *iov, const size_t niov __unused, const size_t iolen,
void *arg)
{
@@ -291,6 +295,9 @@
assert(sc->ls_fd >= 0);
+ /* Safe to free the request buffer now. */
+ free(req->lr_aux);
+
L9P_LOG(L9P_DEBUG, "%p: sending reply, buf=%p, size=%d", arg,
iov[0].iov_base, iolen);
@@ -304,10 +311,10 @@
}
static void
-l9p_socket_drop_response(struct l9p_request *req __unused,
+l9p_socket_drop_response(struct l9p_request *req,
const struct iovec *iov, size_t niov __unused, void *arg __unused)
{
-
+ free(req->lr_aux);
L9P_LOG(L9P_DEBUG, "%p: drop buf=%p", arg, iov[0].iov_base);
free(iov[0].iov_base);
}
diff --git a/usr.sbin/bhyve/pci_virtio_9p.c b/usr.sbin/bhyve/pci_virtio_9p.c
--- a/usr.sbin/bhyve/pci_virtio_9p.c
+++ b/usr.sbin/bhyve/pci_virtio_9p.c
@@ -213,7 +213,7 @@
iov[i].iov_len));
}
- l9p_connection_recv(sc->vsc_conn, iov, preq->vsr_respidx, preq);
+ (void)l9p_connection_recv(sc->vsc_conn, iov, preq->vsr_respidx, preq);
}
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Sep 29, 7:13 PM (10 h, 44 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39893062
Default Alt Text
D58633.id183399.diff (3 KB)
Attached To
Mode
D58633: lib9p: fix mem leaks and use-after-free in socket.c
Attached
Detach File
Event Timeline
Log In to Comment