vishvananda / netlink

Simple netlink library for go.
Apache License 2.0
2.86k stars 745 forks source link

`GenlFamilyList()`: `fatal error: checkptr: converted pointer straddles multiple allocations` #720

Open qdm12 opened 2 years ago

qdm12 commented 2 years ago

There is a race issue in the GenlFamilyList() function.

Reproduction:

package main

import (
    "testing"

    "github.com/vishvananda/netlink"
)

func Test(t *testing.T) {
    _, _ = netlink.GenlFamilyList()
}

And run the test with the race detector enabled:

CGO_ENABLED=1 go test -race -run ^Test$ .

(this is running on an Alpine host)

Gives logs

fatal error: checkptr: converted pointer straddles multiple allocations

goroutine 19 [running]:
runtime.throw({0x5c457a, 0x57bdc2})
        /usr/local/go/src/runtime/panic.go:1198 +0x71 fp=0xc000052a30 sp=0xc000052a00 pc=0x466ff1
runtime.checkptrAlignment(0x18, 0x58f940, 0x57cf01)
        /usr/local/go/src/runtime/checkptr.go:26 +0x6c fp=0xc000052a50 sp=0xc000052a30 pc=0x438d6c
github.com/vishvananda/netlink/nl.(*Genlmsg).Serialize(0xc0000c046e)
        /go/pkg/mod/github.com/vishvananda/netlink@v1.1.1-0.20211129163951-9ada19101fc5/nl/genetlink_linux.go:88 +0x3b fp=0xc000052a78 sp=0xc000052a50 pc=0x57b9fb
github.com/vishvananda/netlink/nl.(*NetlinkRequest).Serialize(0xc0000a6190)
        /go/pkg/mod/github.com/vishvananda/netlink@v1.1.1-0.20211129163951-9ada19101fc5/nl/nl_linux.go:378 +0x382 fp=0xc000052b48 sp=0xc000052a78 pc=0x57bdc2
github.com/vishvananda/netlink/nl.(*NetlinkSocket).Send(0xc0000a0060, 0x50fa2c)
        /go/pkg/mod/github.com/vishvananda/netlink@v1.1.1-0.20211129163951-9ada19101fc5/nl/nl_linux.go:650 +0x54 fp=0xc000052bc0 sp=0xc000052b48 pc=0x57cfb4
github.com/vishvananda/netlink/nl.(*NetlinkRequest).Execute(0xc0000a6190, 0x0, 0x0)
        /go/pkg/mod/github.com/vishvananda/netlink@v1.1.1-0.20211129163951-9ada19101fc5/nl/nl_linux.go:446 +0x32a fp=0xc000052de0 sp=0xc000052bc0 pc=0x57c20a
github.com/vishvananda/netlink.(*Handle).GenlFamilyList(0xc000052e78)
        /go/pkg/mod/github.com/vishvananda/netlink@v1.1.1-0.20211129163951-9ada19101fc5/genetlink_linux.go:136 +0x1a5 fp=0xc000052e80 sp=0xc000052de0 pc=0x57ee05
github.com/vishvananda/netlink.GenlFamilyList(...)
        /go/pkg/mod/github.com/vishvananda/netlink@v1.1.1-0.20211129163951-9ada19101fc5/genetlink_linux.go:144
github.com/qdm12/mytestrepo.Test(0x0)
        /workspace/my_test.go:10 +0x37 fp=0xc000052e98 sp=0xc000052e80 pc=0x580fd7
testing.tRunner(0xc0000836c0, 0x5c5198)
        /usr/local/go/src/testing/testing.go:1259 +0x230 fp=0xc000052fb0 sp=0xc000052e98 pc=0x50fc10
testing.(*T).Run·dwrap·21()
        /usr/local/go/src/testing/testing.go:1306 +0x48 fp=0xc000052fe0 sp=0xc000052fb0 pc=0x5111a8
runtime.goexit()
        /usr/local/go/src/runtime/asm_amd64.s:1581 +0x1 fp=0xc000052fe8 sp=0xc000052fe0 pc=0x4985e1
created by testing.(*T).Run
        /usr/local/go/src/testing/testing.go:1306 +0x727

goroutine 1 [chan receive]:
testing.(*T).Run(0xc000083520, {0x5ba6b4, 0x4}, 0x5c5198)
        /usr/local/go/src/testing/testing.go:1307 +0x752
testing.runTests.func1(0x0)
        /usr/local/go/src/testing/testing.go:1598 +0x9a
testing.tRunner(0xc000083520, 0xc0000adbf8)
        /usr/local/go/src/testing/testing.go:1259 +0x230
testing.runTests(0xc0000d6000, {0x6d2040, 0x1, 0x1}, {0x0, 0x7fdf262eefff, 0x6daa00})
        /usr/local/go/src/testing/testing.go:1596 +0x7cb
testing.(*M).Run(0xc0000d6000)
        /usr/local/go/src/testing/testing.go:1504 +0x9d2
main.main()
        _testmain.go:43 +0x22c
FAIL    github.com/qdm12/mytestrepo        0.006s
FAIL
vishvananda commented 2 years ago

