From: Hui Peng <benquike@gmail.com>
To: pablo@netfilter.org, fw@strlen.de, phil@nwl.cc,
davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com
Cc: netfilter-devel@vger.kernel.org, coreteam@netfilter.org,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] netfilter: nfnetlink_log: fix config error handling, SIT headroom OOB read, and nlmsg rollback
Date: Sat, 19 Sep 2026 21:52:41 +0000 [thread overview]
Message-ID: <20260919215241.3471723-1-benquike@gmail.com> (raw)
Fix three issues in net/netfilter/nfnetlink_log.c:
1. In __build_packet_message(), subtracting ETH_HLEN from skb_mac_header()
for ARPHRD_SIT tunnels can read before skb->head or past
skb_tail_pointer(skb), and nla_put_failure returns -1 without calling
nlmsg_cancel(inst->skb, nlh). Remove the unsafe ETH_HLEN subtraction,
verify hwhdrp + hard_header_len <= skb_tail_pointer(skb), and cancel
the partial nlmsg on error.
2. In nfulnl_log_packet(), only increment inst->qlen after
__build_packet_message() succeeds.
3. In nfulnl_recv_config(), propagate errors from nfulnl_set_mode() and
nfulnl_set_nlbufsiz() and destroy the newly created instance if
NFULNL_CFG_CMD_BIND was processed in the same message.
Fixes: 0c36b48b36dc ("netfilter: nfnetlink_log: fix mac address for 6in4 tunnels")
Assisted-by: LLM
Signed-off-by: Hui Peng <benquike@gmail.com>
---
diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
index d923f2cb1398..ae29dd55d7d3 100644
--- a/net/netfilter/nfnetlink_log.c
+++ b/net/netfilter/nfnetlink_log.c
@@ -610,10 +610,8 @@ __build_packet_message(struct nfnl_log_net *log,
hwhdrp = skb_mac_header(skb);
- if (skb->dev->type == ARPHRD_SIT)
- hwhdrp -= ETH_HLEN;
-
if (hwhdrp >= skb->head &&
+ hwhdrp + skb->dev->hard_header_len <= skb_tail_pointer(skb) &&
nla_put(inst->skb, NFULA_HWHEADER,
skb->dev->hard_header_len, hwhdrp))
goto nla_put_failure;
@@ -688,6 +686,7 @@ __build_packet_message(struct nfnl_log_net *log,
return 0;
nla_put_failure:
+ nlmsg_cancel(inst->skb, nlh);
PRINTR(KERN_ERR "nfnetlink_log: error creating log nlmsg\n");
return -1;
}
@@ -832,11 +831,12 @@ nfulnl_log_packet(struct net *net,
goto alloc_failure;
}
- inst->qlen++;
+ if (__build_packet_message(log, inst, skb, data_len, pf,
+ hooknum, in, out, prefix, plen,
+ nfnl_ct, ct, ctinfo) < 0)
+ goto unlock_and_release;
- __build_packet_message(log, inst, skb, data_len, pf,
- hooknum, in, out, prefix, plen,
- nfnl_ct, ct, ctinfo);
+ inst->qlen++;
if (inst->qlen >= qthreshold)
__nfulnl_flush(inst);
@@ -1002,8 +1002,10 @@ static int nfulnl_recv_config(struct sk_buff *skb, const struct nfnl_info *info,
struct nfulnl_msg_config_mode *params =
nla_data(nfula[NFULA_CFG_MODE]);
- nfulnl_set_mode(inst, params->copy_mode,
- ntohl(params->copy_range));
+ ret = nfulnl_set_mode(inst, params->copy_mode,
+ ntohl(params->copy_range));
+ if (ret < 0)
+ goto err_destroy;
}
if (nfula[NFULA_CFG_TIMEOUT]) {
@@ -1015,7 +1017,9 @@ static int nfulnl_recv_config(struct sk_buff *skb, const struct nfnl_info *info,
if (nfula[NFULA_CFG_NLBUFSIZ]) {
__be32 nlbufsiz = nla_get_be32(nfula[NFULA_CFG_NLBUFSIZ]);
- nfulnl_set_nlbufsiz(inst, ntohl(nlbufsiz));
+ ret = nfulnl_set_nlbufsiz(inst, ntohl(nlbufsiz));
+ if (ret < 0)
+ goto err_destroy;
}
if (nfula[NFULA_CFG_QTHRESH]) {
@@ -1031,6 +1035,11 @@ static int nfulnl_recv_config(struct sk_buff *skb, const struct nfnl_info *info,
instance_put(inst);
out:
return ret;
+
+err_destroy:
+ if (cmd && cmd->command == NFULNL_CFG_CMD_BIND)
+ instance_destroy(log, inst);
+ goto out_put;
}
static const struct nfnl_callback nfulnl_cb[NFULNL_MSG_MAX] = {
next reply other threads:[~2026-09-19 21:52 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-19 21:52 Hui Peng [this message]
2026-11-16 19:15 ` [PATCH] netfilter: nfnetlink_log: fix config error handling, SIT headroom OOB read, and nlmsg rollback Florian Westphal
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=20260919215241.3471723-1-benquike@gmail.com \
--to=benquike@gmail.com \
--cc=coreteam@netfilter.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=fw@strlen.de \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pablo@netfilter.org \
--cc=phil@nwl.cc \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.