mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [BUG] net: openvswitch: WARN_ONCE in ovs_fragment() reachable with a user-supplied MRU on a non-IP packet
@ 2026-11-17 15:12 Kyuwon Cho
  2026-11-18 17:39 ` Aaron Conole
  0 siblings, 1 reply; 3+ messages in thread
From: Kyuwon Cho @ 2026-11-17 15:12 UTC (permalink / raw)
  To: Aaron Conole, Eelco Chaudron, Ilya Maximets
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Simon Horman, netdev, dev, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2481 bytes --]

Hi Aaron, Eelco, Ilya,

While testing v7.4-rc3 with an LLM-guided test generator that we are
developing as a research prototype, we found that OVS_PACKET_CMD_EXECUTE
can trigger the WARN_ONCE() at the end of ovs_fragment(). An unprivileged
user can do this from its own user and network namespace:

  Failed fragment ->ovs0: eth=8847, MRU=500, MTU=1500.
  WARNING: net/openvswitch/actions.c:831 at ovs_fragment+0x239/0x840, CPU#1: test/106
  CPU: 1 UID: 65534 PID: 106 Comm: test Not tainted 7.4.0-rc3 #1 PREEMPT(lazy) 
  RIP: 0010:ovs_fragment+0x24e/0x840
  Call Trace:
   <TASK>
   do_execute_actions+0x580e/0x7380
   ovs_execute_actions+0xd3/0x3e0
   ovs_packet_cmd_execute+0xc21/0x13c0
   genl_family_rcv_msg_doit+0x1e0/0x2c0
   genl_rcv_msg+0x42d/0x6f0
   netlink_rcv_skb+0x11f/0x350
   genl_rcv+0x23/0x30
   netlink_unicast+0x518/0x870
   netlink_sendmsg+0x849/0xe20
   __sys_sendto+0x36a/0x3c0

OVS_PACKET_ATTR_MRU is taken from the request as is. In do_output(), a
packet longer than mru + hard_header_len goes to ovs_fragment() when mru
is not larger than the port's MTU. ovs_fragment() only handles IPv4 and
IPv6, and treats any other ethertype as a case that should not happen:

	} else {
		WARN_ONCE(1, "Failed fragment ->%s: eth=%04x, MRU=%d, MTU=%d.",
			  ovs_vport_name(vport), ntohs(key->eth.type), mru,
			  vport->dev->mtu);
		reason = OVS_DROP_FRAG_INVALID_PROTO;
		goto err;
	}

With an MRU in the request, any ethertype reaches it; we used MPLS
(0x8847). The packet is dropped either way, so the effect is the
warning, which panics a machine with panic_on_warn.

Dropping the packet with a rate-limited message instead of the WARN, as
fd954cc1919e ("openvswitch: switch from WARN to pr_warn") did for
ovs_dp_reset_user_features(), or checking the ethertype in do_output()
before calling ovs_fragment(), should avoid it. We have not tested either
change.

The reproducer runs as an unprivileged user (uid 65534) that creates a
user and network namespace, creates a datapath with an internal port,
and executes one 1434-byte Ethernet frame with ethertype 0x8847,
OVS_PACKET_ATTR_MRU 500 and an output action to that port. On an x86_64
QEMU guest with 2 vCPUs and KASAN (gcc 13.3, config attached), it warns
in every run (7 of 7).

Checked against v7.4-rc3 (aebb72744764); actions.c is the same in
net-next (6ff4c5942a30). We found no earlier report on syzbot or in a
web search.

The reproducer (repro.c) and the kernel config are attached.

Thanks,
Kyuwon Cho

[-- Attachment #2: repro.c --]
[-- Type: text/plain, Size: 4522 bytes --]

// WARNING in ovs_fragment: an unprivileged user executes an MPLS frame larger
// than the MRU it supplies, with output to an internal port of its own datapath.
#define _GNU_SOURCE
#include <arpa/inet.h>
#include <fcntl.h>
#include <linux/genetlink.h>
#include <linux/if_ether.h>
#include <linux/netlink.h>
#include <linux/openvswitch.h>
#include <net/if.h>
#include <sched.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <unistd.h>

static int fd;

static void put(char *buf, size_t *len, uint16_t type, const void *data, size_t dlen)
{
	struct nlattr *a = (struct nlattr *)(buf + *len);

	a->nla_type = type;
	a->nla_len = NLA_HDRLEN + dlen;
	memcpy((char *)a + NLA_HDRLEN, data, dlen);
	*len += NLA_ALIGN(a->nla_len);
}

/* Send one generic netlink request; return the reply in rb and the error. */
static int req(uint16_t fam, uint8_t cmd, uint32_t dp, const char *attrs, size_t alen, char *rb)
{
	char msg[8192] = {0};
	struct nlmsghdr *nh = (struct nlmsghdr *)msg;
	struct genlmsghdr *gh = (struct genlmsghdr *)NLMSG_DATA(nh);
	size_t off = NLMSG_HDRLEN + GENL_HDRLEN;

	gh->cmd = cmd;
	gh->version = 1;
	if (fam != GENL_ID_CTRL) {
		((struct ovs_header *)(msg + off))->dp_ifindex = dp;
		off += sizeof(struct ovs_header);
	}
	memcpy(msg + off, attrs, alen);
	nh->nlmsg_len = off + alen;
	nh->nlmsg_type = fam;
	nh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
	if (send(fd, msg, nh->nlmsg_len, 0) < 0)
		return -1;
	/* A reply, if any, comes before the ACK that NLM_F_ACK asks for. */
	for (;;) {
		if (recv(fd, msg, sizeof(msg), 0) < 0)
			return -1;
		if (nh->nlmsg_type == NLMSG_ERROR)
			return ((struct nlmsgerr *)NLMSG_DATA(nh))->error;
		memcpy(rb, msg, sizeof(msg));
	}
}

static uint16_t family(const char *name)
{
	char a[64], rb[8192];
	size_t al = 0;
	struct nlattr *na;

	put(a, &al, CTRL_ATTR_FAMILY_NAME, name, strlen(name) + 1);
	if (req(GENL_ID_CTRL, CTRL_CMD_GETFAMILY, 0, a, al, rb))
		exit(1);
	for (na = (struct nlattr *)(rb + NLMSG_HDRLEN + GENL_HDRLEN); na->nla_type != CTRL_ATTR_FAMILY_ID;
	     na = (struct nlattr *)((char *)na + NLA_ALIGN(na->nla_len)))
		;
	return *(uint16_t *)((char *)na + NLA_HDRLEN);
}

static void write_file(const char *path, const char *s)
{
	int f = open(path, O_WRONLY);

	if (f < 0 || write(f, s, strlen(s)) < 0)
		exit(1);
	close(f);
}

int main(void)
{
	char a[4096], key[256], act[64], rb[8192];
	uint8_t frame[1434] = {0};
	size_t al = 0, kl = 0, cl = 0;
	uint32_t pid = 0, type = OVS_VPORT_TYPE_INTERNAL, port = 1, dp;
	uint16_t fam_dp, fam_vport, fam_packet, et = htons(ETH_P_MPLS_UC), mru = 500;
	struct ovs_key_ethernet eth = {{0}};
	struct ifreq ifr = {0};
	char map[32];

	snprintf(map, sizeof(map), "0 %d 1", getuid());
	if (unshare(CLONE_NEWUSER | CLONE_NEWNET))
		return 1;
	write_file("/proc/self/setgroups", "deny");
	write_file("/proc/self/uid_map", map);
	snprintf(map, sizeof(map), "0 %d 1", getgid());
	write_file("/proc/self/gid_map", map);

	fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC);
	fam_dp = family(OVS_DATAPATH_FAMILY);
	fam_vport = family(OVS_VPORT_FAMILY);
	fam_packet = family(OVS_PACKET_FAMILY);

	put(a, &al, OVS_DP_ATTR_NAME, "dp0", 4);
	put(a, &al, OVS_DP_ATTR_UPCALL_PID, &pid, 4);
	printf("datapath: %d\n", req(fam_dp, OVS_DP_CMD_NEW, 0, a, al, rb));
	dp = if_nametoindex("dp0");

	al = 0;
	put(a, &al, OVS_VPORT_ATTR_NAME, "ovs0", 5);
	put(a, &al, OVS_VPORT_ATTR_TYPE, &type, 4);
	put(a, &al, OVS_VPORT_ATTR_PORT_NO, &port, 4);
	put(a, &al, OVS_VPORT_ATTR_UPCALL_PID, &pid, 4);
	printf("vport: %d\n", req(fam_vport, OVS_VPORT_CMD_NEW, dp, a, al, rb));
	strcpy(ifr.ifr_name, "ovs0");
	ifr.ifr_flags = IFF_UP;
	ioctl(socket(AF_INET, SOCK_DGRAM, 0), SIOCSIFFLAGS, &ifr);

	/* An Ethernet frame with an MPLS ethertype, longer than the MRU below. */
	frame[0] = 0x02;
	frame[11] = 0x02;
	memcpy(frame + 12, &et, 2);
	memset(frame + 14, 0x41, sizeof(frame) - 14);
	memcpy(eth.eth_dst, frame, 6);
	memcpy(eth.eth_src, frame + 6, 6);
	put(key, &kl, OVS_KEY_ATTR_ETHERNET, &eth, sizeof(eth));
	put(key, &kl, OVS_KEY_ATTR_ETHERTYPE, &et, 2);
	put(key, &kl, OVS_KEY_ATTR_IN_PORT, &pid, 4);
	put(act, &cl, OVS_ACTION_ATTR_OUTPUT, &port, 4);

	al = 0;
	put(a, &al, OVS_PACKET_ATTR_PACKET, frame, sizeof(frame));
	put(a, &al, OVS_PACKET_ATTR_KEY, key, kl);
	put(a, &al, OVS_PACKET_ATTR_ACTIONS, act, cl);
	put(a, &al, OVS_PACKET_ATTR_MRU, &mru, 2);
	printf("execute: %d\n", req(fam_packet, OVS_PACKET_CMD_EXECUTE, dp, a, al, rb));
	return 0;
}

[-- Attachment #3: config.gz --]
[-- Type: application/gzip, Size: 37687 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [BUG] net: openvswitch: WARN_ONCE in ovs_fragment() reachable with a user-supplied MRU on a non-IP packet
  2026-11-17 15:12 [BUG] net: openvswitch: WARN_ONCE in ovs_fragment() reachable with a user-supplied MRU on a non-IP packet Kyuwon Cho
@ 2026-11-18 17:39 ` Aaron Conole
  2026-11-18 18:06   ` [PATCH net] net: openvswitch: don't WARN on a non-IP packet that needs fragmenting Kyuwon Cho
  0 siblings, 1 reply; 3+ messages in thread
From: Aaron Conole @ 2026-11-18 17:39 UTC (permalink / raw)
  To: Kyuwon Cho
  Cc: Eelco Chaudron, Ilya Maximets, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Simon Horman, netdev, dev,
	linux-kernel

Hi,

Kyuwon Cho <kyuwoncho18@gmail.com> writes:

> Hi Aaron, Eelco, Ilya,
>
> While testing v7.4-rc3 with an LLM-guided test generator that we are
> developing as a research prototype, we found that OVS_PACKET_CMD_EXECUTE
> can trigger the WARN_ONCE() at the end of ovs_fragment(). An unprivileged
> user can do this from its own user and network namespace:
>
>   Failed fragment ->ovs0: eth=8847, MRU=500, MTU=1500.
>   WARNING: net/openvswitch/actions.c:831 at ovs_fragment+0x239/0x840, CPU#1: test/106
>   CPU: 1 UID: 65534 PID: 106 Comm: test Not tainted 7.4.0-rc3 #1 PREEMPT(lazy) 
>   RIP: 0010:ovs_fragment+0x24e/0x840
>   Call Trace:
>    <TASK>
>    do_execute_actions+0x580e/0x7380
>    ovs_execute_actions+0xd3/0x3e0
>    ovs_packet_cmd_execute+0xc21/0x13c0
>    genl_family_rcv_msg_doit+0x1e0/0x2c0
>    genl_rcv_msg+0x42d/0x6f0
>    netlink_rcv_skb+0x11f/0x350
>    genl_rcv+0x23/0x30
>    netlink_unicast+0x518/0x870
>    netlink_sendmsg+0x849/0xe20
>    __sys_sendto+0x36a/0x3c0
>
> OVS_PACKET_ATTR_MRU is taken from the request as is. In do_output(), a
> packet longer than mru + hard_header_len goes to ovs_fragment() when mru
> is not larger than the port's MTU. ovs_fragment() only handles IPv4 and
> IPv6, and treats any other ethertype as a case that should not happen:
>
> 	} else {
> 		WARN_ONCE(1, "Failed fragment ->%s: eth=%04x, MRU=%d, MTU=%d.",
> 			  ovs_vport_name(vport), ntohs(key->eth.type), mru,
> 			  vport->dev->mtu);
> 		reason = OVS_DROP_FRAG_INVALID_PROTO;
> 		goto err;
> 	}
>
> With an MRU in the request, any ethertype reaches it; we used MPLS
> (0x8847). The packet is dropped either way, so the effect is the
> warning, which panics a machine with panic_on_warn.
>
> Dropping the packet with a rate-limited message instead of the WARN, as
> fd954cc1919e ("openvswitch: switch from WARN to pr_warn") did for
> ovs_dp_reset_user_features(), or checking the ethertype in do_output()
> before calling ovs_fragment(), should avoid it. We have not tested either
> change.
>
> The reproducer runs as an unprivileged user (uid 65534) that creates a
> user and network namespace, creates a datapath with an internal port,
> and executes one 1434-byte Ethernet frame with ethertype 0x8847,
> OVS_PACKET_ATTR_MRU 500 and an output action to that port. On an x86_64
> QEMU guest with 2 vCPUs and KASAN (gcc 13.3, config attached), it warns
> in every run (7 of 7).
>
> Checked against v7.4-rc3 (aebb72744764); actions.c is the same in
> net-next (6ff4c5942a30). We found no earlier report on syzbot or in a
> web search.
>
> The reproducer (repro.c) and the kernel config are attached.

We can change it, and I think it makes sense.  A ratelimited warn seems
appropriate.

Did the LLM already generate a patch for the issue?  That would helpful.

> Thanks,
> Kyuwon Cho


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH net] net: openvswitch: don't WARN on a non-IP packet that needs fragmenting
  2026-11-18 17:39 ` Aaron Conole
