hash = __sel_hash(sel, family, hmask, dbits, sbits);
 
        if (hash == hmask + 1)
-               return &net->xfrm.policy_inexact[dir];
+               return NULL;
 
        return rcu_dereference_check(net->xfrm.policy_bydst[dir].table,
                     lockdep_is_held(&net->xfrm.xfrm_policy_lock)) + hash;
                chain = policy_hash_bysel(net, &policy->selector,
                                          policy->family,
                                          xfrm_policy_id2dir(policy->index));
+               if (!chain)
+                       chain = &net->xfrm.policy_inexact[dir];
                hlist_for_each_entry(pol, chain, bydst) {
                        if (policy->priority >= pol->priority)
                                newpos = &pol->bydst;
 
        spin_lock_bh(&net->xfrm.xfrm_policy_lock);
        chain = policy_hash_bysel(net, &policy->selector, policy->family, dir);
-       delpol = xfrm_policy_insert_list(chain, policy, excl);
+       if (chain) {
+               delpol = xfrm_policy_insert_list(chain, policy, excl);
+       } else {
+               chain = &net->xfrm.policy_inexact[dir];
+               delpol = xfrm_policy_insert_list(chain, policy, excl);
+       }
 
        if (IS_ERR(delpol)) {
                spin_unlock_bh(&net->xfrm.xfrm_policy_lock);
        *err = 0;
        spin_lock_bh(&net->xfrm.xfrm_policy_lock);
        chain = policy_hash_bysel(net, sel, sel->family, dir);
+       if (!chain)
+               chain = &net->xfrm.policy_inexact[dir];
        ret = NULL;
        hlist_for_each_entry(pol, chain, bydst) {
                if (pol->type == type &&