cipso,calipso: resolve a number of problems with the DOI refcounts
authorPaul Moore <paul@paul-moore.com>
Thu, 4 Mar 2021 21:29:51 +0000 (16:29 -0500)
committerDavid S. Miller <davem@davemloft.net>
Thu, 4 Mar 2021 23:26:57 +0000 (15:26 -0800)
commitad5d07f4a9cd671233ae20983848874731102c08
tree3f3646f6f025a9f2f2701773053ad4fe378e207e
parent67eb211487f0c993d9f402d1c196ef159fd6a3b5
cipso,calipso: resolve a number of problems with the DOI refcounts

The current CIPSO and CALIPSO refcounting scheme for the DOI
definitions is a bit flawed in that we:

1. Don't correctly match gets/puts in netlbl_cipsov4_list().
2. Decrement the refcount on each attempt to remove the DOI from the
   DOI list, only removing it from the list once the refcount drops
   to zero.

This patch fixes these problems by adding the missing "puts" to
netlbl_cipsov4_list() and introduces a more conventional, i.e.
not-buggy, refcounting mechanism to the DOI definitions.  Upon the
addition of a DOI to the DOI list, it is initialized with a refcount
of one, removing a DOI from the list removes it from the list and
drops the refcount by one; "gets" and "puts" behave as expected with
respect to refcounts, increasing and decreasing the DOI's refcount by
one.

Fixes: b1edeb102397 ("netlabel: Replace protocol/NetLabel linking with refrerence counts")
Fixes: d7cce01504a0 ("netlabel: Add support for removing a CALIPSO DOI.")
Reported-by: syzbot+9ec037722d2603a9f52e@syzkaller.appspotmail.com
Signed-off-by: Paul Moore <paul@paul-moore.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/ipv4/cipso_ipv4.c
net/ipv6/calipso.c
net/netlabel/netlabel_cipso_v4.c