diff options
author | Elena Reshetova <elena.reshetova@intel.com> | 2017-10-20 05:53:32 -0400 |
---|---|---|
committer | Anna Schumaker <Anna.Schumaker@Netapp.com> | 2017-11-17 13:47:59 -0500 |
commit | eba6dd691743a9d7a57735f36bf6946fc58878ec (patch) | |
tree | e6b14b8b629462d1e7707bd32536292e91bccef0 /fs/nfs/pnfs.c | |
parent | a2a5dea7b6cb77365ed9c987f54d160668c8a95f (diff) |
fs, nfs: convert pnfs_layout_segment.pls_refcount from atomic_t to refcount_t
refcount_t type and corresponding API should be
used instead of atomic_t when the variable is used as
a reference counter. This allows to avoid accidental
refcounter overflows that might lead to use-after-free
situations.
Signed-off-by: Elena Reshetova <elena.reshetova@intel.com>
Signed-off-by: Hans Liljestrand <ishkamiel@gmail.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: David Windsor <dwindsor@gmail.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
Diffstat (limited to 'fs/nfs/pnfs.c')
-rw-r--r-- | fs/nfs/pnfs.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c index 3bcd669a3152..499bb710713e 100644 --- a/fs/nfs/pnfs.c +++ b/fs/nfs/pnfs.c | |||
@@ -450,7 +450,7 @@ pnfs_init_lseg(struct pnfs_layout_hdr *lo, struct pnfs_layout_segment *lseg, | |||
450 | { | 450 | { |
451 | INIT_LIST_HEAD(&lseg->pls_list); | 451 | INIT_LIST_HEAD(&lseg->pls_list); |
452 | INIT_LIST_HEAD(&lseg->pls_lc_list); | 452 | INIT_LIST_HEAD(&lseg->pls_lc_list); |
453 | atomic_set(&lseg->pls_refcount, 1); | 453 | refcount_set(&lseg->pls_refcount, 1); |
454 | set_bit(NFS_LSEG_VALID, &lseg->pls_flags); | 454 | set_bit(NFS_LSEG_VALID, &lseg->pls_flags); |
455 | lseg->pls_layout = lo; | 455 | lseg->pls_layout = lo; |
456 | lseg->pls_range = *range; | 456 | lseg->pls_range = *range; |
@@ -507,13 +507,13 @@ pnfs_put_lseg(struct pnfs_layout_segment *lseg) | |||
507 | return; | 507 | return; |
508 | 508 | ||
509 | dprintk("%s: lseg %p ref %d valid %d\n", __func__, lseg, | 509 | dprintk("%s: lseg %p ref %d valid %d\n", __func__, lseg, |
510 | atomic_read(&lseg->pls_refcount), | 510 | refcount_read(&lseg->pls_refcount), |
511 | test_bit(NFS_LSEG_VALID, &lseg->pls_flags)); | 511 | test_bit(NFS_LSEG_VALID, &lseg->pls_flags)); |
512 | 512 | ||
513 | lo = lseg->pls_layout; | 513 | lo = lseg->pls_layout; |
514 | inode = lo->plh_inode; | 514 | inode = lo->plh_inode; |
515 | 515 | ||
516 | if (atomic_dec_and_lock(&lseg->pls_refcount, &inode->i_lock)) { | 516 | if (refcount_dec_and_lock(&lseg->pls_refcount, &inode->i_lock)) { |
517 | if (test_bit(NFS_LSEG_VALID, &lseg->pls_flags)) { | 517 | if (test_bit(NFS_LSEG_VALID, &lseg->pls_flags)) { |
518 | spin_unlock(&inode->i_lock); | 518 | spin_unlock(&inode->i_lock); |
519 | return; | 519 | return; |
@@ -551,7 +551,7 @@ pnfs_lseg_range_contained(const struct pnfs_layout_range *l1, | |||
551 | static bool pnfs_lseg_dec_and_remove_zero(struct pnfs_layout_segment *lseg, | 551 | static bool pnfs_lseg_dec_and_remove_zero(struct pnfs_layout_segment *lseg, |
552 | struct list_head *tmp_list) | 552 | struct list_head *tmp_list) |
553 | { | 553 | { |
554 | if (!atomic_dec_and_test(&lseg->pls_refcount)) | 554 | if (!refcount_dec_and_test(&lseg->pls_refcount)) |
555 | return false; | 555 | return false; |
556 | pnfs_layout_remove_lseg(lseg->pls_layout, lseg); | 556 | pnfs_layout_remove_lseg(lseg->pls_layout, lseg); |
557 | list_add(&lseg->pls_list, tmp_list); | 557 | list_add(&lseg->pls_list, tmp_list); |
@@ -570,7 +570,7 @@ static int mark_lseg_invalid(struct pnfs_layout_segment *lseg, | |||
570 | * outstanding io is finished. | 570 | * outstanding io is finished. |
571 | */ | 571 | */ |
572 | dprintk("%s: lseg %p ref %d\n", __func__, lseg, | 572 | dprintk("%s: lseg %p ref %d\n", __func__, lseg, |
573 | atomic_read(&lseg->pls_refcount)); | 573 | refcount_read(&lseg->pls_refcount)); |
574 | if (pnfs_lseg_dec_and_remove_zero(lseg, tmp_list)) | 574 | if (pnfs_lseg_dec_and_remove_zero(lseg, tmp_list)) |
575 | rv = 1; | 575 | rv = 1; |
576 | } | 576 | } |
@@ -1546,7 +1546,7 @@ pnfs_find_lseg(struct pnfs_layout_hdr *lo, | |||
1546 | } | 1546 | } |
1547 | 1547 | ||
1548 | dprintk("%s:Return lseg %p ref %d\n", | 1548 | dprintk("%s:Return lseg %p ref %d\n", |
1549 | __func__, ret, ret ? atomic_read(&ret->pls_refcount) : 0); | 1549 | __func__, ret, ret ? refcount_read(&ret->pls_refcount) : 0); |
1550 | return ret; | 1550 | return ret; |
1551 | } | 1551 | } |
1552 | 1552 | ||