From: Eric Dumazet <edumazet@kernel.org>
To: "David S . Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Alexander Aring <alex.aring@gmail.com>
Cc: Simon Horman <horms@kernel.org>,
netdev@vger.kernel.org, edumazet@google.com,
Eric Dumazet <edumazet@kernel.org>
Subject: [PATCH v2 net 1/2] ieee802154: 6lowpan: look up the neighbour short address in lowpan_xmit()
Date: Fri, 2 Oct 2026 08:27:11 +0000 [thread overview]
Message-ID: <20261002082712.3535213-2-edumazet@kernel.org> (raw)
In-Reply-To: <20261002082712.3535213-1-edumazet@kernel.org>
lowpan_header_create() uses ipv6_hdr(skb)->daddr to find the
neighbour, and to use its 802.15.4 short address if it has one.
The IPv6 header is not there yet when lowpan_header_create() is
called for AF_PACKET SOCK_DGRAM sockets: packet_snd() copies the
payload after dev_hard_header(), and tpacket_fill_skb() attaches it
as page fragments after dev_hard_header(). The lookup then reads
uninitialized memory, possibly past the end of the linear data.
Move the lookup to lowpan_header(), called from lowpan_xmit().
lowpan_xmit() now makes sure the IPv6 header is in the linear part
of the skb.
Fixes: eab560e58208 ("6lowpan: add support for 802.15.4 short addr handling")
Signed-off-by: Eric Dumazet <edumazet@kernel.org>
Cc: Alexander Aring <alex.aring@gmail.com>
---
net/ieee802154/6lowpan/tx.c | 62 +++++++++++++++++++++----------------
1 file changed, 36 insertions(+), 26 deletions(-)
diff --git a/net/ieee802154/6lowpan/tx.c b/net/ieee802154/6lowpan/tx.c
index 4df76ff50699ede5c187c9cca6f0cc10b19d2123..ab28b6f912c000f5cf141982b6d1b25e7d2e48f6 100644
--- a/net/ieee802154/6lowpan/tx.c
+++ b/net/ieee802154/6lowpan/tx.c
@@ -36,9 +36,6 @@ int lowpan_header_create(struct sk_buff *skb, struct net_device *ldev,
{
struct wpan_dev *wpan_dev = lowpan_802154_dev(ldev)->wdev->ieee802154_ptr;
struct lowpan_addr_info *info = lowpan_skb_priv(skb);
- struct lowpan_802154_neigh *llneigh = NULL;
- const struct ipv6hdr *hdr = ipv6_hdr(skb);
- struct neighbour *n;
if (!daddr)
return -EINVAL;
@@ -57,28 +54,12 @@ int lowpan_header_create(struct sk_buff *skb, struct net_device *ldev,
info->daddr.short_addr = cpu_to_le16(IEEE802154_ADDR_BROADCAST);
info->daddr.mode = IEEE802154_ADDR_SHORT;
} else {
- __le16 short_addr = cpu_to_le16(IEEE802154_ADDR_SHORT_UNSPEC);
-
- n = neigh_lookup(&nd_tbl, &hdr->daddr, ldev);
- if (n) {
- llneigh = lowpan_802154_neigh(neighbour_priv(n));
- read_lock_bh(&n->lock);
- short_addr = llneigh->short_addr;
- read_unlock_bh(&n->lock);
- }
-
- if (llneigh &&
- lowpan_802154_is_valid_src_short_addr(short_addr)) {
- info->daddr.short_addr = short_addr;
- info->daddr.mode = IEEE802154_ADDR_SHORT;
- } else {
- info->daddr.mode = IEEE802154_ADDR_LONG;
- ieee802154_be64_to_le64(&info->daddr.extended_addr,
- daddr);
- }
-
- if (n)
- neigh_release(n);
+ /* The IPv6 header might not be there yet (AF_PACKET).
+ * lowpan_header() will use the neighbour short address,
+ * if there is one.
+ */
+ info->daddr.mode = IEEE802154_ADDR_LONG;
+ ieee802154_be64_to_le64(&info->daddr.extended_addr, daddr);
}
if (!saddr) {
@@ -221,6 +202,31 @@ lowpan_xmit_fragmented(struct sk_buff *skb, struct net_device *ldev,
return rc;
}
+/* Use the short address of the IPv6 destination, if the neighbour has one. */
+static void lowpan_neigh_short_addr(const struct sk_buff *skb,
+ struct net_device *ldev,
+ struct ieee802154_addr *daddr)
+{
+ struct lowpan_802154_neigh *llneigh;
+ struct neighbour *n;
+ __le16 short_addr;
+
+ n = neigh_lookup(&nd_tbl, &ipv6_hdr(skb)->daddr, ldev);
+ if (!n)
+ return;
+
+ llneigh = lowpan_802154_neigh(neighbour_priv(n));
+ read_lock_bh(&n->lock);
+ short_addr = llneigh->short_addr;
+ read_unlock_bh(&n->lock);
+ neigh_release(n);
+
+ if (lowpan_802154_is_valid_src_short_addr(short_addr)) {
+ daddr->short_addr = short_addr;
+ daddr->mode = IEEE802154_ADDR_SHORT;
+ }
+}
+
static int lowpan_header(struct sk_buff *skb, struct net_device *ldev,
u16 *dgram_size, u16 *dgram_offset)
{
@@ -230,6 +236,9 @@ static int lowpan_header(struct sk_buff *skb, struct net_device *ldev,
memcpy(&info, lowpan_skb_priv(skb), sizeof(info));
+ if (info.daddr.mode == IEEE802154_ADDR_LONG)
+ lowpan_neigh_short_addr(skb, ldev, &info.daddr);
+
*dgram_size = skb->len;
lowpan_header_compress(skb, ldev, &info.daddr, &info.saddr);
/* dgram_offset = (saved bytes after compression) + lowpan header len */
@@ -255,7 +264,8 @@ netdev_tx_t lowpan_xmit(struct sk_buff *skb, struct net_device *ldev)
pr_debug("package xmit\n");
- if (skb->protocol != htons(ETH_P_IPV6)) {
+ if (skb->protocol != htons(ETH_P_IPV6) ||
+ !pskb_network_may_pull(skb, sizeof(struct ipv6hdr))) {
kfree_skb(skb);
return NET_XMIT_DROP;
}
--
2.56.0.rc1.315.gc6ed9934b7-goog
next prev parent reply other threads:[~2026-10-02 8:27 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-02 8:27 [PATCH v2 net 0/2] ieee802154: 6lowpan: fix transmit address handling Eric Dumazet
2026-10-02 8:27 ` Eric Dumazet [this message]
2026-10-02 8:27 ` [PATCH v2 net 2/2] 6lowpan: fix warning in lowpan_compress_addr_64() Eric Dumazet
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=20261002082712.3535213-2-edumazet@kernel.org \
--to=edumazet@kernel.org \
--cc=alex.aring@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/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