linux-ppp.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Elena Reshetova <elena.reshetova@intel.com>
To: netdev@vger.kernel.org
Cc: peterz@infradead.org, matanb@mellanox.com, paulus@samba.org,
	Elena Reshetova <elena.reshetova@intel.com>,
	nbd@openwrt.org, linux-rdma@vger.kernel.org, saeedm@mellanox.com,
	ganeshgr@chelsio.com, Hans Liljestrand <ishkamiel@gmail.com>,
	David Windsor <dwindsor@gmail.com>,
	keescook@chromium.org, j@w1.fi, ajk@comnets.uni-bremen.de,
	leonro@mellanox.com, matthias.bgg@gmail.com,
	linux-hams@vger.kernel.org, kvalo@codeaurora.org,
	blogic@openwrt.org, linux-arm-kernel@lists.infradead.org,
	linux-ppp@vger.kernel.org, yishaih@mellanox.com,
	linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org,
	gregkh@linuxfoundation.org
Subject: [PATCH 01/16] drivers, net, ethernet: convert clip_entry.refcnt from atomic_t to refcount_t
Date: Tue, 28 Mar 2017 08:56:28 +0000	[thread overview]
Message-ID: <1490691403-4016-2-git-send-email-elena.reshetova@intel.com> (raw)
In-Reply-To: <1490691403-4016-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>
---
 drivers/net/ethernet/chelsio/cxgb4/clip_tbl.c | 13 ++++++-------
 drivers/net/ethernet/chelsio/cxgb4/clip_tbl.h |  4 +++-
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/chelsio/cxgb4/clip_tbl.c b/drivers/net/ethernet/chelsio/cxgb4/clip_tbl.c
index 3103ef9..2900390 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/clip_tbl.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/clip_tbl.c
@@ -96,7 +96,8 @@ int cxgb4_clip_get(const struct net_device *dev, const u32 *lip, u8 v6)
 		if (!ret) {
 			ce = cte;
 			read_unlock_bh(&ctbl->lock);
-			goto found;
+			refcount_inc(&ce->refcnt);
+			return 0;
 		}
 	}
 	read_unlock_bh(&ctbl->lock);
@@ -108,7 +109,7 @@ int cxgb4_clip_get(const struct net_device *dev, const u32 *lip, u8 v6)
 		list_del(&ce->list);
 		INIT_LIST_HEAD(&ce->list);
 		spin_lock_init(&ce->lock);
-		atomic_set(&ce->refcnt, 0);
+		refcount_set(&ce->refcnt, 0);
 		atomic_dec(&ctbl->nfree);
 		list_add_tail(&ce->list, &ctbl->hash_list[hash]);
 		if (v6) {
@@ -138,9 +139,7 @@ int cxgb4_clip_get(const struct net_device *dev, const u32 *lip, u8 v6)
 		return -ENOMEM;
 	}
 	write_unlock_bh(&ctbl->lock);
-found:
-	atomic_inc(&ce->refcnt);
-
+	refcount_set(&ce->refcnt, 1);
 	return 0;
 }
 EXPORT_SYMBOL(cxgb4_clip_get);
@@ -179,7 +178,7 @@ void cxgb4_clip_release(const struct net_device *dev, const u32 *lip, u8 v6)
 found:
 	write_lock_bh(&ctbl->lock);
 	spin_lock_bh(&ce->lock);
-	if (atomic_dec_and_test(&ce->refcnt)) {
+	if (refcount_dec_and_test(&ce->refcnt)) {
 		list_del(&ce->list);
 		INIT_LIST_HEAD(&ce->list);
 		list_add_tail(&ce->list, &ctbl->ce_free_head);
@@ -266,7 +265,7 @@ int clip_tbl_show(struct seq_file *seq, void *v)
 			ip[0] = '\0';
 			sprintf(ip, "%pISc", &ce->addr);
 			seq_printf(seq, "%-25s   %u\n", ip,
-				   atomic_read(&ce->refcnt));
+				   refcount_read(&ce->refcnt));
 		}
 	}
 	seq_printf(seq, "Free clip entries : %d\n", atomic_read(&ctbl->nfree));
diff --git a/drivers/net/ethernet/chelsio/cxgb4/clip_tbl.h b/drivers/net/ethernet/chelsio/cxgb4/clip_tbl.h
index 35eb43c..a0e0ae1 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/clip_tbl.h
+++ b/drivers/net/ethernet/chelsio/cxgb4/clip_tbl.h
@@ -10,9 +10,11 @@
  *  release for licensing terms and conditions.
  */
 
