Skip to content

Commit

Permalink
dmz: cloned binary: set +x permissions when creating regular tmpfile
Browse files Browse the repository at this point in the history
While we did set +x when "sealing" regular temporary files, the "is
executable" checks were done before then and would thus fail, causing
the fallback to not work properly.

So just set +x after we create the file. We already have a O_RDWR handle
open when we do the chmod so we won't get permission issues when writing
to the file.

Fixes: e089db3 ("dmz: add fallbacks to handle noexec for O_TMPFILE and mktemp()")

Signed-off-by: lifubang <[email protected]>
  • Loading branch information
lifubang committed Oct 14, 2024
1 parent 9112335 commit 9fa324c
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions libcontainer/dmz/cloned_binary_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ func Memfd(comment string) (*os.File, SealFunc, error) {
}

func sealFile(f **os.File) error {
if err := (*f).Chmod(0o511); err != nil {
return err
}
// When sealing an O_TMPFILE-style descriptor we need to
// re-open the path as O_PATH to clear the existing write
// handle we have.
Expand Down Expand Up @@ -108,6 +105,9 @@ func mktemp(dir string) (*os.File, SealFunc, error) {
if err := os.Remove(file.Name()); err != nil {
return nil, nil, fmt.Errorf("unlinking classic tmpfile: %w", err)
}
if err := file.Chmod(0o511); err != nil {
return nil, nil, fmt.Errorf("chmod classic tmpfile: %w", err)
}
var stat unix.Stat_t
if err := unix.Fstat(int(file.Fd()), &stat); err != nil {
return nil, nil, fmt.Errorf("cannot fstat classic tmpfile: %w", err)
Expand Down

0 comments on commit 9fa324c

Please sign in to comment.