Skip to content

Commit 85178d7

Browse files
pcmooregregkh
authored andcommitted
cipso,calipso: resolve a number of problems with the DOI refcounts
commit ad5d07f upstream. 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: b1edeb1 ("netlabel: Replace protocol/NetLabel linking with refrerence counts") Fixes: d7cce01 ("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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent e03ed11 commit 85178d7

3 files changed

Lines changed: 9 additions & 19 deletions

File tree

‎net/ipv4/cipso_ipv4.c‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -519,16 +519,10 @@ int cipso_v4_doi_remove(u32 doi, struct netlbl_audit *audit_info)
519519
ret_val = -ENOENT;
520520
goto doi_remove_return;
521521
}
522-
if (!refcount_dec_and_test(&doi_def->refcount)) {
523-
spin_unlock(&cipso_v4_doi_list_lock);
524-
ret_val = -EBUSY;
525-
goto doi_remove_return;
526-
}
527522
list_del_rcu(&doi_def->list);
528523
spin_unlock(&cipso_v4_doi_list_lock);
529524

530-
cipso_v4_cache_invalidate();
531-
call_rcu(&doi_def->rcu, cipso_v4_doi_free_rcu);
525+
cipso_v4_doi_putdef(doi_def);
532526
ret_val = 0;
533527

534528
doi_remove_return:
@@ -585,9 +579,6 @@ void cipso_v4_doi_putdef(struct cipso_v4_doi *doi_def)
585579

586580
if (!refcount_dec_and_test(&doi_def->refcount))
587581
return;
588-
spin_lock(&cipso_v4_doi_list_lock);
589-
list_del_rcu(&doi_def->list);
590-
spin_unlock(&cipso_v4_doi_list_lock);
591582

592583
cipso_v4_cache_invalidate();
593584
call_rcu(&doi_def->rcu, cipso_v4_doi_free_rcu);

‎net/ipv6/calipso.c‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ struct calipso_map_cache_entry {
8383

8484
static struct calipso_map_cache_bkt *calipso_cache;
8585

86+
static void calipso_cache_invalidate(void);
87+
static void calipso_doi_putdef(struct calipso_doi *doi_def);
88+
8689
/* Label Mapping Cache Functions
8790
*/
8891

@@ -444,15 +447,10 @@ static int calipso_doi_remove(u32 doi, struct netlbl_audit *audit_info)
444447
ret_val = -ENOENT;
445448
goto doi_remove_return;
446449
}
447-
if (!refcount_dec_and_test(&doi_def->refcount)) {
448-
spin_unlock(&calipso_doi_list_lock);
449-
ret_val = -EBUSY;
450-
goto doi_remove_return;
451-
}
452450
list_del_rcu(&doi_def->list);
453451
spin_unlock(&calipso_doi_list_lock);
454452

455-
call_rcu(&doi_def->rcu, calipso_doi_free_rcu);
453+
calipso_doi_putdef(doi_def);
456454
ret_val = 0;
457455

458456
doi_remove_return:
@@ -508,10 +506,8 @@ static void calipso_doi_putdef(struct calipso_doi *doi_def)
508506

509507
if (!refcount_dec_and_test(&doi_def->refcount))
510508
return;
511-
spin_lock(&calipso_doi_list_lock);
512-
list_del_rcu(&doi_def->list);
513-
spin_unlock(&calipso_doi_list_lock);
514509

510+
calipso_cache_invalidate();
515511
call_rcu(&doi_def->rcu, calipso_doi_free_rcu);
516512
}
517513

‎net/netlabel/netlabel_cipso_v4.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,7 @@ static int netlbl_cipsov4_list(struct sk_buff *skb, struct genl_info *info)
575575

576576
break;
577577
}
578+
cipso_v4_doi_putdef(doi_def);
578579
rcu_read_unlock();
579580

580581
genlmsg_end(ans_skb, data);
@@ -583,12 +584,14 @@ static int netlbl_cipsov4_list(struct sk_buff *skb, struct genl_info *info)
583584
list_retry:
584585
/* XXX - this limit is a guesstimate */
585586
if (nlsze_mult < 4) {
587+
cipso_v4_doi_putdef(doi_def);
586588
rcu_read_unlock();
587589
kfree_skb(ans_skb);
588590
nlsze_mult *= 2;
589591
goto list_start;
590592
}
591593
list_failure_lock:
594+
cipso_v4_doi_putdef(doi_def);
592595
rcu_read_unlock();
593596
list_failure:
594597
kfree_skb(ans_skb);

0 commit comments

Comments
 (0)