git: c260d5cd8e36 - main - routing: fix crash when RTM_CHANGE results in no-op for the multipath route.

From: Alexander V. Chernikov <melifaro_at_FreeBSD.org>
Date: Sat, 25 Jun 2022 19:41:54 UTC
The branch main has been updated by melifaro:

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

commit c260d5cd8e364ad448ba714d9f851976c6f8da51
Author:     Alexander V. Chernikov <melifaro@FreeBSD.org>
AuthorDate: 2022-06-25 19:32:59 +0000
Commit:     Alexander V. Chernikov <melifaro@FreeBSD.org>
CommitDate: 2022-06-25 19:35:09 +0000

    routing: fix crash when RTM_CHANGE results in no-op for the multipath
    route.
    
    Reporting logic assumed there is always some nhop change for every
     successful modification operation. Explicitly check that the changed
     nexthop indeed exists when reporting back to userland.
    
    MFC after:      2 weeks
    Reported by:    Claudio Jeker <claudio.jeker@klarasystems.com>
    Tested by:      Claudio Jeker <claudio.jeker@klarasystems.com>
---
 sys/net/rtsock.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c
index bbdd0279a04c..6775f09cfe50 100644
--- a/sys/net/rtsock.c
+++ b/sys/net/rtsock.c
@@ -1124,9 +1124,12 @@ route_output(struct mbuf *m, struct socket *so, ...)
 				rc = rc_simple;
 			}
 #endif
+			/* nh MAY be empty if RTM_CHANGE request is no-op */
 			nh = rc.rc_nh_new;
-			rtm->rtm_index = nh->nh_ifp->if_index;
-			rtm->rtm_flags = rc.rc_rt->rte_flags | nhop_get_rtflags(nh);
+			if (nh != NULL) {
+				rtm->rtm_index = nh->nh_ifp->if_index;
+				rtm->rtm_flags = rc.rc_rt->rte_flags | nhop_get_rtflags(nh);
+			}
 		}
 		break;
 
@@ -1163,7 +1166,7 @@ route_output(struct mbuf *m, struct socket *so, ...)
 		senderr(EOPNOTSUPP);
 	}
 
-	if (error == 0) {
+	if (error == 0 && nh != NULL) {
 		error = update_rtm_from_rc(&info, &rtm, alloc_len, &rc, nh);
 		/*
 		 * Note that some sockaddr pointers may have changed to