Files
Shailend ChandandgVisor bot e428bbea51 Fix creds check in linkat(AT_EMPTY_PATH)
linkat(AT_EMPTY_PATH) needs to check for CAP_DAC_READ_SEARCH in the userns in
which the fd was opened, not the userns of the task running linkat().

To get at that userns, vfs.FileDescription now saves a pointer to the creds
at the time of its creation: plumbing these creds in accounts for much of the
diff. This is similar to how `struct file` stores creds in `f_cred` in Linux.

Moreover, since the Linux patch "vfs: relax linkat() AT_EMPTY_PATH..." [1], the
need for this cap is excused if the creds of the calling task are literally
the same as the one stored in the fd.

[1] https://github.com/torvalds/linux/commit/42bd2af5950456d

PiperOrigin-RevId: 853374474
2026-01-07 12:48:17 -08:00

79 lines
1.8 KiB
Python

load("//tools:defs.bzl", "go_library")
load("//tools/go_generics:defs.bzl", "go_template_instance")
package(default_applicable_licenses = ["//:license"])
licenses(["notice"])
go_library(
name = "vfio",
srcs = [
"devaddr_range.go",
"devaddr_set.go",
"pci_device_fd.go",
"pci_device_fd_mmap.go",
"save_restore.go",
"tpu_fd.go",
"tpu_fd_mmap.go",
"vfio.go",
"vfio_fd.go",
"vfio_fd_mmap.go",
],
visibility = [
"//pkg/sentry:internal",
],
deps = [
"//pkg/abi/linux",
"//pkg/cleanup",
"//pkg/context",
"//pkg/devutil",
"//pkg/errors/linuxerr",
"//pkg/fdnotifier",
"//pkg/hostarch",
"//pkg/log",
"//pkg/marshal/primitive",
"//pkg/safemem",
"//pkg/sentry/arch",
"//pkg/sentry/devices/tpuproxy/util",
"//pkg/sentry/fsimpl/eventfd",
"//pkg/sentry/fsutil",
"//pkg/sentry/kernel",
"//pkg/sentry/kernel/auth",
"//pkg/sentry/memmap",
"//pkg/sentry/mm",
"//pkg/sentry/vfs",
"//pkg/sync",
"//pkg/usermem",
"//pkg/waiter",
"@org_golang_x_sys//unix:go_default_library",
],
)
go_template_instance(
name = "devaddr_range",
out = "devaddr_range.go",
package = "vfio",
prefix = "DevAddr",
template = "//pkg/segment:generic_range",
types = {
"T": "uint64",
},
)
go_template_instance(
name = "devaddr_set",
out = "devaddr_set.go",
imports = {
"mm": "gvisor.dev/gvisor/pkg/sentry/mm",
},
package = "vfio",
prefix = "DevAddr",
template = "//pkg/segment:generic_set",
types = {
"Key": "uint64",
"Range": "DevAddrRange",
"Value": "mm.PinnedRange",
"Functions": "devAddrSetFuncs",
},
)