@ 2026-11-18 18:06   ` Kyuwon Cho
  0 siblings, 0 replies; 3+ messages in thread
From: Kyuwon Cho @ 2026-11-18 18:06 UTC (permalink / raw)
  To: Aaron Conole
  Cc: Eelco Chaudron, Ilya Maximets, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Simon Horman, netdev, dev,
	linux-kernel

ovs_fragment() only handles IPv4 and IPv6 and drops any other packet
with a WARN_ONCE(). Since OVS_PACKET_CMD_EXECUTE takes the MRU from
userspace, any ethertype can get there, e.g. an MPLS packet executed by
an unprivileged user in its own user and network namespace:

  Failed fragment ->ovs0: eth=8847, MRU=500, MTU=1500.
  WARNING: net/openvswitch/actions.c:831 at ovs_fragment+0x239/0x840, CPU#1: test/106
  Call Trace:
   do_execute_actions+0x580e/0x7380
   ovs_execute_actions+0xd3/0x3e0
   ovs_packet_cmd_execute+0xc21/0x13c0

The packet is dropped either way, so use a rate-limited warning instead.

Fixes: 7f8a436eaa2c ("openvswitch: Add conntrack action")
Closes: https://lore.kernel.org/netdev/179492834266.3639154.14679778183890331729@gmail.com/
Signed-off-by: Kyuwon Cho <kyuwoncho18@gmail.com>
---
Aaron, here is the patch, with the rate-limited warning you suggested.
It was written with LLM assistance; we reviewed and tested it. With it
applied on net, the reproducer from the report prints the message
instead of warning.

 net/openvswitch/actions.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/net/openvswitch/actions.c b/net/openvswitch/actions.c
index 12e339cbf791..bf3f2b328b53 100644
--- a/net/openvswitch/actions.c
+++ b/net/openvswitch/actions.c
@@ -828,9 +828,9 @@ static void ovs_fragment(struct net *net, struct vport *vport,
 		ip6_fragment(net, skb->sk, skb, ovs_vport_output);
 		refdst_drop(orig_dst);
 	} else {
-		WARN_ONCE(1, "Failed fragment ->%s: eth=%04x, MRU=%d, MTU=%d.",
-			  ovs_vport_name(vport), ntohs(key->eth.type), mru,
-			  vport->dev->mtu);
+		net_warn_ratelimited("Failed fragment ->%s: eth=%04x, MRU=%d, MTU=%d.\n",
+				     ovs_vport_name(vport), ntohs(key->eth.type),
+				     mru, vport->dev->mtu);
 		reason = OVS_DROP_FRAG_INVALID_PROTO;
 		goto err;
 	}

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-18 18:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-17 15:12 [BUG] net: openvswitch: WARN_ONCE in ovs_fragment() reachable with a user-supplied MRU on a non-IP packet Kyuwon Cho
2026-11-18 17:39 ` Aaron Conole
2026-11-18 18:06   ` [PATCH net] net: openvswitch: don't WARN on a non-IP packet that needs fragmenting Kyuwon Cho

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®