Skip to content

Commit

Permalink
netlink: Avoid netlink mmap alloc if msg size exceeds frame size
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Thomas Graf authored and Jesse Gross committed Jan 6, 2014
1 parent bb9b18f commit aae9f0e
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions net/netlink/af_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit aae9f0e

Please sign in to comment.