Skip to content

Commit

Permalink
seccomp: don't leave dangling ->notif if file allocation fails
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reported-by: Christian Brauner <[email protected]>
Signed-off-by: Tycho Andersen <[email protected]>
Acked-by: Christian Brauner <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Kees Cook <[email protected]>
  • Loading branch information
tych0 authored and kees committed Sep 8, 2020
1 parent 19d1d49 commit e839317
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions kernel/seccomp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,12 @@ static long seccomp_set_mode_strict(void)
}

#ifdef CONFIG_SECCOMP_FILTER
static void seccomp_notify_free(struct seccomp_filter *filter)
{
kfree(filter->notif);
filter->notif = NULL;
}

static void seccomp_notify_detach(struct seccomp_filter *filter)
{
struct seccomp_knotif *knotif;
Expand Down Expand Up @@ -1138,8 +1144,7 @@ static void seccomp_notify_detach(struct seccomp_filter *filter)
complete(&knotif->ready);
}

kfree(filter->notif);
filter->notif = NULL;
seccomp_notify_free(filter);
mutex_unlock(&filter->notify_lock);
}

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

out_notif:
if (IS_ERR(ret))
kfree(filter->notif);
seccomp_notify_free(filter);
out:
return ret;
}
Expand Down

0 comments on commit e839317

Please sign in to comment.