From nobody Wed Sep 16 13:56:59 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hlL6S6Kvhz6rW2S for ; Wed, 16 Sep 2026 13:57:04 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "YR2" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hlL6S5BsHz3JGf for ; Wed, 16 Sep 2026 13:57:04 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1789567024; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=xEpw+N8Axdt2yrCr4uL25cmrjOcKlkCggL+syN1CpmM=; b=W9l60pyGcMH7VEM5WZyYnk7AM5iK9csqdHz1mYuJ/7YN7Hs/P+mdXAij3fl28T1VetS0DW 29U7HNPUxZaSzgrS4lVhiEaMY4yYvZU3JTB240rZIGvFTHGB63NEp7dfg5MpX3s9U25Re3 cBsZXJ0yNEyxqfGcaKv+JBNnO00Zl+hU1ifVVy95yGXaR+r7Raq16W0cRKJtmn3Cx1FtOJ ZwSTfYKY5fxRTOSAp6zOACI4RvrVTOj1Fg4rzolT8ixXn/esrwvkoSJaa78nkowXx8GqAN scTUl5Yq1bglxsd+kh5Ca+oKK830hDCXeamnvav2yyoBK/aiaeIh4oN9AJ28rA== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1789567024; b=Qjo1RP01kRrDqmC91vRZGoBzMWRhZPVJ6qxrMG7AkE2X3a6AzYN5afj60FXGR8jdXqCE+y RzZAlFMM+EDshqOR8tMKRHRux3zyfioBN3HxEcnJuVVmI3//ysgUu9XZ5nEHLt5gaDxxpX uJ3NMygvjVWLOnzT/SFZVjmZnpNdHh7LvM3ToxKFrmniNMVcWEn9h3gJTyh27gEVCGhzL3 xPN9cgf6IH7ZNsHePDFUtNQ1hNr2DFRGiOxR95pULNzri0+hrsaUM7aoDtpak4Ybzhc5o+ Rjw3Z1ptPEUfxovPKoeBGHqet09jCKm6ypmF7RD5wNs0bmqYhjVaN57Ql3cqng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1789567024; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=xEpw+N8Axdt2yrCr4uL25cmrjOcKlkCggL+syN1CpmM=; b=SzcJBhUvoslPqoMHoP7efIla34lD8F/YnK1ugG/drPs92fJ/OIXPDkh8JTR9aoyErHzfvC 6c+J5n5iaEl1TkU4gXKtKo2eXrLU/b0t2vu94shMNfuD6+eECIAh6N95YWgoRVNsHXNnV2 iTEMoTFhfLhPZ2a9pLXyNYjqR/ncwYwJxpgOJ+lfSocKDg3qrnUGwCv8JeT8VuV0k8D0o5 1nnSBiAmxfGcVYqtltN53S2vmclPgGAxNLTNhesxUzOy5MYFq/sOclupQP3//6fAOt7Oq5 f8w7Zf8ekJlJdRLizFouw46aqe+LzUMLCHRBcmq2raNEyYGVYMRMk+Q+JuGCrA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hlL6S4DcwzqJX for ; Wed, 16 Sep 2026 13:57:04 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 34851 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 16 Sep 2026 13:56:59 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav Subject: git: b7e5c2e008f5 - main - hastd: Use fixed-length protocol names List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: b7e5c2e008f5b441611830ad3a0329de0882419e Auto-Submitted: auto-generated Date: Wed, 16 Sep 2026 13:56:59 +0000 Message-Id: <6aaaa02b.34851.bd7c45@gitrepo.freebsd.org> The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=b7e5c2e008f5b441611830ad3a0329de0882419e commit b7e5c2e008f5b441611830ad3a0329de0882419e Author: Dag-Erling Smørgrav AuthorDate: 2026-09-08 20:55:15 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2026-09-16 13:56:44 +0000 hastd: Use fixed-length protocol names All communication between hastd nodes and internally between hastd 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 hastd 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 hastd requires one). Note that this issue appears to have been reported independently first by Alessandro Sagratini in PR 234576 and then by Martin Vidovic in D57511. I ended up going in a different direction than Martin's patch, but his analysis was invaluable, hence the double credit below. PR: 234576 Reported by: Martin Vidovic MFC after: 1 week Event: EuroBSDcon DevSummit 2026 Reviewed by: xtronom_gmail.com, kevans, glebius, gjb Differential Revision: https://reviews.freebsd.org/D59521 --- sbin/hastd/proto.c | 15 +++++---------- sbin/hastd/proto_impl.h | 2 +- sbin/hastd/proto_socketpair.c | 2 +- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/sbin/hastd/proto.c b/sbin/hastd/proto.c index 70166271a747..56cac566bad0 100644 --- a/sbin/hastd/proto.c +++ b/sbin/hastd/proto.c @@ -281,7 +281,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 ret, fd; PJDLOG_ASSERT(conn != NULL); @@ -293,11 +292,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); ret = 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 (ret != 0) { errno = ret; @@ -310,7 +307,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)]; struct proto *proto; struct proto_conn *newconn; int ret, fd; @@ -321,10 +318,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)); - - ret = conn->pc_proto->prt_recv(conn->pc_ctx, (unsigned char *)protoname, - sizeof(protoname) - 1, &fd); + ret = conn->pc_proto->prt_recv(conn->pc_ctx, protoname, + sizeof(protoname), &fd); if (ret != 0) { errno = ret; return (-1); @@ -333,7 +328,7 @@ proto_connection_recv(const struct proto_conn *conn, bool client, PJDLOG_ASSERT(fd >= 0); TAILQ_FOREACH(proto, &protos, prt_next) { - if (strcmp(proto->prt_name, protoname) == 0) + if (memcmp(proto->prt_name, protoname, sizeof(protoname)) == 0) break; } if (proto == NULL) { diff --git a/sbin/hastd/proto_impl.h b/sbin/hastd/proto_impl.h index 0a0074545f38..181a4cd4a17d 100644 --- a/sbin/hastd/proto_impl.h +++ b/sbin/hastd/proto_impl.h @@ -53,7 +53,7 @@ typedef void prt_remote_address_t(const void *, char *, size_t); typedef void prt_close_t(void *); struct proto { - const char *prt_name; + char prt_name[4]; prt_client_t *prt_client; prt_connect_t *prt_connect; prt_connect_wait_t *prt_connect_wait; diff --git a/sbin/hastd/proto_socketpair.c b/sbin/hastd/proto_socketpair.c index 59ac9553ff6e..31b657f17c32 100644 --- a/sbin/hastd/proto_socketpair.c +++ b/sbin/hastd/proto_socketpair.c @@ -219,7 +219,7 @@ sp_close(void *ctx) } static struct proto sp_proto = { - .prt_name = "socketpair", + .prt_name = "skp", .prt_client = sp_client, .prt_send = sp_send, .prt_recv = sp_recv,