hastd and hastctl both link hast_proto.c's hast_proto_recv_hdr(), which asserts that ebuf_data() returns a non-NULL pointer before receiving a message's payload — but ebuf_data() legitimately returns NULL for a zero-size buffer, and a zero-size payload (a bare protocol header with no attached nv data) is a valid message on the wire. Any peer that sends one crashes the receiving process with SIGABRT. In practice this makes service hastd onerestart 100% reproducible crash, even against a completely empty /etc/hast.conf: hastd's own stop_precmd (see /etc/rc.d/hastd) runs hastctl role init all before stopping the daemon, and that exchange includes a zero-size message — so hastctl (not hastd itself) aborts every single time. Environment: - FreeBSD 16.0-CURRENT, main-n288684-420428718da7, amd64 - Reproduced independently on two separate physical/virtual machines running the same CURRENT snapshot - Not related to the connection-migration bug tracked in bug 292322 / reviewed as D57511 (a different function, proto_common_recv's MSG_WAITALL sizing) — this is a separate defect Reproduction: On a system with hastd_enable="YES" (an otherwise empty /etc/hast.conf is sufficient — no resources need to be configured): # service hastd onerestart Proposed fix: Only dereference/receive when there's actually a nonzero-size payload to read — there is nothing to assert or receive when hdr.size == 0: --- a/sbin/hastd/hast_proto.c +++ b/sbin/hastd/hast_proto.c @@ -149,10 +149,12 @@ hast_proto_recv_hdr(const struct proto_conn *conn, struct nv **nvp) if (ebuf_add_tail(eb, NULL, hdr.size) == -1) goto fail; - hptr = ebuf_data(eb, NULL); - PJDLOG_ASSERT(hptr != NULL); - if (proto_recv(conn, hptr, hdr.size) == -1) - goto fail; + if (hdr.size > 0) { + hptr = ebuf_data(eb, NULL); + PJDLOG_ASSERT(hptr != NULL); + if (proto_recv(conn, hptr, hdr.size) == -1) + goto fail; + } nv = nv_ntoh(eb); if (nv == NULL) goto fail; This has been built and tested locally: hastd/hastctl rebuilt from a patched tree, installed on two machines, and service hastd onerestart now succeeds cleanly and repeatedly on both, including under a real, active hastd configuration (not just an empty one).
Created attachment 274320 [details] patch to only dereference/receive when there's actually a nonzero-size payload to read
Created attachment 274321 [details] fixed patch Hopefully the attachment is not mangled this time.
Do all callers of hast_proto_recv_hdr() actually handle the case where the payload size is zero? Are they potentially relying on this assertion to guard against malicious payloads?
https://reviews.freebsd.org/D59306
(In reply to Mark Johnston from comment #3) Callers of hast_proto_recv_hdr() get an nvlist. If hdr.size == 0, that nvlist is empty and nv_get_*() fails, which the code already checks for.
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=8646d65b45339642d4aab1de35a2bc79fc45f09e commit 8646d65b45339642d4aab1de35a2bc79fc45f09e Author: Glen Barber <gjb@FreeBSD.org> AuthorDate: 2026-09-03 07:51:28 +0000 Commit: Dag-Erling Smørgrav <des@FreeBSD.org> CommitDate: 2026-09-03 07:58:54 +0000 hastd: Fix crash on empty message A HAST message can be empty, in which case ebuf_add_tail() does nothing and ebuf_data() returns NULL because the size of the ebuf is zero, but hast_proto_recv_hdr() asserts that the return value is not NULL, resulting in an immediate crash if hastctl or hastd receive an empty message. This is trivially reproducable by running `hastctl status` or `hastctl role init` (as the rc script does prior to stopping hastd). To avoid this, don't try to grow the ebuf or receive additional data if the header size is zero. PR: 298085 MFC after: 3 days Reviewed by: kevans, gjb Differential Revision: https://reviews.freebsd.org/D59306 sbin/hastd/hast_proto.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
A commit in branch stable/15 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=2581bc3af3815e92b0eef44bee224fff92931de8 commit 2581bc3af3815e92b0eef44bee224fff92931de8 Author: Glen Barber <gjb@FreeBSD.org> AuthorDate: 2026-09-03 07:51:28 +0000 Commit: Dag-Erling Smørgrav <des@FreeBSD.org> CommitDate: 2026-09-03 11:56:38 +0000 hastd: Fix crash on empty message A HAST message can be empty, in which case ebuf_add_tail() does nothing and ebuf_data() returns NULL because the size of the ebuf is zero, but hast_proto_recv_hdr() asserts that the return value is not NULL, resulting in an immediate crash if hastctl or hastd receive an empty message. This is trivially reproducable by running `hastctl status` or `hastctl role init` (as the rc script does prior to stopping hastd). To avoid this, don't try to grow the ebuf or receive additional data if the header size is zero. PR: 298085 MFC after: 3 days Reviewed by: kevans, gjb Differential Revision: https://reviews.freebsd.org/D59306 (cherry picked from commit 8646d65b45339642d4aab1de35a2bc79fc45f09e) sbin/hastd/hast_proto.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
A commit in branch stable/14 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=4d83686bc38780405459b45819e9f6482dcd335c commit 4d83686bc38780405459b45819e9f6482dcd335c Author: Glen Barber <gjb@FreeBSD.org> AuthorDate: 2026-09-03 07:51:28 +0000 Commit: Dag-Erling Smørgrav <des@FreeBSD.org> CommitDate: 2026-09-03 11:56:44 +0000 hastd: Fix crash on empty message A HAST message can be empty, in which case ebuf_add_tail() does nothing and ebuf_data() returns NULL because the size of the ebuf is zero, but hast_proto_recv_hdr() asserts that the return value is not NULL, resulting in an immediate crash if hastctl or hastd receive an empty message. This is trivially reproducable by running `hastctl status` or `hastctl role init` (as the rc script does prior to stopping hastd). To avoid this, don't try to grow the ebuf or receive additional data if the header size is zero. PR: 298085 MFC after: 3 days Reviewed by: kevans, gjb Differential Revision: https://reviews.freebsd.org/D59306 (cherry picked from commit 8646d65b45339642d4aab1de35a2bc79fc45f09e) sbin/hastd/hast_proto.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
A commit in branch releng/14.4 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=a6ccb9d6905beabbfccb18b01d454695b496deea commit a6ccb9d6905beabbfccb18b01d454695b496deea Author: Glen Barber <gjb@FreeBSD.org> AuthorDate: 2026-09-03 07:51:28 +0000 Commit: Mark Johnston <markj@FreeBSD.org> CommitDate: 2026-10-13 13:47:11 +0000 hastd: Fix crash on empty message A HAST message can be empty, in which case ebuf_add_tail() does nothing and ebuf_data() returns NULL because the size of the ebuf is zero, but hast_proto_recv_hdr() asserts that the return value is not NULL, resulting in an immediate crash if hastctl or hastd receive an empty message. This is trivially reproducable by running `hastctl status` or `hastctl role init` (as the rc script does prior to stopping hastd). To avoid this, don't try to grow the ebuf or receive additional data if the header size is zero. Approved by: so Security: FreeBSD-EN-26:26.hastd PR: 298085 MFC after: 3 days Reviewed by: kevans, gjb Differential Revision: https://reviews.freebsd.org/D59306 (cherry picked from commit 8646d65b45339642d4aab1de35a2bc79fc45f09e) (cherry picked from commit 4d83686bc38780405459b45819e9f6482dcd335c) sbin/hastd/hast_proto.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
A commit in branch releng/14.5 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=3d10f8cdb001655ba0638c933820abbd0130c1eb commit 3d10f8cdb001655ba0638c933820abbd0130c1eb Author: Glen Barber <gjb@FreeBSD.org> AuthorDate: 2026-09-03 07:51:28 +0000 Commit: Mark Johnston <markj@FreeBSD.org> CommitDate: 2026-10-13 14:03:00 +0000 hastd: Fix crash on empty message A HAST message can be empty, in which case ebuf_add_tail() does nothing and ebuf_data() returns NULL because the size of the ebuf is zero, but hast_proto_recv_hdr() asserts that the return value is not NULL, resulting in an immediate crash if hastctl or hastd receive an empty message. This is trivially reproducable by running `hastctl status` or `hastctl role init` (as the rc script does prior to stopping hastd). To avoid this, don't try to grow the ebuf or receive additional data if the header size is zero. Approved by: so Security: FreeBSD-EN-26:26.hastd PR: 298085 MFC after: 3 days Reviewed by: kevans, gjb Differential Revision: https://reviews.freebsd.org/D59306 (cherry picked from commit 8646d65b45339642d4aab1de35a2bc79fc45f09e) (cherry picked from commit 4d83686bc38780405459b45819e9f6482dcd335c) sbin/hastd/hast_proto.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
A commit in branch releng/15.1 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=ddbf289ac125447c1bcccf784a05f263d8676186 commit ddbf289ac125447c1bcccf784a05f263d8676186 Author: Glen Barber <gjb@FreeBSD.org> AuthorDate: 2026-09-03 07:51:28 +0000 Commit: Mark Johnston <markj@FreeBSD.org> CommitDate: 2026-10-13 14:10:21 +0000 hastd: Fix crash on empty message A HAST message can be empty, in which case ebuf_add_tail() does nothing and ebuf_data() returns NULL because the size of the ebuf is zero, but hast_proto_recv_hdr() asserts that the return value is not NULL, resulting in an immediate crash if hastctl or hastd receive an empty message. This is trivially reproducable by running `hastctl status` or `hastctl role init` (as the rc script does prior to stopping hastd). To avoid this, don't try to grow the ebuf or receive additional data if the header size is zero. Approved by: so Security: FreeBSD-EN-26:26.hastd PR: 298085 MFC after: 3 days Reviewed by: kevans, gjb Differential Revision: https://reviews.freebsd.org/D59306 (cherry picked from commit 8646d65b45339642d4aab1de35a2bc79fc45f09e) (cherry picked from commit 2581bc3af3815e92b0eef44bee224fff92931de8) sbin/hastd/hast_proto.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)