Skip to contentSkip to conversation

seccomp: release seccomp after killing terminate clone/fork

PATCH In review Calvin Liao 2 participants 2 messages Dec 28, 2021 – Dec 29, 2021

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

PATCH 1/1 seccomp: release seccomp after killing terminate clone/fork

From: "calvin.liao" <[email protected]>

Add to release seccomp after killing terminate clone/fork to avoid memory leak when enabling CONFIG_SECCOMP.

---
 kernel/fork.c | 8 ++++++++
 1 file changed, 8 insertions(+)
kernel/fork.c +8 -0
index 403b9dbbfb62..984103967a97 100644
@@ -1698,6 +1698,13 @@ static void copy_seccomp(struct task_struct *p)
 #endif
 }
 
+static void release_seccomp(struct task_struct *p)
+{
+#ifdef CONFIG_SECCOMP
+	seccomp_filter_release(p);
+#endif
+}
+
 SYSCALL_DEFINE1(set_tid_address, int __user *, tidptr)
 {
 	current->clear_child_tid = tidptr;
@@ -2405,6 +2412,7 @@ static __latent_entropy struct task_struct *copy_process(
 	return p;
 
 bad_fork_cancel_cgroup:
+	release_seccomp(p);
 	sched_core_free(p);
 	spin_unlock(&current->sighand->siglock);
 	write_unlock_irq(&tasklist_lock);
Signature · 7 lines
2.18.0


_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
maintainer
#1 lore raw
Quoted 5 lines · On Tue, 28 Dec 2021 13:34:21 +0800 Calvin Liao <[email protected]> wrote:

From: "calvin.liao" <[email protected]>

Add to release seccomp after killing terminate clone/fork to avoid memory leak when enabling CONFIG_SECCOMP.

Help us out here - where was this filter allocated? Please describe the code flow which led to this leak. Rather than simply saying "there is a leak".

kernel/fork.c static void copy_seccomp(struct task_struct *p) · line 1705

Quoted 11 lines
kernel/fork.c +5 -0
@@ -1698,6 +1698,13 @@ static void copy_seccomp(struct task_struct *p)
 #endif
 }
 
+static void release_seccomp(struct task_struct *p)
+{
+#ifdef CONFIG_SECCOMP
+	seccomp_filter_release(p);
+#endif

ifdefs aren't needed?

kernel/fork.c static __latent_entropy struct task_struct *copy_process( · line 2415

Quoted 10 lines
kernel/fork.c +3 -0
+}
+
 SYSCALL_DEFINE1(set_tid_address, int __user *, tidptr)
 {
 	current->clear_child_tid = tidptr;
@@ -2405,6 +2412,7 @@ static __latent_entropy struct task_struct *copy_process(
 	return p;
 
 bad_fork_cancel_cgroup:
+	release_seccomp(p);

Why not simply call seccomp_filter_release() here, without ifdefs?

kernel/fork.c static __latent_entropy struct task_struct *copy_process( · line 2418

Quoted 3 lines
kernel/fork.c +0 -0
 	sched_core_free(p);
 	spin_unlock(&current->sighand->siglock);
 	write_unlock_irq(&tasklist_lock);

_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek