From: Elena Reshetova <elena.reshetova@intel.com> Date: 2017-03-28 09:00:40
This series, for various different networking drivers, replaces atomic_t reference
counters with the new refcount_t type and API (see include/linux/refcount.h).
By doing this we prevent intentional or accidental
underflows or overflows that can led to use-after-free vulnerabilities.
The below patches are fully independent and can be cherry-picked separately.
Since we convert all kernel subsystems in the same fashion, resulting
in about 300 patches, we have to group them for sending at least in some
fashion to be manageable. Please excuse the long cc list.
If there are no objections to these patches, please take them
through the relevant trees.
Elena Reshetova (16):
drivers, net, ethernet: convert clip_entry.refcnt from atomic_t to
refcount_t
drivers, net, ethernet: convert mtk_eth.dma_refcnt from atomic_t to
refcount_t
drivers, net, mlx4: convert mlx4_cq.refcount from atomic_t to
refcount_t
drivers, net, mlx4: convert mlx4_qp.refcount from atomic_t to
refcount_t
drivers, net, mlx4: convert mlx4_srq.refcount from atomic_t to
refcount_t
drivers, net, mlx5: convert mlx5_cq.refcount from atomic_t to
refcount_t
drivers, net, mlx5: convert fs_node.refcount from atomic_t to
refcount_t
drivers, net, hamradio: convert sixpack.refcnt from atomic_t to
refcount_t
drivers, net: convert masces_rx_sa.refcnt from atomic_t to refcount_t
drivers, net: convert masces_rx_sc.refcnt from atomic_t to refcount_t
drivers, net: convert masces_tx_sa.refcnt from atomic_t to refcount_t
drivers, net, ppp: convert asyncppp.refcnt from atomic_t to refcount_t
drivers, net, ppp: convert ppp_file.refcnt from atomic_t to refcount_t
drivers, net, ppp: convert syncppp.refcnt from atomic_t to refcount_t
drivers, net, intersil: convert hostap_cmd_queue.usecnt from atomic_t
to refcount_t
drivers, net, intersil: convert request_context.refcount from atomic_t
to refcount_t
drivers/net/ethernet/chelsio/cxgb4/clip_tbl.c | 13 ++++++-----
drivers/net/ethernet/chelsio/cxgb4/clip_tbl.h | 4 +++-
drivers/net/ethernet/mediatek/mtk_eth_soc.c | 8 ++++---
drivers/net/ethernet/mediatek/mtk_eth_soc.h | 4 +++-
drivers/net/ethernet/mellanox/mlx4/cq.c | 8 +++----
drivers/net/ethernet/mellanox/mlx4/qp.c | 8 +++----
drivers/net/ethernet/mellanox/mlx4/srq.c | 8 +++----
drivers/net/ethernet/mellanox/mlx5/core/cq.c | 16 +++++++-------
drivers/net/ethernet/mellanox/mlx5/core/fs_core.c | 24 ++++++++++-----------
drivers/net/ethernet/mellanox/mlx5/core/fs_core.h | 3 ++-
drivers/net/hamradio/6pack.c | 12 +++++------
drivers/net/macsec.c | 25 +++++++++++-----------
drivers/net/ppp/ppp_async.c | 10 ++++-----
drivers/net/ppp/ppp_generic.c | 17 ++++++++-------
drivers/net/ppp/ppp_synctty.c | 11 +++++-----
drivers/net/wireless/intersil/hostap/hostap_hw.c | 12 +++++------
drivers/net/wireless/intersil/hostap/hostap_wlan.h | 3 ++-
.../net/wireless/intersil/orinoco/orinoco_usb.c | 15 +++++++------
include/linux/mlx4/device.h | 8 +++----
include/linux/mlx5/cq.h | 4 ++--
20 files changed, 112 insertions(+), 101 deletions(-)
--
2.7.4
From: Elena Reshetova <elena.reshetova@intel.com> Date: 2017-03-28 08:58:32
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 <redacted>
Signed-off-by: Kees Cook <redacted>
Signed-off-by: David Windsor <redacted>
---
drivers/net/hamradio/6pack.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
@@ -580,7 +580,7 @@ static int sixpack_open(struct tty_struct *tty)sp->dev=dev;spin_lock_init(&sp->lock);-atomic_set(&sp->refcnt,1);+refcount_set(&sp->refcnt,1);sema_init(&sp->dead_sem,0);/* !!! length of the buffers. MTU is IP MTU, not PACLEN! */
@@ -676,7 +676,7 @@ static void sixpack_close(struct tty_struct *tty)*Wehavenowensuredthatnobodycanstartusingapfromnowon,but*wehavetowaitforallexistinguserstofinish.*/-if(!atomic_dec_and_test(&sp->refcnt))+if(!refcount_dec_and_test(&sp->refcnt))down(&sp->dead_sem);/* We must stop the queue to avoid potentially scribbling
From: Elena Reshetova <elena.reshetova@intel.com> Date: 2017-03-28 08:58:35
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 <redacted>
Signed-off-by: Kees Cook <redacted>
Signed-off-by: David Windsor <redacted>
---
drivers/net/macsec.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
From: Elena Reshetova <elena.reshetova@intel.com> Date: 2017-03-28 08:58:39
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 <redacted>
Signed-off-by: Kees Cook <redacted>
Signed-off-by: David Windsor <redacted>
---
drivers/net/macsec.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
From: Elena Reshetova <elena.reshetova@intel.com> Date: 2017-03-28 08:58:40
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 <redacted>
Signed-off-by: Hans Liljestrand <redacted>
Signed-off-by: Kees Cook <redacted>
Signed-off-by: David Windsor <redacted>
---
drivers/net/ethernet/mellanox/mlx5/core/fs_core.c | 24 +++++++++++------------
drivers/net/ethernet/mellanox/mlx5/core/fs_core.h | 3 ++-
2 files changed, 14 insertions(+), 13 deletions(-)
@@ -80,7 +81,7 @@ struct fs_node {structfs_node*root;/* lock the node for writing and traversing */structmutexlock;-atomic_trefcount;+refcount_trefcount;void(*remove_func)(structfs_node*);};
--
2.7.4
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
From: Elena Reshetova <elena.reshetova@intel.com> Date: 2017-03-28 08:58:41
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 <redacted>
Signed-off-by: Kees Cook <redacted>
Signed-off-by: David Windsor <redacted>
---
drivers/net/ethernet/mellanox/mlx4/srq.c | 8 ++++----
include/linux/mlx4/device.h | 2 +-
2 files changed, 5 insertions(+), 5 deletions(-)
From: Elena Reshetova <elena.reshetova@intel.com> Date: 2017-03-28 08:58:43
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 <redacted>
Signed-off-by: Kees Cook <redacted>
Signed-off-by: David Windsor <redacted>
---
drivers/net/macsec.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
From: Elena Reshetova <elena.reshetova@intel.com> Date: 2017-03-28 08:58:44
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 <redacted>
Signed-off-by: Kees Cook <redacted>
Signed-off-by: David Windsor <redacted>
---
drivers/net/ppp/ppp_async.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
From: Elena Reshetova <elena.reshetova@intel.com> Date: 2017-03-28 08:58:45
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 <redacted>
Signed-off-by: Kees Cook <redacted>
Signed-off-by: David Windsor <redacted>
---
drivers/net/ethernet/mellanox/mlx5/core/cq.c | 16 ++++++++--------
include/linux/mlx5/cq.h | 4 ++--
2 files changed, 10 insertions(+), 10 deletions(-)
From: Elena Reshetova <elena.reshetova@intel.com> Date: 2017-03-28 08:58:54
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 <redacted>
Signed-off-by: Kees Cook <redacted>
Signed-off-by: David Windsor <redacted>
---
drivers/net/wireless/intersil/hostap/hostap_hw.c | 12 ++++++------
drivers/net/wireless/intersil/hostap/hostap_wlan.h | 3 ++-
2 files changed, 8 insertions(+), 7 deletions(-)
From: Elena Reshetova <elena.reshetova@intel.com> Date: 2017-03-28 09:00:44
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 <redacted>
Signed-off-by: Kees Cook <redacted>
Signed-off-by: David Windsor <redacted>
---
drivers/net/ethernet/mediatek/mtk_eth_soc.c | 8 +++++---
drivers/net/ethernet/mediatek/mtk_eth_soc.h | 4 +++-
2 files changed, 8 insertions(+), 4 deletions(-)
@@ -1725,7 +1725,7 @@ static int mtk_open(struct net_device *dev)structmtk_eth*eth=mac->hw;/* we run 2 netdevs on the same dma ring so we only bring it up once */-if(!atomic_read(ð->dma_refcnt)){+if(!refcount_read(ð->dma_refcnt)){interr=mtk_start_dma(eth);if(err)
@@ -1735,8 +1735,10 @@ static int mtk_open(struct net_device *dev)napi_enable(ð->rx_napi);mtk_irq_enable(eth,MTK_QDMA_INT_MASK,MTK_TX_DONE_INT);mtk_irq_enable(eth,MTK_PDMA_INT_MASK,MTK_RX_DONE_INT);+refcount_set(ð->dma_refcnt,1);}-atomic_inc(ð->dma_refcnt);+else+refcount_inc(ð->dma_refcnt);phy_start(dev->phydev);netif_start_queue(dev);
@@ -1776,7 +1778,7 @@ static int mtk_stop(struct net_device *dev)phy_stop(dev->phydev);/* only shutdown DMA if this is the last user */-if(!atomic_dec_and_test(ð->dma_refcnt))+if(!refcount_dec_and_test(ð->dma_refcnt))return0;mtk_irq_disable(eth,MTK_QDMA_INT_MASK,MTK_TX_DONE_INT);
From: Elena Reshetova <elena.reshetova@intel.com> Date: 2017-03-28 09:00:59
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 <redacted>
Signed-off-by: Kees Cook <redacted>
Signed-off-by: David Windsor <redacted>
---
drivers/net/ethernet/mellanox/mlx4/qp.c | 8 ++++----
include/linux/mlx4/device.h | 2 +-
2 files changed, 5 insertions(+), 5 deletions(-)
From: Elena Reshetova <elena.reshetova@intel.com> Date: 2017-03-28 09:01:36
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 <redacted>
Signed-off-by: Kees Cook <redacted>
Signed-off-by: David Windsor <redacted>
---
drivers/net/wireless/intersil/orinoco/orinoco_usb.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
@@ -268,7 +269,7 @@ enum ezusb_state {structrequest_context{structlist_headlist;-atomic_trefcount;+refcount_trefcount;structcompletiondone;/* Signals that CTX is dead */intkilled;structurb*outurb;/* OUT for req pkt */
From: Elena Reshetova <elena.reshetova@intel.com> Date: 2017-03-28 09:02:46
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 <redacted>
Signed-off-by: Kees Cook <redacted>
Signed-off-by: David Windsor <redacted>
---
drivers/net/ethernet/mellanox/mlx4/cq.c | 8 ++++----
include/linux/mlx4/device.h | 4 ++--
2 files changed, 6 insertions(+), 6 deletions(-)
@@ -343,7 +343,7 @@ int mlx4_cq_alloc(struct mlx4_dev *dev, int nent,cq->cons_index=0;cq->arm_sn=1;cq->uar=uar;-atomic_set(&cq->refcount,1);+refcount_set(&cq->refcount,1);init_completion(&cq->free);cq->comp=mlx4_add_cq_to_tasklet;cq->tasklet_ctx.priv=
From: Elena Reshetova <elena.reshetova@intel.com> Date: 2017-03-28 09:02:49
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 <redacted>
Signed-off-by: Kees Cook <redacted>
Signed-off-by: David Windsor <redacted>
---
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(-)
@@ -10,9 +10,11 @@*releaseforlicensingtermsandconditions.*/+#include<linux/refcount.h>+structclip_entry{spinlock_tlock;/* Hold while modifying clip reference */-atomic_trefcnt;+refcount_trefcnt;structlist_headlist;union{structsockaddr_inaddr;
From: Elena Reshetova <elena.reshetova@intel.com> Date: 2017-03-28 09:05:23
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 <redacted>
Signed-off-by: Kees Cook <redacted>
Signed-off-by: David Windsor <redacted>
---
drivers/net/ppp/ppp_synctty.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
From: Elena Reshetova <elena.reshetova@intel.com> Date: 2017-03-28 09:05:55
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 <redacted>
Signed-off-by: Kees Cook <redacted>
Signed-off-by: David Windsor <redacted>
---
drivers/net/ppp/ppp_generic.c | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
@@ -84,7 +85,7 @@ struct ppp_file {structsk_buff_headxq;/* pppd transmit queue */structsk_buff_headrq;/* receive queue for pppd */wait_queue_head_trwait;/* for poll on reading /dev/ppp */-atomic_trefcnt;/* # refs (incl /dev/ppp attached) */+refcount_trefcnt;/* # refs (incl /dev/ppp attached) */inthdrlen;/* space to leave for headers */intindex;/* interface unit / channel number */intdead;/* unit/channel has been shut down */
From: David Laight <hidden> Date: 2017-03-28 09:35:07
From: Elena Reshetova
Sent: 28 March 2017 09:57
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.
I can't help feeling that you ought to find a scheme
that will detect extra decrements and extra increments
before the counter wraps 32 bits.
If an extra reference is requested every 100us it takes 4.8 days
for the counter to increment back to zero.
Simple tests aren't doing to find that - but it can easily happen
on a system that is running for several years.
David
Sent: 28 March 2017 09:57
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.
I can't help feeling that you ought to find a scheme
that will detect extra decrements and extra increments
before the counter wraps 32 bits.
If an extra reference is requested every 100us it takes 4.8 days
for the counter to increment back to zero.
Simple tests aren't doing to find that - but it can easily happen
on a system that is running for several years.
So, you are proposing to try detecting this case instead of preventing overflows?
Not sure how this would look like in a generic form...
From: Kalle Valo <hidden> Date: 2017-05-22 15:24:55
Elena Reshetova [off-list ref] wrote:
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 <redacted>
Signed-off-by: Kees Cook <redacted>
Signed-off-by: David Windsor <redacted>
From: Kalle Valo <hidden> Date: 2017-05-22 15:25:02
Elena Reshetova [off-list ref] wrote:
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 <redacted>
Signed-off-by: Hans Liljestrand <redacted>
Signed-off-by: Kees Cook <redacted>
Signed-off-by: David Windsor <redacted>