Skip to content

Commit bd671b6

Browse files
authored
Merge pull request #4392 from cyphar/1.1-remove-bindfd
[1.1] nsenter: cloned_binary: remove bindfd logic entirely
2 parents 2655e7c + 614ce12 commit bd671b6

File tree

1 file changed

+0
-67
lines changed

1 file changed

+0
-67
lines changed

libcontainer/nsenter/cloned_binary.c

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -396,61 +396,6 @@ static int seal_execfd(int *fd, int fdtype)
396396
return -1;
397397
}
398398

399-
static int try_bindfd(void)
400-
{
401-
int fd, ret = -1;
402-
char template[PATH_MAX] = { 0 };
403-
char *prefix = getenv("_LIBCONTAINER_STATEDIR");
404-
405-
if (!prefix || *prefix != '/')
406-
prefix = "/tmp";
407-
if (snprintf(template, sizeof(template), "%s/runc.XXXXXX", prefix) < 0)
408-
return ret;
409-
410-
/*
411-
* We need somewhere to mount it, mounting anything over /proc/self is a
412-
* BAD idea on the host -- even if we do it temporarily.
413-
*/
414-
fd = mkstemp(template);
415-
if (fd < 0)
416-
return ret;
417-
close(fd);
418-
419-
/*
420-
* For obvious reasons this won't work in rootless mode because we haven't
421-
* created a userns+mntns -- but getting that to work will be a bit
422-
* complicated and it's only worth doing if someone actually needs it.
423-
*/
424-
ret = -EPERM;
425-
if (mount("/proc/self/exe", template, "", MS_BIND, "") < 0)
426-
goto out;
427-
if (mount("", template, "", MS_REMOUNT | MS_BIND | MS_RDONLY, "") < 0)
428-
goto out_umount;
429-
430-
/* Get read-only handle that we're sure can't be made read-write. */
431-
ret = open(template, O_PATH | O_CLOEXEC);
432-
433-
out_umount:
434-
/*
435-
* Make sure the MNT_DETACH works, otherwise we could get remounted
436-
* read-write and that would be quite bad (the fd would be made read-write
437-
* too, invalidating the protection).
438-
*/
439-
if (umount2(template, MNT_DETACH) < 0) {
440-
if (ret >= 0)
441-
close(ret);
442-
ret = -ENOTRECOVERABLE;
443-
}
444-
445-
out:
446-
/*
447-
* We don't care about unlink errors, the worst that happens is that
448-
* there's an empty file left around in STATEDIR.
449-
*/
450-
unlink(template);
451-
return ret;
452-
}
453-
454399
static ssize_t fd_to_fd(int outfd, int infd)
455400
{
456401
ssize_t total = 0;
@@ -485,18 +430,6 @@ static int clone_binary(void)
485430
size_t sent = 0;
486431
int fdtype = EFD_NONE;
487432

488-
/*
489-
* Before we resort to copying, let's try creating an ro-binfd in one shot
490-
* by getting a handle for a read-only bind-mount of the execfd.
491-
*/
492-
execfd = try_bindfd();
493-
if (execfd >= 0)
494-
return execfd;
495-
496-
/*
497-
* Dammit, that didn't work -- time to copy the binary to a safe place we
498-
* can seal the contents.
499-
*/
500433
execfd = make_execfd(&fdtype);
501434
if (execfd < 0 || fdtype == EFD_NONE)
502435
return -ENOTRECOVERABLE;

0 commit comments

Comments
 (0)