git: 7a78ae88659e - main - netlink: Zero-initialize writer structures allocated on the stack

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Thu, 26 Jan 2023 15:46:45 UTC
The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=7a78ae88659e0f6a901574d17672d1ccdc3e971b

commit 7a78ae88659e0f6a901574d17672d1ccdc3e971b
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2023-01-26 15:46:19 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2023-01-26 15:46:19 +0000

    netlink: Zero-initialize writer structures allocated on the stack
    
    The prevailing pattern seems to be to simply initialize all fields to
    zero.  Without this, it's possible to trigger a branch on uninitialized
    memory, specifically, when testing nw->ignore_limit in
    nlmsg_refill_buffer().
    
    Initialize the writer structure in a couple of functions where this is
    necessary.
    
    Reported by:    KMSAN
    Reviewed by:    melifaro
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D38213
---
 sys/netlink/route/rt.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/sys/netlink/route/rt.c b/sys/netlink/route/rt.c
index 07735cd9d5bc..9854785d0ee8 100644
--- a/sys/netlink/route/rt.c
+++ b/sys/netlink/route/rt.c
@@ -336,9 +336,9 @@ static void
 report_operation(uint32_t fibnum, struct rib_cmd_info *rc,
     struct nlpcb *nlp, struct nlmsghdr *hdr)
 {
-	struct nl_writer nw;
-
+	struct nl_writer nw = {};
 	uint32_t group_id = family_to_group(rt_get_family(rc->rc_rt));
+
 	if (nlmsg_get_group_writer(&nw, NLMSG_SMALL, NETLINK_ROUTE, group_id)) {
 		struct route_nhop_data rnd = {
 			.rnd_nhop = rc_get_nhop(rc),
@@ -918,10 +918,9 @@ rtnl_handle_getroute(struct nlmsghdr *hdr, struct nlpcb *nlp, struct nl_pstate *
 void
 rtnl_handle_route_event(uint32_t fibnum, const struct rib_cmd_info *rc)
 {
+	struct nl_writer nw = {};
 	int family, nlm_flags = 0;
 
-	struct nl_writer nw;
-
 	family = rt_get_family(rc->rc_rt);
 
 	/* XXX: check if there are active listeners first */