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

error read auxv in vdsoMemoryAddress function in arm_32 env #1133

Closed
hailwind opened this issue Sep 14, 2023 · 1 comment · Fixed by #1144
Closed

error read auxv in vdsoMemoryAddress function in arm_32 env #1133

hailwind opened this issue Sep 14, 2023 · 1 comment · Fixed by #1144
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@hailwind
Copy link

Describe the bug
EOF read auxv in vdsoMemoryAddress function in arm_32 env

code position
https://github.com/cilium/ebpf/blob/main/internal/vdso.go#L65

To Reproduce

#uint64
root@1c40e8105b98:/sdwan# ./testx 
2023/09/14 22:31:41 Tag: 13752409965245497377, Val: 17927356702261264
2023/09/14 22:31:41 Tag: 17592186044422, Val: 429496729617
2023/09/14 22:31:41 Tag: 281698315010051, Val: 137438953476
2023/09/14 22:31:41 Tag: 30064771077, Val: 7
2023/09/14 22:31:41 Tag: 8, Val: 286371239428105
2023/09/14 22:31:41 Tag: 11, Val: 12
2023/09/14 22:31:41 Tag: 13, Val: 14
2023/09/14 22:31:41 Tag: 23, Val: 13747605919770869785
2023/09/14 22:31:41 Tag: 26, Val: 13747607246915764255
2023/09/14 22:31:41 Tag: 13747605988490346511, Val: 0
2023/09/14 22:31:41 reading auxv entry: EOF

#uint32
root@1c40e8105b98:/tmp# ./testx 
2023/09/14 22:32:26 Tag: 33, Val: 3204325376
2023/09/14 22:32:26 aux.VAL: 3204325376

root@1c40e8105b98:/tmp# uname -a
Linux testx 5.15.130 #0 SMP Thu Sep 14 07:12:57 2023 armv7l GNU/Linux

troubleshooting code

package main

import (
	"encoding/binary"
	"errors"
	"log"
	"os"

	"golang.org/x/sys/unix"
)

func main() {
	av, err := os.Open("/proc/self/auxv")
	if errors.Is(err, unix.EACCES) {
		log.Printf("opening auxv: %s (process may not be dumpable due to file capabilities)", err)
	}

	if err != nil {
		log.Printf("opening auxv: %s", err)
	}
	defer av.Close()

	const (
		_AT_NULL         = 0  // End of vector
		_AT_SYSINFO_EHDR = 33 // Offset to vDSO blob in process image
	)
	var NativeEndian binary.ByteOrder = binary.LittleEndian
	// Loop through all tag/value pairs in auxv until we find `AT_SYSINFO_EHDR`,
	// the address of a page containing the virtual Dynamic Shared Object (vDSO).
	// aux := struct{ Tag, Val uint64 }{}
	aux := struct{ Tag, Val uint32 }{}
	for {
		if err := binary.Read(av, NativeEndian, &aux); err != nil {
			log.Printf("reading auxv entry: %s", err)
			break
		}
		log.Printf("Tag: %d, Val: %d", aux.Tag, aux.Val)
		switch aux.Tag {
		case _AT_SYSINFO_EHDR:

			if aux.Val != 0 {
				log.Printf("aux.VAL: %d", aux.Val)
				return
			} else {
				log.Printf(("invalid vDSO address in auxv"))
			}
		// _AT_NULL is always the last tag/val pair in the aux vector
		// and can be treated like EOF.
		case _AT_NULL:
			log.Printf("_AT_NULL")
		}
	}
}

compile:
GOOS=linux GOARCH=arm GOARM=7 CGO_ENABLED=1 CC=arm-linux-gnueabi-gcc go build -a -ldflags "-linkmode external -extldflags '-static' -s -w" -o testx main.go

Expected behavior
fix it in arm32

@hailwind hailwind added the bug Something isn't working label Sep 14, 2023
@lmb lmb added the help wanted Extra attention is needed label Sep 14, 2023
@lmb
Copy link
Collaborator

lmb commented Sep 14, 2023

Thanks for the detailed bug report! We don't officially support arm32, so this is kind of expected. I'm happy to merge any fixes you come up with ofc.

lmb added a commit to lmb/ebpf that referenced this issue Oct 2, 2023
It turns out that the auxiliary vector has a platform specific size.
Adjust the code to use uintptr to approximate "unsigned long" from C.

Fixes cilium#1133

Signed-off-by: Lorenz Bauer <lmb@isovalent.com>
lmb added a commit to lmb/ebpf that referenced this issue Oct 2, 2023
It turns out that the auxiliary vector has a platform specific size.
Adjust the code to use uintptr to approximate "unsigned long" from C.

Fixes cilium#1133

Signed-off-by: Lorenz Bauer <lmb@isovalent.com>
lmb added a commit to lmb/ebpf that referenced this issue Oct 2, 2023
It turns out that the auxiliary vector has a platform specific size.
Adjust the code to use uintptr to approximate "unsigned long" from C.

Fixes cilium#1133

Signed-off-by: Lorenz Bauer <lmb@isovalent.com>
lmb added a commit to lmb/ebpf that referenced this issue Oct 10, 2023
It turns out that the auxiliary vector has a platform specific size.
Adjust the code to use uintptr to approximate "unsigned long" from C.

Fixes cilium#1133

Signed-off-by: Lorenz Bauer <lmb@isovalent.com>
lmb added a commit to lmb/ebpf that referenced this issue Oct 11, 2023
It turns out that the auxiliary vector has a platform specific size.
Adjust the code to use uintptr to approximate "unsigned long" from C.
auxv32le.bin is from an i686 Debian bookworm machine.

Fixes cilium#1133

Signed-off-by: Lorenz Bauer <lmb@isovalent.com>
@lmb lmb closed this as completed in #1144 Oct 11, 2023
lmb added a commit that referenced this issue Oct 11, 2023
It turns out that the auxiliary vector has a platform specific size.
Adjust the code to use uintptr to approximate "unsigned long" from C.
auxv32le.bin is from an i686 Debian bookworm machine.

Fixes #1133

Signed-off-by: Lorenz Bauer <lmb@isovalent.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants