Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] packet_snd() (net/packet/af_packet.c) can build an skb whose
network header lies past the end of the packet, on devices that have a…
--
packet: reset network header on all headerless devices
This replaces the min_header_len based heuristic in packet_snd() with a
!dev_has_header(dev) check before resetting the network header on
SOCK_RAW sends. It adds the same check to tpacket_fill_skb(). It also
switches packet_sendmsg_spkt() from dev->header_ops to
dev_has_header(dev).
> diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
> index 0ea3036bee249..4ff7a2cc11e54 100644
> --- a/net/packet/af_packet.c
> +++ b/net/packet/af_packet.c
[ ... ]
> @@ -3125,8 +3127,7 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
> goto out_free;
> } else if (reserve) {
> skb_reserve(skb, -reserve);
> - if (len < reserve + sizeof(struct ipv6hdr) &&
> - dev->min_header_len != hard_header_len)
> + if (!dev_has_header(dev))
> skb_reset_network_header(skb);
> }
>
[Severity: High]
Can this leave skb->network_header past the tail of the skb on devices
that have header_ops->create? GRE with ipgre_header_ops is one example.
packet_snd() reads the header length once and uses it for reserve:
hard_header_len = READ_ONCE(dev->hard_header_len);
if (sock->type == SOCK_RAW)
reserve = hard_header_len;
The later short packet check reads the device field again:
if ((sock->type == SOCK_RAW &&
len < READ_ONCE(dev->hard_header_len)) || !skb->len) {
On GRE, hard_header_len can shrink at runtime under RTNL, and
packet_snd() does not hold RTNL:
net/ipv4/ip_gre.c:ipgre_link_update() {
...
if (dev->header_ops)
dev->hard_header_len += len;
else
dev->needed_headroom += len;
...
}
This runs from ipgre_changelink() and ipgre_tunnel_ctl() when the
okey/csum/seq flags are cleared.
Take a saved value of 28 (GRE with key) and a user len of 24. If the
device value changes to 24 between the two reads, the 24 < 24 check
passes. The skb then has len 24 with network_header at data + 28.
The window between the two reads includes packet_alloc_skb(), which can
block on sndbuf. It also includes skb_copy_datagram_from_iter(), which
can fault.
Before this patch, the old condition reset the network header in this
case, because GRE leaves min_header_len at 0:
if (len < reserve + sizeof(struct ipv6hdr) &&
dev->min_header_len != hard_header_len)
That is the same protection commit 993675a3100b ("packet: reset network
header if packet shorter than ll reserved space") added for the case
where "skb->mac_len may exceed skb->len".
Suppose a clsact egress filter with a mirred ingress action is installed
on the GRE device. The skb would then reach:
__dev_queue_xmit()
sch_handle_egress()
tcf_mirred_to_dev()
net/sched/act_mirred.c:tcf_mirred_to_dev() {
...
expects_nh = want_ingress || !m_mac_header_xmit;
at_nh = skb->data == skb_network_header(skb);
if (at_nh != expects_nh) {
mac_len = at_ingress ? skb->mac_len :
skb_network_offset(skb);
if (expects_nh) {
skb_pull_rcsum(skb_to_send, mac_len);
...
}
Here mac_len is 28 and the clone has len 24, so skb_pull_rcsum() hits:
BUG_ON(len > skb->len);
On other paths, dev_queue_xmit_nit() would log "protocol %04x is buggy"
for this skb, and ipgre_xmit() would drop it in pskb_inet_may_pull().
The trigger needs CAP_NET_RAW and CAP_NET_ADMIN. An unprivileged user
can get both in a user namespace with its own netns.
The final state of the series ("net: remove unused
net_device::min_header_len") seems to have the same code here, so no
later patch fixes it.
Could len be checked against the saved hard_header_len, the value used
for reserve and linear, instead of re-reading dev->hard_header_len?
Alternatively, could the network header still be reset when
len < reserve?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/2026…%40google.com