Skip to content

Commit e839317

Browse files
tych0kees
authored andcommitted
seccomp: don't leave dangling ->notif if file allocation fails
Christian and Kees both pointed out that this is a bit sloppy to open-code both places, and Christian points out that we leave a dangling pointer to ->notif if file allocation fails. Since we check ->notif for null in order to determine if it's ok to install a filter, this means people won't be able to install a filter if the file allocation fails for some reason, even if they subsequently should be able to. To fix this, let's hoist this free+null into its own little helper and use it. Reported-by: Kees Cook <keescook@chromium.org> Reported-by: Christian Brauner <christian.brauner@ubuntu.com> Signed-off-by: Tycho Andersen <tycho@tycho.pizza> Acked-by: Christian Brauner <christian.brauner@ubuntu.com> Link: https://lore.kernel.org/r/20200902140953.1201956-1-tycho@tycho.pizza Signed-off-by: Kees Cook <keescook@chromium.org>
1 parent 19d1d49 commit e839317

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

kernel/seccomp.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,6 +1109,12 @@ static long seccomp_set_mode_strict(void)
11091109
}
11101110

11111111
#ifdef CONFIG_SECCOMP_FILTER
1112+
static void seccomp_notify_free(struct seccomp_filter *filter)
1113+
{
1114+
kfree(filter->notif);
1115+
filter->notif = NULL;
1116+
}
1117+
11121118
static void seccomp_notify_detach(struct seccomp_filter *filter)
11131119
{
11141120
struct seccomp_knotif *knotif;
@@ -1138,8 +1144,7 @@ static void seccomp_notify_detach(struct seccomp_filter *filter)
11381144
complete(&knotif->ready);
11391145
}
11401146

1141-
kfree(filter->notif);
1142-
filter->notif = NULL;
1147+
seccomp_notify_free(filter);
11431148
mutex_unlock(&filter->notify_lock);
11441149
}
11451150

@@ -1494,7 +1499,7 @@ static struct file *init_listener(struct seccomp_filter *filter)
14941499

14951500
out_notif:
14961501
if (IS_ERR(ret))
1497-
kfree(filter->notif);
1502+
seccomp_notify_free(filter);
14981503
out:
14991504
return ret;
15001505
}

0 commit comments

Comments
 (0)