Commit beb4ee6
Smack: fix use-after-free in smk_write_relabel_self()
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>1 parent b3a9e3b commit beb4ee6
1 file changed
+11
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2720 | 2720 | | |
2721 | 2721 | | |
2722 | 2722 | | |
2723 | | - | |
2724 | 2723 | | |
2725 | 2724 | | |
2726 | 2725 | | |
| |||
2745 | 2744 | | |
2746 | 2745 | | |
2747 | 2746 | | |
| 2747 | + | |
| 2748 | + | |
| 2749 | + | |
| 2750 | + | |
| 2751 | + | |
| 2752 | + | |
| 2753 | + | |
| 2754 | + | |
| 2755 | + | |
2748 | 2756 | | |
2749 | 2757 | | |
| 2758 | + | |
2750 | 2759 | | |
2751 | 2760 | | |
2752 | | - | |
| 2761 | + | |
2753 | 2762 | | |
2754 | 2763 | | |
2755 | 2764 | | |
| |||
0 commit comments