From 79f430ba754f1e5d5072aab2d82ebcf36b386fb9 Mon Sep 17 00:00:00 2001 From: Cyrill Gorcunov Date: Wed, 20 Jan 2016 16:25:00 +0300 Subject: [PATCH] parasite: Don't left memfd opened inside dumpee If for some reason ptrace_poke_area return error we might left dumpee with memfd descriptor opened. Later in code we remove out injected blob making dumpee to look untouched but descriptor will hang there. lsof from container output: | systemd-u 48 root 6u REG 0,4 0 53855 /memfd:CRIUMFD (deleted) Thus lets close it immediately. https://jira.sw.ru/browse/PSBM-43199 Signed-off-by: Cyrill Gorcunov Signed-off-by: Pavel Emelyanov --- parasite-syscall.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/parasite-syscall.c b/parasite-syscall.c index d1c1ec936..b0a3d211d 100644 --- a/parasite-syscall.c +++ b/parasite-syscall.c @@ -1187,7 +1187,7 @@ static int parasite_memfd_exchange(struct parasite_ctl *ctl, unsigned long size) void *where = (void *)ctl->syscall_ip + BUILTIN_SYSCALL_SIZE; u8 orig_code[MEMFD_FNAME_SZ] = MEMFD_FNAME; pid_t pid = ctl->pid.real; - unsigned long sret; + unsigned long sret = -ENOSYS; int ret, fd, lfd; BUILD_BUG_ON(sizeof(orig_code) < sizeof(long)); @@ -1201,6 +1201,9 @@ static int parasite_memfd_exchange(struct parasite_ctl *ctl, unsigned long size) (unsigned long)where, 0, 0, 0, 0, 0); if (ptrace_poke_area(pid, orig_code, where, sizeof(orig_code))) { + fd = (int)(long)sret; + if (fd >= 0) + syscall_seized(ctl, __NR_close, &sret, fd, 0, 0, 0, 0, 0); pr_err("Can't restore memfd args (pid: %d)\n", pid); return -1; }