MichaƂ Koc reported another isakmpd(8) crash, this time related to a 
NULL dereference:

#0 0x0000076e6ff12959 in ipsec_sa_check_flow_any (sa=Variable "sa" is not 
available.) at /usr/src/sbin/isakmpd/ipsec.c:275
#1 0x0000076e6ff1c215 in sa_find (check=0x76e6ff128d0 
<ipsec_sa_check_flow_any>, arg=0x7708ab93a00) at /usr/src/sbin/isakmpd/sa.c:132
#2 0x0000076e6ff152ca in ipsec_delete_spi (sa=0x7708ab93a00, 
proto=0x771456e4a00, incoming=0) at /usr/src/sbin/isakmpd/ipsec.c:1573
#3 0x0000076e6ff1c5d1 in proto_free (proto=0x771456e4a00) at 
/usr/src/sbin/isakmpd/sa.c:809
#4 0x0000076e6ff1ceb5 in sa_release (sa=0x7708ab93a00) at 
/usr/src/sbin/isakmpd/sa.c:884
#5 0x0000076e6ff06a04 in exchange_free_aux (v_exch=Variable "v_exch" is not 
available.) at /usr/src/sbin/isakmpd/exchange.c:1238
#6 0x0000076e6ff1e8f0 in timer_handle_expirations () at 
/usr/src/sbin/isakmpd/timer.c:76
#7 0x0000076e6ff15b1b in main (argc=Variable "argc" is not available.) at 
/usr/src/sbin/isakmpd/isakmpd.c:533

In this case sa_find() is called from a timer.  It iterates over all the
`sa' but some of them might be uninitialized.   This can happen if
`finalize_exchange' hasn't yet been called.  But in this case we know,
or at least can't tell if, the SA won't match the flow of another one.
So simply bail.

ok?

Index: ipsec.c
===================================================================
RCS file: /cvs/src/sbin/isakmpd/ipsec.c,v
retrieving revision 1.146
diff -u -p -r1.146 ipsec.c
--- ipsec.c     10 Dec 2015 17:27:00 -0000      1.146
+++ ipsec.c     3 Jul 2017 09:24:39 -0000
@@ -272,6 +272,15 @@ ipsec_sa_check_flow_any(struct sa *sa, v
            isa->dport != isa2->dport)
                return 0;
 
+       /*
+        * If at least one of the IPsec SAs is incomplete, we're done.
+        */
+       if (isa->src_net == NULL || isa2->src_net == NULL ||
+           isa->dst_net == NULL || isa2->dst_net == NULL ||
+           isa->src_mask == NULL || isa2->src_mask == NULL ||
+           isa->dst_mask == NULL || isa2->dst_mask == NULL)
+               return 0;
+
        return isa->src_net->sa_family == isa2->src_net->sa_family &&
            memcmp(sockaddr_addrdata(isa->src_net),
            sockaddr_addrdata(isa2->src_net),

Reply via email to