> > > @@ -305,29 +284,36 @@ static int sidtab_reverse_lookup(struct sidtab *s, struct context *context, > > > rc = -ENOMEM; > > > dst_convert = sidtab_do_lookup(convert->target, count, 1); > > > if (!dst_convert) { > > > - context_destroy(dst); > > > + context_destroy(&dst->context); > > > goto out_unlock; > > > } > > > > > > - rc = convert->func(context, dst_convert, convert->args); > > > + rc = convert->func(context, &dst_convert->context, > > > + convert->args); > > > if (rc) { > > > - context_destroy(dst); > > > + context_destroy(&dst->context); > > > goto out_unlock; > > > } > > > + dst_convert->sid = index_to_sid(count); > > > + convert->target->count = count + 1; > > > > > > /* at this point we know the insert won't fail */ > > > - convert->target->count = count + 1; > > > + spin_lock_irqsave_nested(&convert->target->lock, flags, > > > + SINGLE_DEPTH_NESTING); > > > + hash_add_rcu(convert->target->context_to_sid, > > > + &dst_convert->list, dst_convert->context.hash); > > > + spin_unlock_irqrestore(&convert->target->lock, flags); > > > > Still having a hard time understanding why we need to lock the target. > > The target here is always the newsidtab allocated by > > security_load_policy(), not yet exposed to any other threads in the system? > > I believe this is to avoid a race with the hash_add() in > sidtab_convert_hashtable(), which locks only the target table. > However, I don't like the fact that we need to mess with inconsistent > lock nesting here... I think it would be better to just lock the > master's spinlock in sidtab_convert_hashtable() - it will then block > more when entries would be added to sidtab, but that shouldn't be a > big concern in practice. > I'll try that. Thanks.