Commit 79f430ba authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

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-43199Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@virtuozzo.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent e46594ae
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment