bfd: restore the data within the packet after hash verification 74/35174/2
authorAndrew Yourtchenko <ayourtch@gmail.com>
Wed, 2 Feb 2022 12:32:39 +0000 (13:32 +0100)
committerAndrew Yourtchenko <ayourtch@gmail.com>
Wed, 2 Feb 2022 19:30:49 +0000 (19:30 +0000)
The BFD delayed auth change test was failing intermittently within CI.
Debugging has shown it depends on the initial random seed, e.g. the below
will consistently fail:

RND_SEED=1643734669.7126195 TEST='bfd.BFDAuthOnOffTestCase.test_auth_change_key_delayed'

Same thing will happen with:
RND_SEED=1643736595.1363552
RND_SEED=1643722239.8224792

The analysis of the behavior shown that the function that is doing the hash verification,
modifies the content of the packet for the purposes of hash computation.
In case of the auth rollover, this function may be called twice - resulting in the second
comparison to be made with a bogus packet data, thus failing the check and the test.

The above values of random seed are the ones where the test makes it
to the point of this double comparison.

The solution is to restore the data within the packet after the check from the array
where we have copied it into before modifying the packet.

Change-Id: Ibb09beb4b1230032db04527bbf38fa335651866b
Type: fix
Signed-off-by: Andrew Yourtchenko <ayourtch@gmail.com>
src/vnet/bfd/bfd_main.c

index 3ed9c03..530b297 100644 (file)
@@ -1634,6 +1634,11 @@ bfd_verify_pkt_auth_key_sha1 (vlib_main_t *vm, const bfd_pkt_t *pkt,
   op.len = sizeof (*with_sha1);
   op.digest = calculated_hash;
   vnet_crypto_process_ops (vm, &op, 1);
+
+  /* Restore the modified data within the packet */
+  clib_memcpy (with_sha1->sha1_auth.hash, hash_from_packet,
+              sizeof (with_sha1->sha1_auth.hash));
+
   if (0 ==
       memcmp (calculated_hash, hash_from_packet, sizeof (calculated_hash)))
     {