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
x/sys/unix: Utsname.Version is too small? #65585
Comments
(attn @golang/freebsd) |
Both FreeBSD 13 and 14 libc use 256 bytes for https://cgit.freebsd.org/src/tree/sys/sys/utsname.h?h=stable/13 https://cgit.freebsd.org/src/tree/sys/sys/utsname.h?h=stable/14 This is also true for pFSense AFIK: https://github.com/pfsense/FreeBSD-src/blob/RELENG_2_7_2/sys/sys/utsname.h |
The following C reproducer returns #include <sys/utsname.h>
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/sysctl.h>
#include <errno.h>
#include <stdlib.h>
int main(int argc, char **argv) {
struct utsname u = {0};
int mib[2], rval;
size_t len;
mib[0] = CTL_KERN;
mib[1] = KERN_VERSION;
len = sizeof u.version;
char* q = (char *)u.version;
rval = sysctl(mib, 2, q, &len, NULL, 0);
printf("rval: %d, errno: %d\n", rval, errno);
printf("u.version: %s\n", &u.version[0]);
return 0;
}
Looks like we should suppress |
Change https://go.dev/cl/562617 mentions this issue: |
@paulzhol I have tested the above patch on my pfSense machine, this works, thank you! |
Go version
go1.20.12 freebsd/386
Output of
go env
in your module/workspace:What did you do?
FreeBSD: couldn't get uname: cannot allocate memory prometheus/node_exporter#2809 (comment)
pfSense
"Cannot allocate memory"
errorsys/unix
locally and played around with thesyscall_freebsd.go
file, in particular I commented out sections of theUname
method until I found the section that caused the error. That was this section: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 theUtsname.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: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
The text was updated successfully, but these errors were encountered: