Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1603264
| From | Elena Reshetova <elena.reshetova@intel.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH 09/23] net, rds: convert rds_mr.r_refcount from atomic_t to refcount_t |
| Date | 2017-03-17 13:30 +0100 |
| Message-ID | <tlZb4-6ms-13@gated-at.bofh.it> (permalink) |
| References | <tlZ1n-6iZ-3@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
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>
---
net/rds/rdma.c | 10 +++++-----
net/rds/rds.h | 4 ++--
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/net/rds/rdma.c b/net/rds/rdma.c
index f06fac4..8886f15 100644
--- a/net/rds/rdma.c
+++ b/net/rds/rdma.c
@@ -84,7 +84,7 @@ static struct rds_mr *rds_mr_tree_walk(struct rb_root *root, u64 key,
if (insert) {
rb_link_node(&insert->r_rb_node, parent, p);
rb_insert_color(&insert->r_rb_node, root);
- atomic_inc(&insert->r_refcount);
+ refcount_inc(&insert->r_refcount);
}
return NULL;
}
@@ -99,7 +99,7 @@ static void rds_destroy_mr(struct rds_mr *mr)
unsigned long flags;
rdsdebug("RDS: destroy mr key is %x refcnt %u\n",
- mr->r_key, atomic_read(&mr->r_refcount));
+ mr->r_key, refcount_read(&mr->r_refcount));
if (test_and_set_bit(RDS_MR_DEAD, &mr->r_state))
return;
@@ -223,7 +223,7 @@ static int __rds_rdma_map(struct rds_sock *rs, struct rds_get_mr_args *args,
goto out;
}
- atomic_set(&mr->r_refcount, 1);
+ refcount_set(&mr->r_refcount, 1);
RB_CLEAR_NODE(&mr->r_rb_node);
mr->r_trans = rs->rs_transport;
mr->r_sock = rs;
@@ -307,7 +307,7 @@ static int __rds_rdma_map(struct rds_sock *rs, struct rds_get_mr_args *args,
rdsdebug("RDS: get_mr key is %x\n", mr->r_key);
if (mr_ret) {
- atomic_inc(&mr->r_refcount);
+ refcount_inc(&mr->r_refcount);
*mr_ret = mr;
}
@@ -756,7 +756,7 @@ int rds_cmsg_rdma_dest(struct rds_sock *rs, struct rds_message *rm,
if (!mr)
err = -EINVAL; /* invalid r_key */
else
- atomic_inc(&mr->r_refcount);
+ refcount_inc(&mr->r_refcount);
spin_unlock_irqrestore(&rs->rs_rdma_lock, flags);
if (mr) {
diff --git a/net/rds/rds.h b/net/rds/rds.h
index d8070c7..7487597 100644
--- a/net/rds/rds.h
+++ b/net/rds/rds.h
@@ -276,7 +276,7 @@ struct rds_incoming {
struct rds_mr {
struct rb_node r_rb_node;
- atomic_t r_refcount;
+ refcount_t r_refcount;
u32 r_key;
/* A copy of the creation flags */
@@ -855,7 +855,7 @@ int rds_cmsg_atomic(struct rds_sock *rs, struct rds_message *rm,
void __rds_put_mr_final(struct rds_mr *mr);
static inline void rds_mr_put(struct rds_mr *mr)
{
- if (atomic_dec_and_test(&mr->r_refcount))
+ if (refcount_dec_and_test(&mr->r_refcount))
__rds_put_mr_final(mr);
}
--
2.7.4
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 00/23] various networking refcount conversions, part 2 Elena Reshetova <elena.reshetova@intel.com> - 2017-03-17 13:20 +0100
[PATCH 16/23] net, sctp: convert sctp_auth_bytes.refcnt from atomic_t to refcount_t Elena Reshetova <elena.reshetova@intel.com> - 2017-03-17 13:20 +0100
[PATCH 07/23] net, rds: convert rds_ib_device.refcount from atomic_t to refcount_t Elena Reshetova <elena.reshetova@intel.com> - 2017-03-17 13:20 +0100
[PATCH 14/23] net, xfrm: convert xfrm_policy.refcnt from atomic_t to refcount_t Elena Reshetova <elena.reshetova@intel.com> - 2017-03-17 13:20 +0100
[PATCH 02/23] net, sunrpc: convert gss_cl_ctx.count from atomic_t to refcount_t Elena Reshetova <elena.reshetova@intel.com> - 2017-03-17 13:20 +0100
[PATCH 06/23] net, ceph: convert ceph_pagelist.refcnt from atomic_t to refcount_t Elena Reshetova <elena.reshetova@intel.com> - 2017-03-17 13:20 +0100
Re: [PATCH 06/23] net, ceph: convert ceph_pagelist.refcnt from atomic_t to refcount_t Ilya Dryomov <idryomov@gmail.com> - 2017-03-24 15:00 +0100
[PATCH 08/23] net, rds: convert rds_incoming.i_refcount from atomic_t to refcount_t Elena Reshetova <elena.reshetova@intel.com> - 2017-03-17 13:20 +0100
[PATCH 05/23] net, ceph: convert ceph_osd.o_ref from atomic_t to refcount_t Elena Reshetova <elena.reshetova@intel.com> - 2017-03-17 13:20 +0100
Re: [PATCH 05/23] net, ceph: convert ceph_osd.o_ref from atomic_t to refcount_t Ilya Dryomov <idryomov@gmail.com> - 2017-03-24 15:00 +0100
[PATCH 21/23] net, ax25: convert ax25_uid_assoc.refcount from atomic_t to refcount_t Elena Reshetova <elena.reshetova@intel.com> - 2017-03-17 13:30 +0100
[PATCH 15/23] net, xfrm: convert sec_path.refcnt from atomic_t to refcount_t Elena Reshetova <elena.reshetova@intel.com> - 2017-03-17 13:30 +0100
[PATCH 23/23] net, ax25: convert ax25_cb.refcount from atomic_t to refcount_t Elena Reshetova <elena.reshetova@intel.com> - 2017-03-17 13:30 +0100
[PATCH 10/23] net, rds: convert rds_message.m_refcount from atomic_t to refcount_t Elena Reshetova <elena.reshetova@intel.com> - 2017-03-17 13:30 +0100
[PATCH 09/23] net, rds: convert rds_mr.r_refcount from atomic_t to refcount_t Elena Reshetova <elena.reshetova@intel.com> - 2017-03-17 13:30 +0100
[PATCH 12/23] net, x25: convert x25_neigh.refcnt from atomic_t to refcount_t Elena Reshetova <elena.reshetova@intel.com> - 2017-03-17 13:30 +0100
[PATCH 19/23] net, sctp: convert sctp_transport.refcnt from atomic_t to refcount_t Elena Reshetova <elena.reshetova@intel.com> - 2017-03-17 13:30 +0100
[PATCH 11/23] net, x25: convert x25_route.refcnt from atomic_t to refcount_t Elena Reshetova <elena.reshetova@intel.com> - 2017-03-17 13:30 +0100
[PATCH 13/23] net, xfrm: convert xfrm_state.refcnt from atomic_t to refcount_t Elena Reshetova <elena.reshetova@intel.com> - 2017-03-17 13:30 +0100
[PATCH 18/23] net, sctp: convert sctp_chunk.refcnt from atomic_t to refcount_t Elena Reshetova <elena.reshetova@intel.com> - 2017-03-17 13:30 +0100
csiph-web