Skip to content

x/sys/unix: Utsname.Version is too small? #65585

@seeplusplus

Description

@seeplusplus

Go version

go1.20.12 freebsd/386

Output of go env in your module/workspace:

Not relevant.

What did you do?

  1. Built the following minimal reproducible Go program targeting FreeBSD, shown here:
    FreeBSD: couldn't get uname: cannot allocate memory prometheus/node_exporter#2809 (comment)
  2. Copied the file to a running instances of pfSense
  3. Ran it
  4. Got an "Cannot allocate memory" error
  5. Cloned sys/unix locally and played around with the syscall_freebsd.go file, in particular I commented out sections of the Uname method until I found the section that caused the error. That was this section:
 mib = []_C_int{CTL_KERN, KERN_VERSION}
          n = unsafe.Sizeof(uname.Version)
          if err := sysctl(mib, &uname.Version[0], &n, nil, 0); err != nil {
                 return err
}   

Upon further digging I found that uname.Version is set to 256 bytes here:

https://cs.opensource.google/go/x/sys/+/master:unix/ztypes_freebsd_amd64.go;l=639-645;bpv=0?q=Utsname&ss=go%2Fx%2Fsys

so then I,
6. Modified the above locally to a larger value, 1024.
7. Rebuilt the test binary with all code from step 5 uncommented.
8. Reran the binary on the pfSense OS,
9. No error.

What did you see happen?

Got "cannot allocate memory" until I made the Utsname.Version field larger.

What did you expect to see?

The Uname to be returned.

Apologies if this isn't the correct venue for this report. I'm not a Go developer, nor have I ever worked on FreeBSD or pfSense. I am willing to do what's needed to fix this, but I'm not sure exactly what's "wrong" here. I know the types_freebsd.go file is auto-generated, but I'm not familiar with the domain to know if:

  1. pfSense is errantly reporting a KERN_VERSION larger than 256 bytes, or
  2. the types_freebsd.go file needs to be regenerated/modified in some way.

Edit: Fwiw I was doing some reading and it looks like maybe this isn't the first time someone has encountered this issue in FreeBSD?

https://github.com/freebsd/freebsd-src/blob/82bebc7936581e9c4ff3604d4cb998f8cc017f50/sys/kern/kern_xxx.c#L351-L371

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.OS-FreeBSDcompiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions