From: Thomas Graf Date: Sat, 30 Nov 2013 12:21:31 +0000 (+0100) Subject: netlink: Avoid netlink mmap alloc if msg size exceeds frame size X-Git-Tag: Ubuntu-5.2.0-15.16~14144^2~265^2~11 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=aae9f0e22c07f6b97752741156ac0b3637d37a1a;p=mirror_ubuntu-eoan-kernel.git 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 Reviewed-by: Daniel Borkmann Signed-off-by: Jesse Gross --- 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, if (ring->pg_vec == NULL) goto out_put; + if (ring->frame_size - NL_MMAP_HDRLEN < size) + goto out_put; + skb = alloc_skb_head(gfp_mask); if (skb == NULL) goto err1; @@ -1778,6 +1781,7 @@ struct sk_buff *netlink_alloc_skb(struct sock *ssk, unsigned int size, if (ring->pg_vec == NULL) goto out_free; + /* check again under lock */ maxlen = ring->frame_size - NL_MMAP_HDRLEN; if (maxlen < size) goto out_free;