While creating jails with parameters ip4 or ip6 set to inherit, the jails's IPv4 or IPv6 addresses are not properly copied from parent.
Fixes: eb8dcdeac22d jail: network epoch protection for IP address lists
Differential D37871
jail: Fix wrong IPv[46] addresses inherited from parent jail zlei on Dec 25 2022, 5:49 PM. Authored by Tags None Referenced Files
Subscribers
Details While creating jails with parameters ip4 or ip6 set to inherit, the jails's IPv4 or IPv6 addresses are not properly copied from parent. Fixes: eb8dcdeac22d jail: network epoch protection for IP address lists Run the following script: #!/bin/sh ifconfig lo0 inet 172.16.0.1/32 alias ifconfig lo0 inet 172.16.0.2/32 alias ifconfig lo0 inet6 2001:db8::1/128 alias ifconfig lo0 inet6 2001:db8::2/128 alias jail -c name=parent host.hostname=parent path=/ persist children.max=1 ip4.addr=172.16.0.1 ip4.addr=172.16.0.2 ip6.addr=2001:db8::1 ip6.addr=2001:db8::2 jexec parent /bin/sh -s stdin << EOF jail -c name=c1 host.hostname=c1 path=/ persist ip4=inherit ip6=inherit sleep 1 jls -j c1 jexec c1 ifconfig lo0 EOF Verify the output: JID IP Address Hostname Path 4 172.16.0.1 c1 / lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384 options=680003<RXCSUM,TXCSUM,LINKSTATE,RXCSUM_IPV6,TXCSUM_IPV6> inet6 2001:db8::1 prefixlen 128 inet6 2001:db8::2 prefixlen 128 inet 172.16.0.1 netmask 0xffffffff inet 172.16.0.2 netmask 0xffffffff groups: lo nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL> Could also verify via DDB show prison
Diff Detail
Event Timeline
Comment Actions The problem isn't in the beginning and end of bcopy, it is in the size, which doesn't account for the header structure itself. The code should be: bcopy(ppr->pr_addrs[af], pr->pr_addrs[af], sizeof(struct prison_ip) + pr->pr_addrs[af]->ips * pr_families[af].size); Thanks for finding this problem. I guess it was a hard one to nail down. Comment Actions On the second thought, your code is better than mine since we don't want to intentionally overwrite the header which was already correctly initialized by prison_ip_alloc() (although we overwrite with the same values). Given that you also find several instances of this mistake, I'd suggest to go around all code that does copying and substitute: (pip + 1) to PR_IP(pip, 0). What do you think? Comment Actions I meant: first fix all code that uses pip, but must be pip + 1 into PR_IP(pip, 0), and then substitute that is already correct (pip + 1) into PR_IP(pip, 0). Comment Actions PR_IP(pip, 0) sounds copying the first one only, actually we are copying arrays of addresses. I'd prefer D37874 rather than pip + 1 or PR_IP(pip, 0) . |