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.reshet...@intel.com> Signed-off-by: Hans Liljestrand <ishkam...@gmail.com> Signed-off-by: Kees Cook <keesc...@chromium.org> Signed-off-by: David Windsor <dwind...@gmail.com> --- fs/btrfs/scrub.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c index c9406bf..8299f64 100644 --- a/fs/btrfs/scrub.c +++ b/fs/btrfs/scrub.c @@ -79,7 +79,7 @@ struct scrub_page { u64 logical; u64 physical; u64 physical_for_dev_replace; - atomic_t refs; + refcount_t refs; struct { unsigned int mirror_num:8; unsigned int have_csum:1; @@ -2017,12 +2017,12 @@ static void scrub_block_put(struct scrub_block *sblock) static void scrub_page_get(struct scrub_page *spage) { - atomic_inc(&spage->refs); + refcount_inc(&spage->refs); } static void scrub_page_put(struct scrub_page *spage) { - if (atomic_dec_and_test(&spage->refs)) { + if (refcount_dec_and_test(&spage->refs)) { if (spage->page) __free_page(spage->page); kfree(spage); -- 2.7.4