Hmm, this method is using the same serialization that we do for all other netlink messages. Do you get the same error in any of the other tests?

nelljerram commented 2 years ago

FYI I'm also seeing this:

fatal error: checkptr: converted pointer straddles multiple allocations

goroutine 237 [running]:
runtime.throw({0x442eafe, 0x1f38610})
    /usr/local/go-cgo/src/runtime/panic.go:1198 +0x71 fp=0xc000e3f428 sp=0xc000e3f3f8 pc=0x4533f1
runtime.checkptrAlignment(0xc0009161c0, 0x8, 0x18)
    /usr/local/go-cgo/src/runtime/checkptr.go:26 +0x6c fp=0xc000e3f448 sp=0xc000e3f428 pc=0x42450c
github.com/vishvananda/netlink/nl.DeserializeRtNexthop(...)
    /go/pkg/mod/github.com/vishvananda/netlink@v1.1.1-0.20210703095558-21f2c55a7727/nl/route_linux.go:51
github.com/vishvananda/netlink.deserializeRoute.func1({0xc0009161c8, 0x10, 0x10})
    /go/pkg/mod/github.com/vishvananda/netlink@v1.1.1-0.20210703095558-21f2c55a7727/route_linux.go:1137 +0x86 fp=0xc000e3f580 sp=0xc000e3f448 pc=0x1f38a26
github.com/vishvananda/netlink.deserializeRoute({_, _, _})
    /go/pkg/mod/github.com/vishvananda/netlink@v1.1.1-0.20210703095558-21f2c55a7727/route_linux.go:1195 +0x18d0 fp=0xc000e3f908 sp=0xc000e3f580 pc=0x1f38610
github.com/vishvananda/netlink.routeSubscribeAt.func2()
    /go/pkg/mod/github.com/vishvananda/netlink@v1.1.1-0.20210703095558-21f2c55a7727/route_linux.go:1484 +0x45b fp=0xc000e3ffe0 sp=0xc000e3f908 pc=0x1f3b8bb
runtime.goexit()
    /usr/local/go-cgo/src/runtime/asm_amd64.s:1581 +0x1 fp=0xc000e3ffe8 sp=0xc000e3ffe0 pc=0x4867a1
created by github.com/vishvananda/netlink.routeSubscribeAt
    /go/pkg/mod/github.com/vishvananda/netlink@v1.1.1-0.20210703095558-21f2c55a7727/route_linux.go:1452 +0x436
nelljerram commented 2 years ago

Actually I wonder if both of these cases are just reflecting general data corruption, as the values in the checkptrAlignment calls don't look sensible for what https://go.dev/src/runtime/checkptr.go says.

rampxxxx commented 2 years ago

I have faced the same using the netlink.RouteSubscribe method but depending on the kernel it not happens

The RHEL's bt.

goroutine 6 [running]:
runtime.throw({0x55a5cf, 0x51a390})
        /home/jg/ibm/go-1.17.3/go/src/runtime/panic.go:1198 +0x71 fp=0xc00021f400 sp=0xc00021f3d0 pc=0x4634f1
runtime.checkptrAlignment(0xc00006e460, 0x8, 0x18)
        /home/jg/ibm/go-1.17.3/go/src/runtime/checkptr.go:26 +0x6c fp=0xc00021f420 sp=0xc00021f400 pc=0x43840c
github.com/vishvananda/netlink/nl.DeserializeRtNexthop(...)
        /home/jg/go/pkg/mod/github.com/vishvananda/netlink@v1.1.1-0.20220125195016-0639e7e787ba/nl/route_linux.go:51
github.com/vishvananda/netlink.deserializeRoute.func1({0xc00006e468, 0x10, 0x10})
        /home/jg/go/pkg/mod/github.com/vishvananda/netlink@v1.1.1-0.20220125195016-0639e7e787ba/route_linux.go:1147 +0x86 fp=0xc00021f558 sp=0xc00021f420 pc=0x51af26
github.com/vishvananda/netlink.deserializeRoute({_, _, _})
        /home/jg/go/pkg/mod/github.com/vishvananda/netlink@v1.1.1-0.20220125195016-0639e7e787ba/route_linux.go:1205 +0x12d0 fp=0xc00021f8e8 sp=0xc00021f558 pc=0x51a390
github.com/vishvananda/netlink.routeSubscribeAt.func2()
        /home/jg/go/pkg/mod/github.com/vishvananda/netlink@v1.1.1-0.20220125195016-0639e7e787ba/route_linux.go:1507 +0x470 fp=0xc00021ffe0 sp=0xc00021f8e8 pc=0x51c270
runtime.goexit()
        /home/jg/ibm/go-1.17.3/go/src/runtime/asm_amd64.s:1581 +0x1 fp=0xc00021ffe8 sp=0xc00021ffe0 pc=0x492b61
created by github.com/vishvananda/netlink.routeSubscribeAt
        /home/jg/go/pkg/mod/github.com/vishvananda/netlink@v1.1.1-0.20220125195016-0639e7e787ba/route_linux.go:1475 +0x436

I saw this with lib tags v1.1.0 , v1.0 and 1.2-beta