Skip to content

Commit 332c218

Browse files
committed
utils: invalidate proc_fd on open_proc_file
invalidate the proc_fd file descriptor if we are closing it as part of mark_or_close_fds_ge_than. Closes: #1912 Signed-off-by: Giuseppe Scrivano <[email protected]>
1 parent 7fe47e4 commit 332c218

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/libcrun/utils.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1801,7 +1801,11 @@ mark_or_close_fds_ge_than (libcrun_container_t *container, int n, bool close_now
18011801

18021802
ret = syscall_close_range (n, UINT_MAX, close_now ? 0 : CLOSE_RANGE_CLOEXEC);
18031803
if (ret == 0)
1804-
return 0;
1804+
{
1805+
if (close_now && container->proc_fd >= n)
1806+
container->proc_fd = -1;
1807+
return 0;
1808+
}
18051809
if (ret < 0 && errno != EINVAL && errno != ENOSYS && errno != EPERM)
18061810
return crun_make_error (err, errno, "close_range from `%d`", n);
18071811

@@ -1837,6 +1841,9 @@ mark_or_close_fds_ge_than (libcrun_container_t *container, int n, bool close_now
18371841
ret = close (val);
18381842
if (UNLIKELY (ret < 0))
18391843
return crun_make_error (err, errno, "close fd `%d`", val);
1844+
1845+
if (val == container->proc_fd)
1846+
container->proc_fd = -1;
18401847
}
18411848
else
18421849
{

0 commit comments

Comments
 (0)