From: Marcelo Ricardo Leitner <mleitner@redhat.com>
To: netfilter-devel@vger.kernel.org
Subject: [PATCH v4 2/3] Do error handling if __build_packet_message fails
Date: Wed, 29 Oct 2014 10:51:14 -0200 [thread overview]
Message-ID: <8dcee609af0015c15d2a99ab6d076a65d6ec01a8.1414586968.git.mleitner@redhat.com> (raw)
In-Reply-To: <7be00bf663b212d4984414346da216cf17d3443d.1414586968.git.mleitner@redhat.com>
Currently, we don't check if __build_packet_message fails or not and
that leaves it prone to sending incomplete messages to userspace.
This commit fixes it by canceling the new message if there was any issue
while building it and makes sure the skb is freed if it was the only
message in it.
Signed-off-by: Marcelo Ricardo Leitner <mleitner@redhat.com>
---
net/netfilter/nfnetlink_log.c | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
index b1e3a05794169283ed50d1c0fb4f44d9e7753eeb..045c5956611f61a3f5dad3e15ca7cf19365e5afa 100644
--- a/net/netfilter/nfnetlink_log.c
+++ b/net/netfilter/nfnetlink_log.c
@@ -568,10 +568,8 @@ __build_packet_message(struct nfnl_log_net *log,
struct nlattr *nla;
int size = nla_attr_size(data_len);
- if (skb_tailroom(inst->skb) < nla_total_size(data_len)) {
- printk(KERN_WARNING "nfnetlink_log: no tailroom!\n");
- return -1;
- }
+ if (skb_tailroom(inst->skb) < nla_total_size(data_len))
+ goto nla_put_failure;
nla = (struct nlattr *)skb_put(inst->skb, nla_total_size(data_len));
nla->nla_type = NFULA_PAYLOAD;
@@ -586,6 +584,7 @@ __build_packet_message(struct nfnl_log_net *log,
nla_put_failure:
PRINTR(KERN_ERR "nfnetlink_log: error creating log nlmsg\n");
+ nlmsg_cancel(skb, nlh);
return -1;
}
@@ -708,8 +707,9 @@ nfulnl_log_packet(struct net *net,
inst->qlen++;
- __build_packet_message(log, inst, skb, data_len, pf,
- hooknum, in, out, prefix, plen);
+ if (__build_packet_message(log, inst, skb, data_len, pf,
+ hooknum, in, out, prefix, plen))
+ goto build_failure;
if (inst->qlen >= qthreshold)
__nfulnl_flush(inst);
@@ -726,6 +726,15 @@ unlock_and_release:
instance_put(inst);
return;
+build_failure:
+ /* If no other messages in it, we're good to free it. */
+ if (!inst->skb->len) {
+ kfree_skb(inst->skb);
+ inst->skb = NULL;
+ }
+
+ inst->qlen--;
+
alloc_failure:
/* FIXME: statistics */
goto unlock_and_release;
--
1.9.3
next prev parent reply other threads:[~2014-10-29 12:51 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-29 12:51 [PATCH v4 1/3] netfilter: log: protect nf_log_register against double registering Marcelo Ricardo Leitner
2014-10-29 12:51 ` Marcelo Ricardo Leitner [this message]
2014-11-04 16:47 ` [PATCH v4 2/3] Do error handling if __build_packet_message fails Pablo Neira Ayuso
2014-11-04 18:01 ` Marcelo Ricardo Leitner
2014-11-04 18:26 ` Pablo Neira Ayuso
2014-11-04 18:52 ` Marcelo Ricardo Leitner
2014-11-04 19:04 ` Pablo Neira Ayuso
2014-11-04 19:08 ` Marcelo Ricardo Leitner
2014-11-04 19:11 ` Florian Westphal
2014-11-06 1:07 ` Pablo Neira Ayuso
2014-11-06 2:19 ` Florian Westphal
2014-10-29 12:51 ` [PATCH v4 3/3] Make use of pr_fmt where applicable Marcelo Ricardo Leitner
2014-11-04 16:50 ` Pablo Neira Ayuso
2014-11-04 17:11 ` Marcelo Ricardo Leitner
2014-10-30 16:31 ` [PATCH v4 1/3] netfilter: log: protect nf_log_register against double registering Pablo Neira Ayuso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8dcee609af0015c15d2a99ab6d076a65d6ec01a8.1414586968.git.mleitner@redhat.com \
--to=mleitner@redhat.com \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).