diff mbox

[net] mpls: fix possible use after free of device

Message ID 1433526885-18861-1-git-send-email-rshearma@brocade.com
State Accepted, archived
Delegated to: David Miller
Headers show

Commit Message

Robert Shearman June 5, 2015, 5:54 p.m. UTC
The mpls device is used in an RCU read context without a lock being
held. As the memory is freed without waiting for the RCU grace period
to elapse, the freed memory could still be in use.

Address this by using kfree_rcu to free the memory for the mpls device
after the RCU grace period has elapsed.

Fixes: 03c57747a702 ("mpls: Per-device MPLS state")
Signed-off-by: Robert Shearman <rshearma@brocade.com>
---
 net/mpls/af_mpls.c  | 2 +-
 net/mpls/internal.h | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

Comments

Eric W. Biederman June 5, 2015, 7:08 p.m. UTC | #1
Robert Shearman <rshearma@brocade.com> writes:

> The mpls device is used in an RCU read context without a lock being
> held. As the memory is freed without waiting for the RCU grace period
> to elapse, the freed memory could still be in use.
>
> Address this by using kfree_rcu to free the memory for the mpls device
> after the RCU grace period has elapsed.

Acked-by: "Eric W. Biederman" <ebiederm@xmission.com>


> Fixes: 03c57747a702 ("mpls: Per-device MPLS state")
> Signed-off-by: Robert Shearman <rshearma@brocade.com>
> ---
>  net/mpls/af_mpls.c  | 2 +-
>  net/mpls/internal.h | 1 +
>  2 files changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/net/mpls/af_mpls.c b/net/mpls/af_mpls.c
> index 7b3f732269e4..bff427f31924 100644
> --- a/net/mpls/af_mpls.c
> +++ b/net/mpls/af_mpls.c
> @@ -541,7 +541,7 @@ static void mpls_ifdown(struct net_device *dev)
>  
>  	RCU_INIT_POINTER(dev->mpls_ptr, NULL);
>  
> -	kfree(mdev);
> +	kfree_rcu(mdev, rcu);
>  }
>  
>  static int mpls_dev_notify(struct notifier_block *this, unsigned long event,
> diff --git a/net/mpls/internal.h b/net/mpls/internal.h
> index b064c345042c..8cabeb5a1cb9 100644
> --- a/net/mpls/internal.h
> +++ b/net/mpls/internal.h
> @@ -16,6 +16,7 @@ struct mpls_dev {
>  	int			input_enabled;
>  
>  	struct ctl_table_header *sysctl;
> +	struct rcu_head		rcu;
>  };
>  
>  struct sk_buff;
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Miller June 8, 2015, 2:37 a.m. UTC | #2
From: Robert Shearman <rshearma@brocade.com>
Date: Fri, 5 Jun 2015 18:54:45 +0100

> The mpls device is used in an RCU read context without a lock being
> held. As the memory is freed without waiting for the RCU grace period
> to elapse, the freed memory could still be in use.
> 
> Address this by using kfree_rcu to free the memory for the mpls device
> after the RCU grace period has elapsed.
> 
> Fixes: 03c57747a702 ("mpls: Per-device MPLS state")
> Signed-off-by: Robert Shearman <rshearma@brocade.com>

Applied, thanks.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/net/mpls/af_mpls.c b/net/mpls/af_mpls.c
index 7b3f732269e4..bff427f31924 100644
--- a/net/mpls/af_mpls.c
+++ b/net/mpls/af_mpls.c
@@ -541,7 +541,7 @@  static void mpls_ifdown(struct net_device *dev)
 
 	RCU_INIT_POINTER(dev->mpls_ptr, NULL);
 
-	kfree(mdev);
+	kfree_rcu(mdev, rcu);
 }
 
 static int mpls_dev_notify(struct notifier_block *this, unsigned long event,
diff --git a/net/mpls/internal.h b/net/mpls/internal.h
index b064c345042c..8cabeb5a1cb9 100644
--- a/net/mpls/internal.h
+++ b/net/mpls/internal.h
@@ -16,6 +16,7 @@  struct mpls_dev {
 	int			input_enabled;
 
 	struct ctl_table_header *sysctl;
+	struct rcu_head		rcu;
 };
 
 struct sk_buff;