Commit 6f615018 authored by Elena Reshetova's avatar Elena Reshetova Committed by David Sterba

btrfs: convert scrub_recover.refs 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: default avatarElena Reshetova <elena.reshetova@intel.com>
Signed-off-by: default avatarHans Liljestrand <ishkamiel@gmail.com>
Signed-off-by: default avatarKees Cook <keescook@chromium.org>
Signed-off-by: default avatarDavid Windsor <dwindsor@gmail.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent a50299ae
...@@ -64,7 +64,7 @@ struct scrub_ctx; ...@@ -64,7 +64,7 @@ struct scrub_ctx;
#define SCRUB_MAX_PAGES_PER_BLOCK 16 /* 64k per node/leaf/sector */ #define SCRUB_MAX_PAGES_PER_BLOCK 16 /* 64k per node/leaf/sector */
struct scrub_recover { struct scrub_recover {
atomic_t refs; refcount_t refs;
struct btrfs_bio *bbio; struct btrfs_bio *bbio;
u64 map_length; u64 map_length;
}; };
...@@ -857,12 +857,12 @@ static void scrub_fixup_nodatasum(struct btrfs_work *work) ...@@ -857,12 +857,12 @@ static void scrub_fixup_nodatasum(struct btrfs_work *work)
static inline void scrub_get_recover(struct scrub_recover *recover) static inline void scrub_get_recover(struct scrub_recover *recover)
{ {
atomic_inc(&recover->refs); refcount_inc(&recover->refs);
} }
static inline void scrub_put_recover(struct scrub_recover *recover) static inline void scrub_put_recover(struct scrub_recover *recover)
{ {
if (atomic_dec_and_test(&recover->refs)) { if (refcount_dec_and_test(&recover->refs)) {
btrfs_put_bbio(recover->bbio); btrfs_put_bbio(recover->bbio);
kfree(recover); kfree(recover);
} }
...@@ -1343,7 +1343,7 @@ static int scrub_setup_recheck_block(struct scrub_block *original_sblock, ...@@ -1343,7 +1343,7 @@ static int scrub_setup_recheck_block(struct scrub_block *original_sblock,
return -ENOMEM; return -ENOMEM;
} }
atomic_set(&recover->refs, 1); refcount_set(&recover->refs, 1);
recover->bbio = bbio; recover->bbio = bbio;
recover->map_length = mapped_length; recover->map_length = mapped_length;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment