From: Elena Reshetova <elena.reshetova@intel.com>
To: netdev@vger.kernel.org
Cc: bridge@lists.linux-foundation.org, linux-kernel@vger.kernel.org,
kuznet@ms2.inr.ac.ru, jmorris@namei.org, kaber@trash.net,
stephen@networkplumber.org, peterz@infradead.org,
keescook@chromium.org,
Elena Reshetova <elena.reshetova@intel.com>,
Hans Liljestrand <ishkamiel@gmail.com>,
David Windsor <dwindsor@gmail.com>
Subject: [PATCH 14/17] net: convert inet_frag_queue.refcnt from atomic_t to refcount_t
Date: Wed, 28 Jun 2017 14:55:03 +0300 [thread overview]
Message-ID: <1498650906-12907-15-git-send-email-elena.reshetova@intel.com> (raw)
In-Reply-To: <1498650906-12907-1-git-send-email-elena.reshetova@intel.com>
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>
---
include/net/inet_frag.h | 4 ++--
net/ipv4/inet_fragment.c | 14 +++++++-------
net/ipv4/ip_fragment.c | 2 +-
3 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/include/net/inet_frag.h b/include/net/inet_frag.h
index 5894730..5a334bf 100644
--- a/include/net/inet_frag.h
+++ b/include/net/inet_frag.h
@@ -50,7 +50,7 @@ struct inet_frag_queue {
spinlock_t lock;
struct timer_list timer;
struct hlist_node list;
- atomic_t refcnt;
+ refcount_t refcnt;
struct sk_buff *fragments;
struct sk_buff *fragments_tail;
ktime_t stamp;
@@ -129,7 +129,7 @@ void inet_frag_maybe_warn_overflow(struct inet_frag_queue *q,
static inline void inet_frag_put(struct inet_frag_queue *q, struct inet_frags *f)
{
- if (atomic_dec_and_test(&q->refcnt))
+ if (refcount_dec_and_test(&q->refcnt))
inet_frag_destroy(q, f);
}
diff --git a/net/ipv4/inet_fragment.c b/net/ipv4/inet_fragment.c
index b5e9317..96e95e8 100644
--- a/net/ipv4/inet_fragment.c
+++ b/net/ipv4/inet_fragment.c
@@ -276,11 +276,11 @@ static inline void fq_unlink(struct inet_frag_queue *fq, struct inet_frags *f)
void inet_frag_kill(struct inet_frag_queue *fq, struct inet_frags *f)
{
if (del_timer(&fq->timer))
- atomic_dec(&fq->refcnt);
+ refcount_dec(&fq->refcnt);
if (!(fq->flags & INET_FRAG_COMPLETE)) {
fq_unlink(fq, f);
- atomic_dec(&fq->refcnt);
+ refcount_dec(&fq->refcnt);
}
}
EXPORT_SYMBOL(inet_frag_kill);
@@ -329,7 +329,7 @@ static struct inet_frag_queue *inet_frag_intern(struct netns_frags *nf,
*/
hlist_for_each_entry(qp, &hb->chain, list) {
if (qp->net == nf && f->match(qp, arg)) {
- atomic_inc(&qp->refcnt);
+ refcount_inc(&qp->refcnt);
spin_unlock(&hb->chain_lock);
qp_in->flags |= INET_FRAG_COMPLETE;
inet_frag_put(qp_in, f);
@@ -339,9 +339,9 @@ static struct inet_frag_queue *inet_frag_intern(struct netns_frags *nf,
#endif
qp = qp_in;
if (!mod_timer(&qp->timer, jiffies + nf->timeout))
- atomic_inc(&qp->refcnt);
+ refcount_inc(&qp->refcnt);
- atomic_inc(&qp->refcnt);
+ refcount_inc(&qp->refcnt);
hlist_add_head(&qp->list, &hb->chain);
spin_unlock(&hb->chain_lock);
@@ -370,7 +370,7 @@ static struct inet_frag_queue *inet_frag_alloc(struct netns_frags *nf,
setup_timer(&q->timer, f->frag_expire, (unsigned long)q);
spin_lock_init(&q->lock);
- atomic_set(&q->refcnt, 1);
+ refcount_set(&q->refcnt, 1);
return q;
}
@@ -405,7 +405,7 @@ struct inet_frag_queue *inet_frag_find(struct netns_frags *nf,
spin_lock(&hb->chain_lock);
hlist_for_each_entry(q, &hb->chain, list) {
if (q->net == nf && f->match(q, key)) {
- atomic_inc(&q->refcnt);
+ refcount_inc(&q->refcnt);
spin_unlock(&hb->chain_lock);
return q;
}
diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
index b3cdeec..9a8cfac 100644
--- a/net/ipv4/ip_fragment.c
+++ b/net/ipv4/ip_fragment.c
@@ -312,7 +312,7 @@ static int ip_frag_reinit(struct ipq *qp)
unsigned int sum_truesize = 0;
if (!mod_timer(&qp->q.timer, jiffies + qp->q.net->timeout)) {
- atomic_inc(&qp->q.refcnt);
+ refcount_inc(&qp->q.refcnt);
return -ETIMEDOUT;
}
--
2.7.4
next prev parent reply other threads:[~2017-06-28 11:55 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-28 11:54 [PATCH 00/17] v2 net generic subsystem refcount conversions Elena Reshetova
2017-06-28 11:54 ` [PATCH 01/17] net: convert inet_peer.refcnt from atomic_t to refcount_t Elena Reshetova
2017-06-28 11:54 ` [PATCH 02/17] net: convert neighbour.refcnt " Elena Reshetova
2017-06-28 11:54 ` [PATCH 03/17] net: convert neigh_params.refcnt " Elena Reshetova
2017-06-28 11:54 ` [PATCH 04/17] net: convert nf_bridge_info.use " Elena Reshetova
2017-06-28 11:54 ` [PATCH 05/17] net: convert sk_buff.users " Elena Reshetova
2017-06-28 11:54 ` [PATCH 06/17] net: convert sk_buff_fclones.fclone_ref " Elena Reshetova
2017-06-28 11:54 ` [PATCH 07/17] net: convert sock.sk_wmem_alloc " Elena Reshetova
2017-06-28 11:54 ` [PATCH 08/17] net: convert sock.sk_refcnt " Elena Reshetova
2017-06-28 11:54 ` [PATCH 09/17] net: convert ip_mc_list.refcnt " Elena Reshetova
2017-06-28 11:54 ` [PATCH 10/17] net: convert in_device.refcnt " Elena Reshetova
2017-06-28 11:55 ` [PATCH 11/17] net: convert netpoll_info.refcnt " Elena Reshetova
2017-06-28 11:55 ` [PATCH 12/17] net: convert unix_address.refcnt " Elena Reshetova
2017-06-28 11:55 ` [PATCH 13/17] net: convert fib_rule.refcnt " Elena Reshetova
2017-06-28 11:55 ` Elena Reshetova [this message]
2017-06-28 11:55 ` [PATCH 15/17] net: convert net.passive " Elena Reshetova
2017-06-28 11:55 ` [PATCH 16/17] net: convert netlbl_lsm_cache.refcount " Elena Reshetova
2017-06-28 11:55 ` [PATCH 17/17] net: convert packet_fanout.sk_ref " Elena Reshetova
2017-06-29 18:26 ` [PATCH 00/17] v2 net generic subsystem refcount conversions David Miller
2017-06-30 7:06 ` Reshetova, Elena
-- strict thread matches above, loose matches on Subject: below --
2017-06-30 10:07 [PATCH 00/17] v3 " Elena Reshetova
2017-06-30 10:08 ` [PATCH 14/17] net: convert inet_frag_queue.refcnt from atomic_t to refcount_t Elena Reshetova
2017-03-16 15:28 [PATCH 00/17] net subsystem refcount conversions Elena Reshetova
2017-03-16 15:29 ` [PATCH 14/17] net: convert inet_frag_queue.refcnt from atomic_t to refcount_t Elena Reshetova
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1498650906-12907-15-git-send-email-elena.reshetova@intel.com \
--to=elena.reshetova@intel.com \
--cc=bridge@lists.linux-foundation.org \
--cc=dwindsor@gmail.com \
--cc=ishkamiel@gmail.com \
--cc=jmorris@namei.org \
--cc=kaber@trash.net \
--cc=keescook@chromium.org \
--cc=kuznet@ms2.inr.ac.ru \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).