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

ebpf cgroupdev program: fix device permission check issue #229

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/nvcgo/internal/cgroup/ebpf.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ func (p *program) appendDevice(dev specs.LinuxDeviceCgroup, labelPrefix string)
}
if hasAccess {
p.insts = append(p.insts,
// if (R3 & bpfAccess == 0 /* use R2 as a temp var */) goto next
// if (R3 & bpfAccess != R3 /* use R2 as a temp var */) goto next
asm.Mov.Reg32(asm.R2, asm.R3),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both runc and crun use R1 as a temporary variable here. Could it cause issues that we're using R2 since we're also using R2 in the hasAccess block above?

cc @klueska

Copy link
Contributor Author

@oOraph oOraph Nov 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@elezar yes you're right ! Since we erase R2 the bpfType check in the next block will break. Interesting that the issue was never encountered before. Fixing: I'll just use a free register, R6 (I guess using R1 as you suggest would be safe as we have extracted all we needed from the struct)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, thanks :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rather use R1 since to align with the other implementations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

asm.And.Imm32(asm.R2, bpfAccess),
asm.JEq.Imm(asm.R2, 0, nextBlockSym),
asm.JNE.Reg32(asm.R2, asm.R3, nextBlockSym),
)
}
if hasMajor {
Expand Down