moby / sys

Apache License 2.0
71 stars 41 forks source link

BSD mountinfo implementation is unsound #51

Open cyphar opened 3 years ago

cyphar commented 3 years ago

There are two problems:

kolyshkin commented 3 years ago

Related: #24 (one other issue is freebsd implementation requires cgo)

We need someone who works with FreeBSD to fix this, and we need some CI to test it on.

kolyshkin commented 3 years ago

Related to using reflect.SliceHeader: https://github.com/moby/moby/pull/41626

cuonglm commented 3 years ago

@cyphar Would you elaborating more? I don't see problem with current usage of reflect.SliceHeader in https://github.com/moby/sys/blob/1bc8673b57550ddf85262eb0fed0aac651a37dab/mountinfo/mountinfo_bsd.go#L28

cyphar commented 3 years ago

I'm not saying it doesn't work, the issue is that reflect.SliceHeader is explicitly described in the documentation as being fundamentally unsound to use. There are other issues with it (namely the GC doesn't know how to track the pointer and there are cases where you could get use-after-frees) but because getmntinfo returns a static pointer in memory, this isn't as much of a concern (though I do wonder if there are cases where Go would decide to try to GC the head of a SliceHeader...).

cuonglm commented 3 years ago

I'm not saying it doesn't work, the issue is that reflect.SliceHeader is explicitly described in the documentation as being fundamentally unsound to use. There are other issues with it (namely the GC doesn't know how to track the pointer and there are cases where you could get use-after-frees) but because getmntinfo returns a static pointer in memory, this isn't as much of a concern (though I do wonder if there are cases where Go would decide to try to GC the head of a SliceHeader...).

I dont think it can be the issue if you did use reflect.SliceHeader correctly. I invite you to read https://github.com/golang/go/issues/41705#issuecomment-701706990

cyphar commented 3 years ago

Fair enough, I was going by the literal reading of the documentation (and I've been bitten by Go's runtime far too many times to be optimistic that its behaviour will be nice). But if the Go authors say the example is valid then there's only one correctness issue in the BSD implementation.