]> git.proxmox.com Git - mirror_ovs.git/commit
classifier: Prevent tries vs n_tries race leading to NULL dereference.
authorEiichi Tsukata <eiichi.tsukata@nutanix.com>
Wed, 27 May 2020 02:13:34 +0000 (11:13 +0900)
committerIlya Maximets <i.maximets@ovn.org>
Thu, 28 May 2020 09:46:39 +0000 (11:46 +0200)
commita6117059904bb692039c926221964dd6d49b3bfd
treeaca1bbdbbf48f68ca5b3000f00bb6b14e4988b17
parent8c2c503bdb0da1ce6044a53d462f905fd4f8acf5
classifier: Prevent tries vs n_tries race leading to NULL dereference.

Currently classifier tries and n_tries can be updated not atomically,
there is a race condition which can lead to NULL dereference.
The race can happen when main thread updates a classifier tries and
n_tries in classifier_set_prefix_fields() and at the same time revalidator
or handler thread try to lookup them in classifier_lookup__(). Such race
can be triggered when user changes prefixes of flow_table.

Race(user changes flow_table prefixes: ip_dst,ip_src => none):

  [main thread]             [revalidator/handler thread]
  ===========================================================
                            /* cls->n_tries == 2 */
                            for (int i = 0; i < cls->n_tries; i++) {
  trie_init(cls, i, NULL);
  /* n_tries == 0 */
  cls->n_tries = n_tries;
                            /* cls->tries[i]->feild is NULL */
                            trie_ctx_init(&trie_ctx[i],&cls->tries[i]);
                            /* trie->field is NULL */
                            ctx->be32ofs = trie->field->flow_be32ofs;

To prevent the race, instead of re-introducing internal mutex
implemented in the commit fccd7c092e09 ("classifier: Remove internal
mutex."), this patch makes trie field RCU protected and checks it after
read.

Fixes: fccd7c092e09 ("classifier: Remove internal mutex.")
Signed-off-by: Eiichi Tsukata <eiichi.tsukata@nutanix.com>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
lib/classifier.c
lib/classifier.h
tests/test-classifier.c