aboutsummaryrefslogtreecommitdiffstats
path: root/net/netlink
diff options
context:
space:
mode:
authorThomas Graf <tgraf@suug.ch>2013-11-30 07:21:31 -0500
committerJesse Gross <jesse@nicira.com>2014-01-06 18:52:06 -0500
commitaae9f0e22c07f6b97752741156ac0b3637d37a1a (patch)
tree164aafabd87e384e55527a37ab67761ef7473c86 /net/netlink
parentbb9b18fb55b03477fe5bdd3e97245d6d4d3dee4f (diff)
netlink: Avoid netlink mmap alloc if msg size exceeds frame size
An insufficent ring frame size configuration can lead to an unnecessary skb allocation for every Netlink message. Check frame size before taking the queue lock and allocating the skb and re-check with lock to be safe. Signed-off-by: Thomas Graf <tgraf@suug.ch> Reviewed-by: Daniel Borkmann <dborkman@redhat.com> Signed-off-by: Jesse Gross <jesse@nicira.com>
Diffstat (limited to 'net/netlink')
-rw-r--r--net/netlink/af_netlink.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index bca50b95c182..64334893c61c 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -1769,6 +1769,9 @@ struct sk_buff *netlink_alloc_skb(struct sock *ssk, unsigned int size,
1769 if (ring->pg_vec == NULL) 1769 if (ring->pg_vec == NULL)
1770 goto out_put; 1770 goto out_put;
1771 1771
1772 if (ring->frame_size - NL_MMAP_HDRLEN < size)
1773 goto out_put;
1774
1772 skb = alloc_skb_head(gfp_mask); 1775 skb = alloc_skb_head(gfp_mask);
1773 if (skb == NULL) 1776 if (skb == NULL)
1774 goto err1; 1777 goto err1;
@@ -1778,6 +1781,7 @@ struct sk_buff *netlink_alloc_skb(struct sock *ssk, unsigned int size,
1778 if (ring->pg_vec == NULL) 1781 if (ring->pg_vec == NULL)
1779 goto out_free; 1782 goto out_free;
1780 1783
1784 /* check again under lock */
1781 maxlen = ring->frame_size - NL_MMAP_HDRLEN; 1785 maxlen = ring->frame_size - NL_MMAP_HDRLEN;
1782 if (maxlen < size) 1786 if (maxlen < size)
1783 goto out_free; 1787 goto out_free;