Skip to content

Commit 9fa324c

Browse files
committed
dmz: cloned binary: set +x permissions when creating regular tmpfile
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]>
1 parent 9112335 commit 9fa324c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

libcontainer/dmz/cloned_binary_linux.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,6 @@ func Memfd(comment string) (*os.File, SealFunc, error) {
6464
}
6565

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

0 commit comments

Comments
 (0)