+#include <linux/refcount.h>
+
 struct clip_entry {
 	spinlock_t lock;	/* Hold while modifying clip reference */
-	atomic_t refcnt;
+	refcount_t refcnt;
 	struct list_head list;
 	union {
 		struct sockaddr_in addr;
-- 
2.7.4


  reply	other threads:[~2017-03-28  8:56 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-28  8:56 [PATCH 00/16] Networking drivers refcount conversions Elena Reshetova
2017-03-28  8:56 ` Elena Reshetova [this message]
2017-03-28  8:56 ` [PATCH 02/16] drivers, net, ethernet: convert mtk_eth.dma_refcnt from atomic_t to refcount_t Elena Reshetova
2017-03-28  8:56 ` [PATCH 03/16] drivers, net, mlx4: convert mlx4_cq.refcount " Elena Reshetova
2017-03-28  8:56 ` [PATCH 04/16] drivers, net, mlx4: convert mlx4_qp.refcount " Elena Reshetova
2017-03-28  8:56 ` [PATCH 05/16] drivers, net, mlx4: convert mlx4_srq.refcount " Elena Reshetova
2017-03-28  8:56 ` [PATCH 06/16] drivers, net, mlx5: convert mlx5_cq.refcount " Elena Reshetova
2017-03-28  9:33   ` David Laight
2017-03-28 14:00     ` Reshetova, Elena
     [not found] ` <1490691403-4016-1-git-send-email-elena.reshetova-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2017-03-28  8:56   ` [PATCH 07/16] drivers, net, mlx5: convert fs_node.refcount " Elena Reshetova
2017-03-28  8:56 ` [PATCH 08/16] drivers, net, hamradio: convert sixpack.refcnt " Elena Reshetova
2017-03-28  8:56 ` [PATCH 09/16] drivers, net: convert masces_rx_sa.refcnt " Elena Reshetova
2017-03-28  8:56 ` [PATCH 10/16] drivers, net: convert masces_rx_sc.refcnt " Elena Reshetova
2017-03-28  8:56 ` [PATCH 11/16] drivers, net: convert masces_tx_sa.refcnt " Elena Reshetova
2017-03-28  8:56 ` [PATCH 12/16] drivers, net, ppp: convert asyncppp.refcnt " Elena Reshetova
2017-03-28  8:56 ` [PATCH 13/16] drivers, net, ppp: convert ppp_file.refcnt " Elena Reshetova
2017-03-28  8:56 ` [PATCH 14/16] drivers, net, ppp: convert syncppp.refcnt " Elena Reshetova
2017-03-28  8:56 ` [PATCH 15/16] drivers, net, intersil: convert hostap_cmd_queue.usecnt " Elena Reshetova
     [not found]   ` <1490691403-4016-16-git-send-email-elena.reshetova-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2017-04-03 11:38     ` [PATCH 15/16] drivers, net, intersil: convert hostap_cmd_queue.usecnt from atomic_t to refcount_ Kalle Valo
2017-05-22 15:24     ` [15/16] hostap: convert hostap_cmd_queue.usecnt from atomic_t to refcount_t Kalle Valo
2017-03-28  8:56 ` [PATCH 16/16] drivers, net, intersil: convert request_context.refcount " Elena Reshetova
2017-04-03 11:41   ` [PATCH 16/16] drivers, net, intersil: convert request_context.refcount from atomic_t to refcount Kalle Valo
2017-04-04 10:07     ` Reshetova, Elena
2017-04-05 10:33       ` Kalle Valo

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=1490691403-4016-2-git-send-email-elena.reshetova@intel.com \
    --to=elena.reshetova@intel.com \
    --cc=ajk@comnets.uni-bremen.de \
    --cc=blogic@openwrt.org \
    --cc=dwindsor@gmail.com \
    --cc=ganeshgr@chelsio.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=ishkamiel@gmail.com \
    --cc=j@w1.fi \
    --cc=keescook@chromium.org \
    --cc=kvalo@codeaurora.org \
    --cc=leonro@mellanox.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-hams@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-ppp@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=matanb@mellanox.com \
    --cc=matthias.bgg@gmail.com \
    --cc=nbd@openwrt.org \
    --cc=netdev@vger.kernel.org \
    --cc=paulus@samba.org \
    --cc=peterz@infradead.org \
    --cc=saeedm@mellanox.com \
    --cc=yishaih@mellanox.com \
    /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).