On Tue, Jun 30, 2020 at 7:23 PM Herbert Xu <herb...@gondor.apana.org.au> wrote: > > On Tue, Jun 30, 2020 at 07:17:46PM -0700, Eric Dumazet wrote: > > > > The main issue of the prior code was the double read of key->keylen in > > tcp_md5_hash_key(), not that few bytes could change under us. > > > > I used smp_rmb() to ease backports, since old kernels had no > > READ_ONCE()/WRITE_ONCE(), but ACCESS_ONCE() instead. > > If it's the double-read that you're protecting against, you should > just use barrier() and the comment should say so too.
I made this clear in the changelog, do we want comments all over the places ? Do not get me wrong, we had this bug for years and suddenly this is a big deal... MD5 keys are read with RCU protection, and tcp_md5_do_add() might update in-place a prior key. Normally, typical RCU updates would allocate a new piece of memory. In this case only key->key and key->keylen might be updated, and we do not care if an incoming packet could see the old key, the new one, or some intermediate value, since changing the key on a live flow is known to be problematic anyway. We only want to make sure that in the case key->keylen is changed, cpus in tcp_md5_hash_key() wont try to use uninitialized data, or crash because key->keylen was read twice to feed sg_init_one() and ahash_request_set_crypt()