Closed fuweid closed 2 years ago
Merging #82 (0e59b3d) into main (06e386d) will increase coverage by
0.84%
. The diff coverage is100.00%
.
@@ Coverage Diff @@
## main #82 +/- ##
==========================================
+ Coverage 44.24% 45.08% +0.84%
==========================================
Files 9 9
Lines 391 397 +6
==========================================
+ Hits 173 179 +6
Misses 184 184
Partials 34 34
Impacted Files | Coverage Δ | |
---|---|---|
cni.go | 72.72% <100.00%> (+1.42%) |
:arrow_up: |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact)
,ø = not affected
,? = missing data
Powered by Codecov. Last update 06e386d...0e59b3d. Read the comment docs.
Thanks @fuweid great catch
Before this patch, the package doesn't init CNIConfig.exec field. It is lazy init by CNIConfig.ensureExec() during AddNetworkList. After enhancement [1] , there are always more than two goroutines(one for loopback and other one for eth0) to call ensureExec(). Go runtime doesn't ensure that value-assignment is atomic, and then it is possible to use nil and panic, like [2].
I think it should be fixed in github.com/containernetworking/cni library but we need to delivery containerd release 1.6 version in time. I would like to init CNIConfig like what the
ensureExec()
[3] does instead of lazy init.How to reproduce it:
And run it
Root Cause:
The panic meesage is
main.(*rawExec).FindInPath(0x0, 0x0)
which means that the interfaceexec
var has the underly typerawExec
but its value is zeroFindInPath(0x0
, like what [2] mentioned.Since there are multiple goroutines to check
c.exec == nil
, if the lazy-init only assigns iface.tab and the FindInPath TEXT address, interface's value is still nil and the FindInPath will use the interface's value as method receiver. It will panic if try to read the value from receiver.Reference:
[1] https://github.com/containerd/go-cni/pull/76 [2] https://github.com/moby/buildkit/pull/2589#issuecomment-1032012405 [3] https://github.com/containernetworking/cni/blob/1694fd7b57e0176a98a12823a5ffc03337fdc152/libcni/api.go#L182
Fixes: #76
Signed-off-by: Wei Fu fuweid89@gmail.com