Commit 9dfa1dfe4d5e5e66a991321ab08afe69759d797a

Authored by Florian Westphal
Committed by Pablo Neira Ayuso
1 parent 7677e86843

netfilter: nf_log: account for size of NLMSG_DONE attribute

We currently neither account for the nlattr size, nor do we consider
the size of the trailing NLMSG_DONE when allocating nlmsg skb.

This can result in nflog to stop working, as __nfulnl_send() re-tries
sending forever if it failed to append NLMSG_DONE (which will never
work if buffer is not large enough).

Reported-by: Houcheng Lin <houcheng@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

Showing 1 changed file with 3 additions and 3 deletions Side-by-side Diff

net/netfilter/nfnetlink_log.c
... ... @@ -649,7 +649,8 @@
649 649 + nla_total_size(sizeof(u_int32_t)) /* gid */
650 650 + nla_total_size(plen) /* prefix */
651 651 + nla_total_size(sizeof(struct nfulnl_msg_packet_hw))
652   - + nla_total_size(sizeof(struct nfulnl_msg_packet_timestamp));
  652 + + nla_total_size(sizeof(struct nfulnl_msg_packet_timestamp))
  653 + + nla_total_size(sizeof(struct nfgenmsg)); /* NLMSG_DONE */
653 654  
654 655 if (in && skb_mac_header_was_set(skb)) {
655 656 size += nla_total_size(skb->dev->hard_header_len)
... ... @@ -692,8 +693,7 @@
692 693 goto unlock_and_release;
693 694 }
694 695  
695   - if (inst->skb &&
696   - size > skb_tailroom(inst->skb) - sizeof(struct nfgenmsg)) {
  696 + if (inst->skb && size > skb_tailroom(inst->skb)) {
697 697 /* either the queue len is too high or we don't have
698 698 * enough room in the skb left. flush to userspace. */
699 699 __nfulnl_flush(inst);