net: initialize rmem_alloc and omem_alloc to 0 in netlink socket
Subsystems (3)
PATCH 1/6 net: initialize rmem_alloc and omem_alloc to 0 in netlink socket
From: John Fastabend <[email protected]>
The rmem_alloc and omem_alloc socket fields are not initialized. This sets each variable to zero when a socket is created. Note the sk_wmem_alloc is already initialized in sock_init_data.
---
net/netlink/af_netlink.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
net/netlink/af_netlink.c +3 -0
@@ -423,6 +423,9 @@ static int __netlink_create(struct net *net, struct socket *sock, }init_waitqueue_head (&nlk->wait); +atomic_set (&sk->sk_rmem_alloc,0 ); +atomic_set (&sk->sk_omem_alloc,0 ); + sk->sk_destruct = netlink_sock_destruct; sk->sk_protocol = protocol;return 0 ;
PATCH 2/6 net: remove kfree_skb on a NULL pointer in af_netlink.c
From: John Fastabend <[email protected]>
This removes a kfree_skb that is being called on a NULL pointer when do_one_broadcast() is sucessful. And moves the kfree_skb into do_one_broadcast() for the error case.
---
net/netlink/af_netlink.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
net/netlink/af_netlink.c +2 -2
@@ -1021,6 +1021,8 @@ static inline int do_one_broadcast(struct sock *sk,netlink_overrun (sk);if (nlk->flags &NETLINK_BROADCAST_SEND_ERROR ) p->delivery_failure =1 ; +kfree_skb (p->skb2); + p->skb2 =NULL ; }else { p->congested |= val; p->delivered =1 ;
@@ -1065,8 +1067,6 @@ int netlink_broadcast(struct sock *ssk, struct sk_buff *skb, u32 pid,netlink_unlock_table (); -kfree_skb (info.skb2); -if (info.delivery_failure)return -ENOBUFS ;
David Miller
maintainerRe: [net-2.6 PATCH 2/6] net: remove kfree_skb on a NULL pointer in af_netlink.c
From: Jeff Kirsher <[email protected]>
Date: Thu, 17 Sep 2009 17:57:29 -0700
Quoted 8 lines
From: John Fastabend <[email protected]>
This removes a
kfree_skbthat is being called on a NULL pointer whendo_one_broadcast()is sucessful. And moves thekfree_skbintodo_one_broadcast()for the error case.Signed-off-by John Fastabend <[email protected]>Signed-off-by Jeff Kirsher <[email protected]>
kfree_skb() on a NULL pointer is completely legal.
Re: [net-2.6 PATCH 2/6] net: remove kfree_skb on a NULL pointer in af_netlink.c
Quoted 10 lines · David Miller
From: Jeff Kirsher <[email protected]>
Date: Thu, 17 Sep 2009 17:57:29 -0700Quoted 6 lines
From: John Fastabend <[email protected]>
This removes a
kfree_skbthat is being called on a NULL pointer whendo_one_broadcast()is sucessful. And moves thekfree_skbintodo_one_broadcast()for the error case.
Quoted 6 lines
Quoted 3 lines
Signed-off-by John Fastabend <[email protected]>Signed-off-by Jeff Kirsher <[email protected]>
kfree_skb()on a NULL pointer is completely legal.
OK, but this depends on the unlikely() macro in kfree_skb() to catch a case that is the expected non-error case. Would it be better to wrap the kfree_skb() in an if statement to avoid hitting the unlikely() macro? Or is the performance hit from the unlikely() macro so small this is not an issue? Thanks for looking at these.
john.
David Miller
maintainerRe: [net-2.6 PATCH 2/6] net: remove kfree_skb on a NULL pointer in af_netlink.c
From: John Fastabend <[email protected]>
Date: Mon, 21 Sep 2009 12:04:35 +0000
Quoted 7 lines
Quoted 1 line
OK, but this depends on the
unlikely()macro inkfree_skb()to catch a case that is the expected non-error case. Would it be better to wrap thekfree_skb()in an if statement to avoid hitting theunlikely()macro? Or is the performance hit from theunlikely()macro so small this is not an issue? Thanks for looking at these.
Expands too much code inline, that's why we don't do it that way.
PATCH 3/6 net: fix vlan_get_size to include vlan_flags size
In reply to Jeff KirsherFrom: John Fastabend <[email protected]>
Fix vlan_get_size to include vlan->flags. Currently, the size of the vlan flags is not included in the nlmsg size.
---
net/8021q/vlan_netlink.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
net/8021q/vlan_netlink.c +1 -0
@@ -169,6 +169,7 @@ static size_t vlan_get_size(const struct net_device *dev)struct vlan_dev_info *vlan =vlan_dev_info (dev);return nla_total_size (2 ) +/* IFLA_VLAN_ID */ +sizeof (struct ifla_vlan_flags ) +/* IFLA_VLAN_FLAGS */ vlan_qos_map_size (vlan->nr_ingress_mappings) +vlan_qos_map_size (vlan->nr_egress_mappings); }
PATCH 4/6 net: fix nlmsg len size for skb when error bit is set.
In reply to Jeff KirsherFrom: John Fastabend <[email protected]>
Currently, the nlmsg->len field is not set correctly in netlink_ack() for ack messages that include the nlmsg of the error frame. This corrects the length field passed to __nlmsg_put to use the correct payload size.
---
net/netlink/af_netlink.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
net/netlink/af_netlink.c +1 -1
@@ -1788,7 +1788,7 @@ void netlink_ack(struct sk_buff *in_skb, struct nlmsghdr *nlh, int err) } rep =__nlmsg_put (skb,NETLINK_CB (in_skb).pid, nlh->nlmsg_seq, -NLMSG_ERROR ,sizeof (struct nlmsgerr ),0 ); +NLMSG_ERROR , payload,0 ); errmsg =nlmsg_data (rep); errmsg->error = err;memcpy (&errmsg->msg, nlh, err ? nlh->nlmsg_len :sizeof (*nlh));
PATCH 5/6 net: fix sock locking for sk_err field in netlink.
In reply to Jeff KirsherFrom: John Fastabend <[email protected]>
This adds the sock lock around setting the sk_err field in sock struct. Without the lock multiple threads may write to this field.
---
net/netlink/af_netlink.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
net/netlink/af_netlink.c +6 -0
@@ -732,7 +732,9 @@ static void netlink_overrun(struct sock *sk)if (!(nlk->flags &NETLINK_RECV_NO_ENOBUFS )) {if (!test_and_set_bit (0 , &nlk_sk (sk)->state)) { +lock_sock (sk); sk->sk_err =ENOBUFS ; +release_sock (sk); sk->sk_error_report (sk); } }
@@ -1101,7 +1103,9 @@ static inline int do_one_set_err(struct sock *sk, !test_bit(p->group - 1, nlk->groups)) goto out; +lock_sock (sk); sk->sk_err = p->code; +release_sock (sk); sk->sk_error_report (sk); out:return 0 ;
@@ -1780,7 +1784,9 @@ void netlink_ack(struct sk_buff *in_skb, struct nlmsghdr *nlh, int err) in_skb->sk->sk_protocol, NETLINK_CB(in_skb).pid);if (sk) { +lock_sock (sk); sk->sk_err =ENOBUFS ; +release_sock (sk); sk->sk_error_report (sk);sock_put (sk); }
David Miller
maintainerRe: [net-2.6 PATCH 5/6] net: fix sock locking for sk_err field in netlink.
From: Jeff Kirsher <[email protected]>
Date: Thu, 17 Sep 2009 17:58:32 -0700
Quoted 8 lines
From: John Fastabend <[email protected]>
This adds the sock lock around setting the
sk_errfield in sock struct. Without the lock multiple threads may write to this field.Signed-off-by John Fastabend <[email protected]>Signed-off-by Jeff Kirsher <[email protected]>
This isn't right.
Writes to sk->sk_err can occur asynchronously just fine and without any locking.
The only requirement is that consumers of the sk_err value use sock_error() which uses xchg() to get and clear the value atomically.
PATCH 6/6 net: fix double skb free in dcbnl
In reply to Jeff KirsherFrom: John Fastabend <[email protected]>
netlink_unicast() calls kfree_skb even in the error case.
dcbnl calls netlink_unicast() which when it fails free's the skb and returns an error value. dcbnl is free'ing the skb again when this error occurs. This patch removes the double free.
---
net/dcb/dcbnl.c | 15 +++++++-------- 1 files changed, 7 insertions(+), 8 deletions(-)
net/dcb/dcbnl.c +7 -8
@@ -194,7 +194,7 @@ static int dcbnl_reply(u8 value, u8 event, u8 cmd, u8 attr, u32 pid,nlmsg_end (dcbnl_skb, nlh); ret =rtnl_unicast (dcbnl_skb, &init_net, pid);if (ret) - goto err; +return -EINVAL ;return 0 ; nlmsg_failure:
@@ -275,7 +275,7 @@ static int dcbnl_getpfccfg(struct net_device *netdev, struct nlattr **tb, ret =rtnl_unicast (dcbnl_skb, &init_net, pid);if (ret) - goto err; + goto err_out;return 0 ; nlmsg_failure:
@@ -316,12 +316,11 @@ static int dcbnl_getperm_hwaddr(struct net_device *netdev, struct nlattr **tb, ret =rtnl_unicast (dcbnl_skb, &init_net, pid);if (ret) - goto err; + goto err_out;return 0 ; nlmsg_failure: -err:kfree_skb (dcbnl_skb); err_out:return -EINVAL ;
@@ -383,7 +382,7 @@ static int dcbnl_getcap(struct net_device *netdev, struct nlattr **tb, ret =rtnl_unicast (dcbnl_skb, &init_net, pid);if (ret) - goto err; + goto err_out;return 0 ; nlmsg_failure:
@@ -460,7 +459,7 @@ static int dcbnl_getnumtcs(struct net_device *netdev, struct nlattr **tb, ret =rtnl_unicast (dcbnl_skb, &init_net, pid);if (ret) { ret = -EINVAL ; - goto err; + goto err_out; }return 0 ;
@@ -799,7 +798,7 @@ static int __dcbnl_pg_getcfg(struct net_device *netdev, struct nlattr **tb, ret =rtnl_unicast (dcbnl_skb, &init_net, pid);if (ret) - goto err; + goto err_out;return 0 ;
@@ -1063,7 +1062,7 @@ static int dcbnl_bcn_getcfg(struct net_device *netdev, struct nlattr **tb, ret =rtnl_unicast (dcbnl_skb, &init_net, pid);if (ret) - goto err; + goto err_out;return 0 ;
David Miller
maintainerFrom: Jeff Kirsher <[email protected]>
Date: Thu, 17 Sep 2009 17:57:09 -0700
Quoted 9 lines
From: John Fastabend <[email protected]>
The
rmem_allocandomem_allocsocket fields are not initialized. This sets each variable to zero when a socket is created. Note thesk_wmem_allocis already initialized insock_init_data.Signed-off-by John Fastabend <[email protected]>Signed-off-by Jeff Kirsher <[email protected]>
It's set to zero implicitly by the memset() done at sock_alloc() time.
Re-setting it again here explicitly will just add unnecessary memory traffic.