• E
    Smack: fix use-after-free in smk_write_relabel_self() · ccf8f1a7
    Eric Biggers 提交于
    commit beb4ee6770a89646659e6a2178538d2b13e2654e 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: 38416e53 ("Smack: limited capability for changing process label")
    Cc: <stable@vger.kernel.org> # v4.4+
    Signed-off-by: NEric Biggers <ebiggers@google.com>
    Signed-off-by: NCasey Schaufler <casey@schaufler-ca.com>
    Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
    ccf8f1a7
smackfs.c 69.7 KB