[PATCH batadv] batman-adv: annotate functions which may cow reallocate the skbuff
Sven Eckelmann <[email protected]> Fri, 10 Jul 2026 22:19:58 +0200
| Newsgroups | org.open-mesh.lists.batman |
|---|---|
| Message-ID | <[email protected]> |
When a function is called which reallocated the skbuff, it is necessary to reacquire the pointers into the skb data. Otherwise they might cause an use-after-free. But is hard to identify such case when it is not clear that helpers are actually using skb-reallocating functions. Signed-off-by: Sven Eckelmann <[email protected]> --- net/batman-adv/mesh-interface.c | 5 +++++ net/batman-adv/multicast_forw.c | 10 ++++++++++ net/batman-adv/routing.c | 5 +++++ 3 files changed, 20 insertions(+) diff --git a/net/batman-adv/mesh-interface.c b/net/batman-adv/mesh-interface.c index 20582fe0..f1bfe2a5 100644 --- a/net/batman-adv/mesh-interface.c +++ b/net/batman-adv/mesh-interface.c @@ -57,6 +57,11 @@ * @skb: packet buffer which should be modified * @len: number of bytes to add * + * Warning: This function may reallocate the skb data buffer via + * skb_cow_head(). Any pointer into the skb data (e.g. obtained + * from skb->data or eth_hdr()) before this call must be considered + * invalid afterwards and has to be reacquired. + * * Return: 0 on success or negative error number in case of failure */ int batadv_skb_head_push(struct sk_buff *skb, unsigned int len) diff --git a/net/batman-adv/multicast_forw.c b/net/batman-adv/multicast_forw.c index d8374ef5..ccd4ae15 100644 --- a/net/batman-adv/multicast_forw.c +++ b/net/batman-adv/multicast_forw.c @@ -1080,6 +1080,11 @@ unsigned int batadv_mcast_forw_packet_hdrlen(unsigned int num_dests) * Tries to expand an skb's headroom so that its head to tail is 1298 * bytes (minimum IPv6 MTU + vlan ethernet header size) large. * + * Warning: This function may reallocate the skb data buffer via + * skb_cow() / skb_linearize(). Any pointer into the skb data (e.g. + * obtained from skb->data or eth_hdr()) before this call must be + * considered invalid afterwards and has to be reacquired. + * * Return: -EINVAL if the given skb's length is too large or -ENOMEM on memory * allocation failure. Otherwise, on success, zero is returned. */ @@ -1123,6 +1128,11 @@ static int batadv_mcast_forw_expand_head(struct batadv_priv *bat_priv, * that signaled interest in it, that is either via the translation table or the * according want-all flags, is attached accordingly. * + * Warning: This function may reallocate the skb data buffer via + * batadv_mcast_forw_expand_head(). Any pointer into the skb data (e.g. + * obtained from skb->data or eth_hdr()) before this call must be + * considered invalid afterwards and has to be reacquired. + * * Return: true on success, false otherwise. */ bool batadv_mcast_forw_push(struct batadv_priv *bat_priv, struct sk_buff *skb, diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c index cd290a7b..5193e370 100644 --- a/net/batman-adv/routing.c +++ b/net/batman-adv/routing.c @@ -172,6 +172,11 @@ bool batadv_window_protected(struct batadv_priv *bat_priv, s32 seq_num_diff, * @hard_iface: incoming hard interface * @header_len: minimal header length of packet type * + * Warning: This function may reallocate the skb data buffer via + * skb_cow() / skb_linearize(). Any pointer into the skb data (e.g. + * obtained from skb->data or eth_hdr()) before this call must be + * considered invalid afterwards and has to be reacquired. + * * Return: true when management preconditions are met, false otherwise */ bool batadv_check_management_packet(struct sk_buff *skb, --- base-commit: e8d6ecd5b27bf4ab6dfef96e01cd0057065ed396 change-id: 20260710-realloc-kernel-doc-87f99d90b802 Best regards, -- Sven Eckelmann <[email protected]>