Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1591818

[PATCH 13/17] fs, btrfs: convert scrub_page.refs from atomic_t to refcount_t

From Elena Reshetova <elena.reshetova@intel.com>
Newsgroups linux.kernel
Subject [PATCH 13/17] fs, btrfs: convert scrub_page.refs from atomic_t to refcount_t
Date 2017-03-03 11:00 +0100
Message-ID <tgSaf-7JR-33@gated-at.bofh.it> (permalink)
References <tgRea-75L-23@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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>
---
 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

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 00/17] fs, btrfs refcount conversions Elena Reshetova <elena.reshetova@intel.com> - 2017-03-03 10:00 +0100
  [PATCH 15/17] fs, btrfs: convert scrub_parity.refs from atomic_t to refcount_t Elena Reshetova <elena.reshetova@intel.com> - 2017-03-03 10:10 +0100
  [PATCH 16/17] fs, btrfs: convert scrub_ctx.refs from atomic_t to refcount_t Elena Reshetova <elena.reshetova@intel.com> - 2017-03-03 10:10 +0100
  [PATCH 10/17] fs, btrfs: convert extent_state.refs from atomic_t to refcount_t Elena Reshetova <elena.reshetova@intel.com> - 2017-03-03 10:10 +0100
  [PATCH 05/17] fs, btrfs: convert btrfs_caching_control.count from atomic_t to refcount_t Elena Reshetova <elena.reshetova@intel.com> - 2017-03-03 10:10 +0100
  [PATCH 03/17] fs, btrfs: convert extent_map.refs from atomic_t to refcount_t Elena Reshetova <elena.reshetova@intel.com> - 2017-03-03 10:10 +0100
  [PATCH 04/17] fs, btrfs: convert btrfs_ordered_extent.refs from atomic_t to refcount_t Elena Reshetova <elena.reshetova@intel.com> - 2017-03-03 10:10 +0100
  [PATCH 09/17] fs, btrfs: convert btrfs_root.refs from atomic_t to refcount_t Elena Reshetova <elena.reshetova@intel.com> - 2017-03-03 10:10 +0100
  [PATCH 17/17] fs, btrfs: convert btrfs_raid_bio.refs from atomic_t to refcount_t Elena Reshetova <elena.reshetova@intel.com> - 2017-03-03 10:10 +0100
  [PATCH 08/17] fs, btrfs: convert btrfs_delayed_item.refs from atomic_t to refcount_t Elena Reshetova <elena.reshetova@intel.com> - 2017-03-03 10:30 +0100
  [PATCH 14/17] fs, btrfs: convert scrub_block.refs from atomic_t to refcount_t Elena Reshetova <elena.reshetova@intel.com> - 2017-03-03 11:00 +0100
  [PATCH 13/17] fs, btrfs: convert scrub_page.refs from atomic_t to refcount_t Elena Reshetova <elena.reshetova@intel.com> - 2017-03-03 11:00 +0100
  [PATCH 11/17] fs, btrfs: convert compressed_bio.pending_bios from atomic_t to refcount_t Elena Reshetova <elena.reshetova@intel.com> - 2017-03-03 11:40 +0100
  [PATCH 06/17] fs, btrfs: convert btrfs_delayed_ref_node.refs from atomic_t to refcount_t Elena Reshetova <elena.reshetova@intel.com> - 2017-03-03 13:40 +0100
  [PATCH 12/17] fs, btrfs: convert scrub_recover.refs from atomic_t to refcount_t Elena Reshetova <elena.reshetova@intel.com> - 2017-03-03 14:00 +0100
  [PATCH 07/17] fs, btrfs: convert btrfs_delayed_node.refs from atomic_t to refcount_t Elena Reshetova <elena.reshetova@intel.com> - 2017-03-03 16:40 +0100
  Re: [PATCH 00/17] fs, btrfs refcount conversions Qu Wenruo <quwenruo@cn.fujitsu.com> - 2017-03-06 01:30 +0100
  Re: [PATCH 00/17] fs, btrfs refcount conversions Qu Wenruo <quwenruo@cn.fujitsu.com> - 2017-03-06 05:10 +0100
    Re: [PATCH 00/17] fs, btrfs refcount conversions Qu Wenruo <quwenruo@cn.fujitsu.com> - 2017-03-07 07:30 +0100
      RE: [PATCH 00/17] fs, btrfs refcount conversions "Reshetova, Elena" <elena.reshetova@intel.com> - 2017-03-07 09:00 +0100
        Re: [PATCH 00/17] fs, btrfs refcount conversions David Sterba <dsterba@suse.cz> - 2017-03-09 16:40 +0100
  Re: [PATCH 00/17] fs, btrfs refcount conversions David Sterba <dsterba@suse.cz> - 2017-03-09 17:30 +0100
    RE: [PATCH 00/17] fs, btrfs refcount conversions "Reshetova, Elena" <elena.reshetova@intel.com> - 2017-03-13 12:00 +0100

csiph-web