Skip to content

Commit 82081e8

Browse files
Merge pull request #9225 from mheon/fix_CVE-2021-20199_30
Fix CVE-2021-20199 for Podman v3.0
2 parents c2a298e + f11aabd commit 82081e8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+893
-134
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ require (
4949
github.com/opentracing/opentracing-go v1.2.0
5050
github.com/pkg/errors v0.9.1
5151
github.com/pmezard/go-difflib v1.0.0
52-
github.com/rootless-containers/rootlesskit v0.11.1
52+
github.com/rootless-containers/rootlesskit v0.12.0
5353
github.com/sirupsen/logrus v1.7.0
5454
github.com/spf13/cobra v1.1.1
5555
github.com/spf13/pflag v1.0.5
@@ -63,7 +63,7 @@ require (
6363
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad
6464
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect
6565
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9
66-
golang.org/x/sys v0.0.0-20201218084310-7d0127a74742
66+
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4
6767
google.golang.org/appengine v1.6.6 // indirect
6868
gopkg.in/square/go-jose.v2 v2.5.1 // indirect
6969
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect

go.sum

Lines changed: 38 additions & 9 deletions
Large diffs are not rendered by default.

libpod/container_internal_linux.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,7 +1735,7 @@ func (c *Container) generateResolvConf() (string, error) {
17351735
nameservers = resolvconf.GetNameservers(resolv.Content)
17361736
// slirp4netns has a built in DNS server.
17371737
if c.config.NetMode.IsSlirp4netns() {
1738-
nameservers = append([]string{"10.0.2.3"}, nameservers...)
1738+
nameservers = append([]string{slirp4netnsDNS}, nameservers...)
17391739
}
17401740
}
17411741

@@ -1815,7 +1815,7 @@ func (c *Container) getHosts() string {
18151815
if c.Hostname() != "" {
18161816
if c.config.NetMode.IsSlirp4netns() {
18171817
// When using slirp4netns, the interface gets a static IP
1818-
hosts += fmt.Sprintf("# used by slirp4netns\n%s\t%s %s\n", "10.0.2.100", c.Hostname(), c.config.Name)
1818+
hosts += fmt.Sprintf("# used by slirp4netns\n%s\t%s %s\n", slirp4netnsIP, c.Hostname(), c.config.Name)
18191819
} else {
18201820
hasNetNS := false
18211821
netNone := false

libpod/networking_linux.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ import (
3535
"golang.org/x/sys/unix"
3636
)
3737

38+
const (
39+
// slirp4netnsIP is the IP used by slirp4netns to configure the tap device
40+
// inside the network namespace.
41+
slirp4netnsIP = "10.0.2.100"
42+
43+
// slirp4netnsDNS is the IP for the built-in DNS server in the slirp network
44+
slirp4netnsDNS = "10.0.2.3"
45+
)
46+
3847
// Get an OCICNI network config
3948
func (r *Runtime) getPodNetwork(id, name, nsPath string, networks []string, ports []ocicni.PortMapping, staticIP net.IP, staticMAC net.HardwareAddr, netDescriptions ContainerNetworkDescriptions) ocicni.PodNetwork {
4049
var networkKey string
@@ -547,6 +556,7 @@ func (r *Runtime) setupRootlessPortMappingViaRLK(ctr *Container, netnsPath strin
547556
ExitFD: 3,
548557
ReadyFD: 4,
549558
TmpDir: ctr.runtime.config.Engine.TmpDir,
559+
ChildIP: slirp4netnsIP,
550560
}
551561
cfgJSON, err := json.Marshal(cfg)
552562
if err != nil {

pkg/rootlessport/rootlessport_linux.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ type Config struct {
4848
ExitFD int
4949
ReadyFD int
5050
TmpDir string
51+
ChildIP string
5152
}
5253

5354
func init() {
@@ -227,7 +228,7 @@ outer:
227228

228229
// let parent expose ports
229230
logrus.Infof("exposing ports %v", cfg.Mappings)
230-
if err := exposePorts(driver, cfg.Mappings); err != nil {
231+
if err := exposePorts(driver, cfg.Mappings, cfg.ChildIP); err != nil {
231232
return err
232233
}
233234

@@ -248,7 +249,7 @@ outer:
248249
return nil
249250
}
250251

251-
func exposePorts(pm rkport.Manager, portMappings []ocicni.PortMapping) error {
252+
func exposePorts(pm rkport.Manager, portMappings []ocicni.PortMapping, childIP string) error {
252253
ctx := context.TODO()
253254
for _, i := range portMappings {
254255
hostIP := i.HostIP
@@ -260,6 +261,7 @@ func exposePorts(pm rkport.Manager, portMappings []ocicni.PortMapping) error {
260261
ParentIP: hostIP,
261262
ParentPort: int(i.HostPort),
262263
ChildPort: int(i.ContainerPort),
264+
ChildIP: childIP,
263265
}
264266
if err := rkportutil.ValidatePortSpec(spec, nil); err != nil {
265267
return err

test/system/500-networking.bats

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,31 @@ load helpers
6565
myport=54321
6666

6767
# Container will exit as soon as 'nc' receives input
68+
# We use '-n -v' to give us log messages showing an incoming connection
69+
# and its IP address; the purpose of that is guaranteeing that the
70+
# remote IP is not 127.0.0.1 (podman PR #9052).
71+
# We could get more parseable output by using $NCAT_REMOTE_ADDR,
72+
# but busybox nc doesn't support that.
6873
run_podman run -d --userns=keep-id -p 127.0.0.1:$myport:$myport \
69-
$IMAGE nc -l -p $myport
74+
$IMAGE nc -l -n -v -p $myport
7075
cid="$output"
7176

7277
# emit random string, and check it
7378
teststring=$(random_string 30)
7479
echo "$teststring" | nc 127.0.0.1 $myport
7580

7681
run_podman logs $cid
77-
is "$output" "$teststring" "test string received on container"
82+
# Sigh. We can't check line-by-line, because 'nc' output order is
83+
# unreliable. We usually get the 'connect to' line before the random
84+
# string, but sometimes we get it after. So, just do substring checks.
85+
is "$output" ".*listening on \[::\]:$myport .*" "nc -v shows right port"
86+
87+
# This is the truly important check: make sure the remote IP is
88+
# in the 10.X range, not 127.X.
89+
is "$output" \
90+
".*connect to \[::ffff:10\..*\]:$myport from \[::ffff:10\..*\]:.*" \
91+
"nc -v shows remote IP address in 10.X space (not 127.0.0.1)"
92+
is "$output" ".*${teststring}.*" "test string received on container"
7893

7994
# Clean up
8095
run_podman rm $cid

vendor/github.com/rootless-containers/rootlesskit/pkg/port/builtin/child/child.go

Lines changed: 15 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/rootless-containers/rootlesskit/pkg/port/builtin/msg/msg.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/rootless-containers/rootlesskit/pkg/port/port.go

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/rootless-containers/rootlesskit/pkg/port/portutil/portutil.go

Lines changed: 36 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)