Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parseIptunData caused index out of range panic #509

Closed
AirbornWdd opened this issue Jan 15, 2020 · 5 comments · Fixed by #512
Closed

parseIptunData caused index out of range panic #509

AirbornWdd opened this issue Jan 15, 2020 · 5 comments · Fixed by #512

Comments

@AirbornWdd
Copy link

The ip link command dump:

13: tunl0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ipip 0.0.0.0 brd 0.0.0.0
14: ipip0@NONE: <NOARP,UP,LOWER_UP> mtu 1480 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/ipip 0.0.0.0 brd 0.0.0.0
15: ip6tnl0@NONE: <NOARP> mtu 1452 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/tunnel6 :: brd ::
16: ipip60@NONE: <NOARP,UP,LOWER_UP> mtu 1452 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/tunnel6 :: brd ::

The panic backtrace are:

panic: runtime error: index out of range

 github.com/vishvananda/netlink.parseIptunData(0xcc4b40, 0xc000214580, 0xc00028ee00, 0xd, 0x10)
         /go/src/github.com/vishvananda/netlink/link_linux.go:2580 +0x2c1
 github.com/vishvananda/netlink.LinkDeserialize(0x0, 0xc00028497c, 0x590, 0x113c, 0x9, 0xc00028c700, 0x8, 0x10)
         /go/src/github.com/vishvananda/netlink/link_linux.go:1608 +0x1482
 github.com/vishvananda/netlink.(*Handle).LinkList(0x1359fd0, 0xbff8b3, 0x9, 0x21a, 0xc000034f70, 0xc000034f00)
         /go/src/github.com/vishvananda/netlink/link_linux.go:1813 +0x2e6
 github.com/vishvananda/netlink.LinkList(...)
         /go/src/github.com/vishvananda/netlink/link_linux.go:1791

@AirbornWdd
Copy link
Author

AirbornWdd commented Jan 15, 2020

dlv dumps:

(dlv) bt
 0  0x00000000009772c3 in github.com/vishvananda/netlink.parseIptunData
    at /go/src/github.com/vishvananda/netlink/link_linux.go:2557
 1  0x000000000096b7e2 in github.com/vishvananda/netlink.LinkDeserialize
    at /go/src/github.com/vishvananda/netlink/link_linux.go:1608
 2  0x000000000096de96 in github.com/vishvananda/netlink.(*Handle).LinkList
    at /go/src/github.com/vishvananda/netlink/link_linux.go:1813
 3  0x00000000009b97e7 in github.com/vishvananda/netlink.LinkList
    at /go/src/github.com/vishvananda/netlink/link_linux.go:1791
…………
 8  0x00000000009da72b in main.main
    at /go/src/xlb/main.go:53
 9  0x00000000004fdb1c in runtime.main
    at /usr/local/go/src/runtime/proc.go:200
10  0x000000000052b3a1 in runtime.goexit
    at /usr/local/go/src/runtime/asm_amd64.s:1337
(dlv) locals
attrs = (unreadable read out of bounds)
(err) = (unreadable could not find loclist entry at 0x35ffdb for address 0x96b7e2)
base = github.com/vishvananda/netlink.LinkAttrs {Index: 14, MTU: 1480, TxQLen: 1000,...+22 more}
link = github.com/vishvananda/netlink.Link(*github.com/vishvananda/netlink.Iptun) 0xbeef0008
stats32 = (unreadable could not find loclist entry at 0x35fb09 for address 0x96b7e2)
stats64 = ("*github.com/vishvananda/netlink.LinkStatistics64")(0xc00026ed80)
linkType = "ipip"
linkSlave = github.com/vishvananda/netlink.LinkSlave nil
slaveType = ""
infos = (unreadable empty OP stack)
(err) = (unreadable could not find loclist entry at 0x36017b for address 0x96b7e2)
data = []syscall.NetlinkRouteAttr len: 13, cap: 16, [...]
err = (unreadable could not find loclist entry at 0x3602c3 for address 0x96b7e2)
(dlv) p data[12]
syscall.NetlinkRouteAttr {
        Attr: syscall.RtAttr {Len: 4, Type: 19},
        Value: []uint8 len: 0, cap: 3756, [],}
