lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250526162746319JPXpL0xRJ-n7onnZApOiV@zte.com.cn>
Date: Mon, 26 May 2025 16:27:46 +0800 (CST)
From: <jiang.kun2@....com.cn>
To: <davem@...emloft.net>, <kuba@...nel.org>
Cc: <dsahern@...nel.org>, <edumazet@...gle.com>, <pabeni@...hat.com>,
        <horms@...nel.org>, <netdev@...r.kernel.org>,
        <linux-kernel@...r.kernel.org>, <xu.xin16@....com.cn>,
        <yang.yang29@....com.cn>, <wang.yaxin@....com.cn>,
        <fan.yu9@....com.cn>, <he.peilin@....com.cn>, <tu.qiang35@....com.cn>,
        <qiu.yutan@....com.cn>, <zhang.yunkai@....com.cn>,
        <ye.xingchen@....com.cn>
Subject: [PATCH net-next] net: arp: use kfree_skb_reason() in arp_rcv()

From: Qiu Yutan <qiu.yutan@....com.cn>

Replace kfree_skb() with kfree_skb_reason() in arp_rcv(). Following
new skb drop reasons are introduced for arp:

/* ARP header hardware address length mismatch */
SKB_DROP_REASON_ARP_HLEN_MISMATCH
/* ARP header protocol addresslength is invalid */
SKB_DROP_REASON_ARP_PLEN_INVALID

Signed-off-by: Qiu Yutan <qiu.yutan@....com.cn>
Signed-off-by: Jiang Kun <jiang.kun2@....com.cn>
---
 include/net/dropreason-core.h | 12 ++++++++++++
 net/ipv4/arp.c                | 15 ++++++++++++---
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/include/net/dropreason-core.h b/include/net/dropreason-core.h
index bea77934a235..dc846b705c24 100644
--- a/include/net/dropreason-core.h
+++ b/include/net/dropreason-core.h
@@ -118,6 +118,8 @@
 	FN(TUNNEL_TXINFO)		\
 	FN(LOCAL_MAC)			\
 	FN(ARP_PVLAN_DISABLE)		\
+	FN(ARP_HLEN_MISMATCH)		\
+	FN(ARP_PLEN_INVALID)		\
 	FN(MAC_IEEE_MAC_CONTROL)	\
 	FN(BRIDGE_INGRESS_STP_STATE)	\
 	FNe(MAX)
@@ -560,6 +562,16 @@ enum skb_drop_reason {
 	 * enabled.
 	 */
 	SKB_DROP_REASON_ARP_PVLAN_DISABLE,
+	/**
+	 * @SKB_DROP_REASON_ARP_HLEN_MISMATCH: ARP header hardware address
+	 * length mismatch.
+	 */
+	SKB_DROP_REASON_ARP_HLEN_MISMATCH,
+	/**
+	 * @SKB_DROP_REASON_ARP_PLEN_INVALID: ARP header protocol address
+	 * length is invalid.
+	 */
+	SKB_DROP_REASON_ARP_PLEN_INVALID,
 	/**
 	 * @SKB_DROP_REASON_MAC_IEEE_MAC_CONTROL: the destination MAC address
 	 * is an IEEE MAC Control address.
diff --git a/net/ipv4/arp.c b/net/ipv4/arp.c
index a648fff71ea7..ca19f2645ccb 100644
--- a/net/ipv4/arp.c
+++ b/net/ipv4/arp.c
@@ -967,6 +967,7 @@ static int arp_rcv(struct sk_buff *skb, struct net_device *dev,
 		   struct packet_type *pt, struct net_device *orig_dev)
 {
 	const struct arphdr *arp;
+	enum skb_drop_reason drop_reason;

 	/* do not tweak dropwatch on an ARP we will ignore */
 	if (dev->flags & IFF_NOARP ||
@@ -979,12 +980,20 @@ static int arp_rcv(struct sk_buff *skb, struct net_device *dev,
 		goto out_of_mem;

 	/* ARP header, plus 2 device addresses, plus 2 IP addresses.  */
-	if (!pskb_may_pull(skb, arp_hdr_len(dev)))
+	drop_reason = pskb_may_pull_reason(skb, arp_hdr_len(dev));
+	if (drop_reason != SKB_NOT_DROPPED_YET)
 		goto freeskb;

 	arp = arp_hdr(skb);
-	if (arp->ar_hln != dev->addr_len || arp->ar_pln != 4)
+	if (arp->ar_hln != dev->addr_len) {
+		drop_reason = SKB_DROP_REASON_ARP_HLEN_MISMATCH;
 		goto freeskb;
+	}
+
+	if (arp->ar_pln != 4) {
+		drop_reason = SKB_DROP_REASON_ARP_PLEN_INVALID;
+		goto freeskb;
+	}

 	memset(NEIGH_CB(skb), 0, sizeof(struct neighbour_cb));

@@ -996,7 +1005,7 @@ static int arp_rcv(struct sk_buff *skb, struct net_device *dev,
 	consume_skb(skb);
 	return NET_RX_SUCCESS;
 freeskb:
-	kfree_skb(skb);
+	kfree_skb_reason(skb, drop_reason);
 out_of_mem:
 	return NET_RX_DROP;
 }
-- 
2.25.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