Skip to contentSkip to conversation

umh: fix memory leak on execve failure

PATCH Applied Vincent Minet 2 participants 2 messages May 7, 2020 – May 9, 2020

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 umh: fix memory leak on execve failure

If a UMH process created by fork_usermode_blob() fails to execute, a pair of struct file allocated by umh_pipe_setup() will leak.

Under normal conditions, the caller (like bpfilter) needs to manage the lifetime of the UMH and its two pipes. But when fork_usermode_blob() fails, the caller doesn't really have a way to know what needs to be done. It seems better to do the cleanup ourselves in this case.

Fixes 449325b52b7a ("umh: introduce fork_usermode_blob() helper")
---
 kernel/umh.c | 6 ++++++
 1 file changed, 6 insertions(+)
kernel/umh.c +6 -0
index 7f255b5a8845..20d51e0957e0 100644
@@ -475,6 +475,12 @@ static void umh_clean_and_save_pid(struct subprocess_info *info)
 {
 	struct umh_info *umh_info = info->data;
 
+	/* cleanup if umh_pipe_setup() was successful but exec failed */
+	if (info->pid && info->retval) {
+		fput(umh_info->pipe_to_umh);
+		fput(umh_info->pipe_from_umh);
+	}
+
 	argv_free(info->argv);
 	umh_info->pid = info->pid;
 }
Signature · 1 line
2.26.2
maintainer Applied
#1 lore raw
Quoted 10 lines · On Fri, 8 May 2020 00:14:22 +0200 Vincent Minet wrote:

If a UMH process created by fork_usermode_blob() fails to execute, a pair of struct file allocated by umh_pipe_setup() will leak.

Under normal conditions, the caller (like bpfilter) needs to manage the lifetime of the UMH and its two pipes. But when fork_usermode_blob() fails, the caller doesn't really have a way to know what needs to be done. It seems better to do the cleanup ourselves in this case.

Fixes 449325b52b7a ("umh: introduce fork_usermode_blob() helper")

Applied to net, thank you!