nhrpd: fixes duplicate auth extension

When an NHRP server was forwarding a message, it was copying all
extensions from the originally received packet. The authentication
extension must be regenerated hop by hop per RFC2332. The copied
auth extension had an incorrect length. This fix checks for the
auth extension when copying extensions and omits the original
packet auth and instead regenerates a new auth extension.

Fix bug #16466

Signed-off-by: Dave LeRoy <dleroy@labn.net>
This commit is contained in:
Dave LeRoy 2024-07-25 11:58:22 -07:00
parent 353efe7ae8
commit 7c20ffaaba

View file

@ -959,9 +959,12 @@ static void nhrp_peer_forward(struct nhrp_peer *p,
if (type == NHRP_EXTENSION_END) if (type == NHRP_EXTENSION_END)
break; break;
dst = NULL;
if (type != NHRP_EXTENSION_AUTHENTICATION) {
dst = nhrp_ext_push(zb, hdr, htons(ext->type)); dst = nhrp_ext_push(zb, hdr, htons(ext->type));
if (!dst) if (!dst)
goto err; goto err;
}
switch (type) { switch (type) {
case NHRP_EXTENSION_FORWARD_TRANSIT_NHS: case NHRP_EXTENSION_FORWARD_TRANSIT_NHS:
@ -1047,12 +1050,11 @@ static void nhrp_peer_forward(struct nhrp_peer *p,
} }
break; break;
case NHRP_EXTENSION_AUTHENTICATION: case NHRP_EXTENSION_AUTHENTICATION:
/* At this point, received packet has been authenticated. /* Extensions can be copied from original packet except
* Just need to regenerate auth extension before forwarding. * authentication extension which must be regenerated
* This will be done below in nhrp_packet_complete_auth(). * hop by hop.
*/ */
break; break;
default: default:
if (htons(ext->type) & NHRP_EXTENSION_FLAG_COMPULSORY) if (htons(ext->type) & NHRP_EXTENSION_FLAG_COMPULSORY)
/* FIXME: RFC says to just copy, but not /* FIXME: RFC says to just copy, but not
@ -1068,6 +1070,7 @@ static void nhrp_peer_forward(struct nhrp_peer *p,
zbuf_copy(zb, &extpl, len); zbuf_copy(zb, &extpl, len);
break; break;
} }
if (dst)
nhrp_ext_complete(zb, dst); nhrp_ext_complete(zb, dst);
} }