mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] netfilter: nfnetlink_log: fix config error handling, SIT headroom OOB read, and nlmsg rollback
@ 2026-09-19 21:52 Hui Peng
  0 siblings, 0 replies; only message in thread
From: Hui Peng @ 2026-09-19 21:52 UTC (permalink / raw)
  To: pablo, fw, phil, davem, edumazet, kuba, pabeni
  Cc: netfilter-devel, coreteam, netdev, linux-kernel

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] = {

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-09-19 21:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-19 21:52 [PATCH] netfilter: nfnetlink_log: fix config error handling, SIT headroom OOB read, and nlmsg rollback Hui Peng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®