mirror of
https://github.com/freebsd/freebsd-src.git
synced 2026-11-07 04:36:52 -10:00
auditdistd: Use fixed-length protocol names
All communication between auditdistd senders and receivers and internally between auditdistd and its worker children passes through the same pair of send / receive functions. The receive function uses recv(2) with the MSG_WAITALL flag, which in theory means we should never get a short read. However, when handing off a socket to a worker child, we also pass a variable-length string identifying the type of socket we're passing, and reading this string relies on a short read. This used to work because the arrival of the descriptor would interrupt the recv(2) call, but this bug was fixed when the AF_UNIX code was rewritten a while ago and auditdistd has been broken ever since. Fixing the length of the protocol name to four characters including the terminating null solves the short-read bug by never requiring a short read (nothing else in auditdistd requires one). PR: 296107 MFC after: 1 week Reviewed by: js, kevans Differential Revision: https://reviews.freebsd.org/D59565
This commit is contained in:
1 parent
989d72fd3d
commit
3ca4b8dd16
4 files changed
+7
-12
No files matched your search
@@ -269,7 +269,6 @@ proto_recv(const struct proto_conn *conn, void *data, size_t size)
|
||||
int
|
||||
proto_connection_send(const struct proto_conn *conn, struct proto_conn *mconn)
|
||||
{
|
||||
const char *protoname;
|
||||
int error, fd;
|
||||
|
||||
PJDLOG_ASSERT(conn != NULL);
|
||||
@@ -281,11 +280,9 @@ proto_connection_send(const struct proto_conn *conn, struct proto_conn *mconn)
|
||||
PJDLOG_ASSERT(mconn->pc_proto != NULL);
|
||||
fd = proto_descriptor(mconn);
|
||||
PJDLOG_ASSERT(fd >= 0);
|
||||
protoname = mconn->pc_proto->prt_name;
|
||||
PJDLOG_ASSERT(protoname != NULL);
|
||||
|
||||
error = conn->pc_proto->prt_send(conn->pc_ctx,
|
||||
(const unsigned char *)protoname, strlen(protoname) + 1, fd);
|
||||
mconn->pc_proto->prt_name, sizeof(mconn->pc_proto->prt_name), fd);
|
||||
proto_close(mconn);
|
||||
if (error != 0) {
|
||||
errno = error;
|
||||
@@ -303,7 +300,7 @@ proto_wrap(const char *protoname, bool client, int fd,
|
||||
int error;
|
||||
|
||||
TAILQ_FOREACH(proto, &protos, prt_next) {
|
||||
if (strcmp(proto->prt_name, protoname) == 0)
|
||||
if (memcmp(proto->prt_name, protoname, sizeof(proto->prt_name)) == 0)
|
||||
break;
|
||||
}
|
||||
if (proto == NULL) {
|
||||
@@ -332,7 +329,7 @@ int
|
||||
proto_connection_recv(const struct proto_conn *conn, bool client,
|
||||
struct proto_conn **newconnp)
|
||||
{
|
||||
char protoname[128];
|
||||
char protoname[sizeof(conn->pc_proto->prt_name)];
|
||||
int error, fd;
|
||||
|
||||
PJDLOG_ASSERT(conn != NULL);
|
||||
@@ -341,10 +338,8 @@ proto_connection_recv(const struct proto_conn *conn, bool client,
|
||||
PJDLOG_ASSERT(conn->pc_proto->prt_recv != NULL);
|
||||
PJDLOG_ASSERT(newconnp != NULL);
|
||||
|
||||
bzero(protoname, sizeof(protoname));
|
||||
|
||||
error = conn->pc_proto->prt_recv(conn->pc_ctx,
|
||||
(unsigned char *)protoname, sizeof(protoname) - 1, &fd);
|
||||
protoname, sizeof(protoname), &fd);
|
||||
if (error != 0) {
|
||||
errno = error;
|
||||
return (-1);
|
||||
|
||||
@@ -54,7 +54,7 @@ typedef void prt_close_t(void *);
|
||||
typedef int prt_exec_t(int, char *[]);
|
||||
|
||||
struct proto {
|
||||
const char *prt_name;
|
||||
char prt_name[4];
|
||||
prt_connect_t *prt_connect;
|
||||
prt_connect_wait_t *prt_connect_wait;
|
||||
prt_server_t *prt_server;
|
||||
|
||||
@@ -247,7 +247,7 @@ sp_close(void *ctx)
|
||||
}
|
||||
|
||||
static struct proto sp_proto = {
|
||||
.prt_name = "socketpair",
|
||||
.prt_name = "skp",
|
||||
.prt_connect = sp_connect,
|
||||
.prt_wrap = sp_wrap,
|
||||
.prt_send = sp_send,
|
||||
|
||||
@@ -854,7 +854,7 @@ tls_wrap(int fd, bool client, void **ctxp)
|
||||
if (tlsctx == NULL)
|
||||
return (errno);
|
||||
|
||||
if (proto_wrap("socketpair", client, fd, &sock) == -1) {
|
||||
if (proto_wrap("skp", client, fd, &sock) == -1) {
|
||||
error = errno;
|
||||
free(tlsctx);
|
||||
return (error);
|
||||
|
||||
Reference in new issue
Block a user