Commit 67b4be3
Smack: fix use-after-free in smk_write_relabel_self()
commit beb4ee6 upstream.
smk_write_relabel_self() frees memory from the task's credentials with
no locking, which can easily cause a use-after-free because multiple
tasks can share the same credentials structure.
Fix this by using prepare_creds() and commit_creds() to correctly modify
the task's credentials.
Reproducer for "BUG: KASAN: use-after-free in smk_write_relabel_self":
#include <fcntl.h>
#include <pthread.h>
#include <unistd.h>
static void *thrproc(void *arg)
{
int fd = open("/sys/fs/smackfs/relabel-self", O_WRONLY);
for (;;) write(fd, "foo", 3);
}
int main()
{
pthread_t t;
pthread_create(&t, NULL, thrproc, NULL);
thrproc(NULL);
}
Reported-by: syzbot+e6416dabb497a650da40@syzkaller.appspotmail.com
Fixes: 38416e5 ("Smack: limited capability for changing process label")
Cc: <stable@vger.kernel.org> # v4.4+
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>1 parent 330aa3b commit 67b4be3
1 file changed
Lines changed: 11 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2746 | 2746 | | |
2747 | 2747 | | |
2748 | 2748 | | |
2749 | | - | |
2750 | 2749 | | |
2751 | 2750 | | |
2752 | 2751 | | |
| |||
2771 | 2770 | | |
2772 | 2771 | | |
2773 | 2772 | | |
| 2773 | + | |
| 2774 | + | |
| 2775 | + | |
| 2776 | + | |
| 2777 | + | |
| 2778 | + | |
| 2779 | + | |
| 2780 | + | |
| 2781 | + | |
2774 | 2782 | | |
2775 | 2783 | | |
| 2784 | + | |
2776 | 2785 | | |
2777 | 2786 | | |
2778 | | - | |
| 2787 | + | |
2779 | 2788 | | |
2780 | 2789 | | |
2781 | 2790 | | |
| |||
0 commit comments