RTM_NEWROUTE accepts RTA_DST with neither a gateway nor RTA_OIF
Author: dany74qCreated Sep 24, 2026Updated Sep 24, 2026
localRoute checks for a missing gateway only when RTA_DST is absent (pkg/sentry/socket/netstack/stack.go:1046) and takes the route's NIC from RTA_OIF alone (stack.go:1074), so an RTM_NEWROUTE request with RTA_DST but neither RTA_GATEWAY nor RTA_OIF adds a route on NIC 0, which route lookup skips (pkg/tcpip/stack/stack.go:1684), where Linux v7.2 returns ENODEV for such a unicast route (net/ipv4/fib_semantics.c:1279, net/ipv6/route.c:3673).
ip -4 route add default and ip -6 route add default send that request, so they succeed inside the sandbox and add a default route that no packet takes.
#define _GNU_SOURCE
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
#include <netinet/in.h>
#include <sched.h>
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
int main(void) {
unshare(CLONE_NEWNET);
int fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
int families[] = {AF_INET, AF_INET6};
for (int i = 0; i < 2; i++) {
int len = families[i] == AF_INET ? 4 : 16;
struct {
struct nlmsghdr hdr;
struct rtmsg rtm;
struct rtattr rta;
struct in6_addr dst;
} req = {};
req.hdr.nlmsg_len = NLMSG_LENGTH(sizeof(req.rtm)) + RTA_LENGTH(len);
req.hdr.nlmsg_type = RTM_NEWROUTE;
req.hdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK | NLM_F_CREATE;
req.hdr.nlmsg_seq = i + 1;
req.rtm.rtm_family = families[i];
req.rtm.rtm_table = RT_TABLE_MAIN;
req.rtm.rtm_protocol = RTPROT_BOOT;
req.rtm.rtm_type = RTN_UNICAST;
req.rta.rta_type = RTA_DST;
req.rta.rta_len = RTA_LENGTH(len);
send(fd, &req, req.hdr.nlmsg_len, 0);
char buf[4096];
recv(fd, buf, sizeof(buf), 0);
struct nlmsgerr* ack = NLMSG_DATA((struct nlmsghdr*)buf);
printf("%s, RTA_DST 0/0 without RTA_GATEWAY or RTA_OIF: %s\n",
families[i] == AF_INET ? "AF_INET" : "AF_INET6",
strerror(-ack->error));
}
return 0;
}Proposed fix in #14971.
Source: google/gvisor