(dlv) p link
github.com/vishvananda/netlink.Link(*github.com/vishvananda/netlink.Iptun) *{
        LinkAttrs: github.com/vishvananda/netlink.LinkAttrs {
                Index: 0,
                MTU: 0,
                TxQLen: 0,
                Name: "",
                HardwareAddr: net.HardwareAddr len: 0, cap: 0, nil,
                Flags: 0,
                RawFlags: 0,
                ParentIndex: 0,
                MasterIndex: 0,
                Namespace: interface {} nil,
                Alias: "",
                Statistics: *github.com/vishvananda/netlink.LinkStatistics nil,
                Promisc: 0,
                Xdp: *github.com/vishvananda/netlink.LinkXdp nil,
                EncapType: "",
                Protinfo: *github.com/vishvananda/netlink.Protinfo nil,
                OperState: 0,
                NetNsID: 0,
                NumTxQueues: 0,
                NumRxQueues: 0,
                GSOMaxSize: 0,
                GSOMaxSegs: 0,
                Vfs: []github.com/vishvananda/netlink.VfInfo len: 0, cap: 0, nil,
                Group: 0,
                Slave: github.com/vishvananda/netlink.LinkSlave nil,},
        Ttl: 0,
        Tos: 0,
        PMtuDisc: 0,
        Link: 0,
        Local: net.IP len: 0, cap: 0, nil,
        Remote: net.IP len: 0, cap: 0, nil,
        EncapSport: 0,
        EncapDport: 0,
        EncapType: 0,
        EncapFlags: 0,
        FlowBased: false,}
(dlv)

@vishvananda
Copy link
Owner

Looks like

iptun.FlowBased = int8(datum.Value[0]) != 0
can have an empty value. I guess that line should be wrapped in a:
if len(datum.Value) != 0

@AirbornWdd
Copy link
Author

AirbornWdd commented Jun 3, 2020

Looks like

iptun.FlowBased = int8(datum.Value[0]) != 0

can have an empty value. I guess that line should be wrapped in a:
if len(datum.Value) != 0

Not only vxlan interface has the issue, all tunnel interface should be checked. Is this OK ?

diff --git a/link_linux.go b/link_linux.go
index 72eb13d..4dd4c0f 100644
--- a/link_linux.go
+++ b/link_linux.go
@@ -2561,6 +2561,9 @@ func addIptunAttrs(iptun *Iptun, linkInfo *nl.RtAttr) {
 func parseIptunData(link Link, data []syscall.NetlinkRouteAttr) {
        iptun := link.(*Iptun)
        for _, datum := range data {
+               if len(datum.Value) == 0 {
+                       continue
+               }
                switch datum.Attr.Type {
                case nl.IFLA_IPTUN_LOCAL:
                        iptun.Local = net.IP(datum.Value[0:4])

@vishvananda
Copy link
Owner

This looks fine. Did you want to propose a change? Or shall i do it

@vishvananda vishvananda reopened this Jun 17, 2020
vishvananda added a commit that referenced this issue Jun 17, 2020
The first fix #512 apparently didn't solve all cases. This generically
skips values that are null to solve the problem. Also closes #548.
vishvananda added a commit that referenced this issue Jun 17, 2020
The first fix #512 apparently didn't solve all cases. This generically
skips values that are null to solve the problem. Also closes #548.
vishvananda added a commit that referenced this issue Jun 18, 2020
The first fix #512 apparently didn't solve all cases. This generically
skips values that are null to solve the problem. Also closes #548.
@AirbornWdd
Copy link
Author

This looks fine. Did you want to propose a change? Or shall i do it

I think you can do it. ;-)

vishvananda added a commit that referenced this issue Sep 14, 2020
The first fix #512 apparently didn't solve all cases. This generically
skips values that are null to solve the problem. Also closes #548.
Dongdong-Wang added a commit to Dongdong-Wang/netlink that referenced this issue May 6, 2021
aboch pushed a commit that referenced this issue May 8, 2021
Signed-off-by: Dongdong Wang <[email protected]>
aojea pushed a commit to aojea/netlink that referenced this issue May 8, 2021
gkodali-zededa pushed a commit to gkodali-zededa/netlink that referenced this issue May 21, 2021
gkodali-zededa pushed a commit to gkodali-zededa/netlink that referenced this issue May 21, 2021
The first fix vishvananda#512 apparently didn't solve all cases. This generically
skips values that are null to solve the problem. Also closes vishvananda#548.
gkodali-zededa pushed a commit to gkodali-zededa/netlink that referenced this issue May 21, 2021
cyberys pushed a commit to cyberys/netlink that referenced this issue Apr 5, 2022
cjmakes pushed a commit to cjmakes/netlink that referenced this issue Jun 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants