cred: copy_process() should clear child->replacement_session_keyring
authorOleg Nesterov <oleg@redhat.com>
Mon, 9 Apr 2012 19:03:50 +0000 (21:03 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 7 Oct 2012 21:37:30 +0000 (23:37 +0200)
commit 79549c6dfda0603dba9a70a53467ce62d9335c33 upstream

keyctl_session_to_parent(task) sets ->replacement_session_keyring,
it should be processed and cleared by key_replace_session_keyring().

However, this task can fork before it notices TIF_NOTIFY_RESUME and
the new child gets the bogus ->replacement_session_keyring copied by
dup_task_struct(). This is obviously wrong and, if nothing else, this
leads to put_cred(already_freed_cred).

change copy_creds() to clear this member. If copy_process() fails
before this point the wrong ->replacement_session_keyring doesn't
matter, exit_creds() won't be called.

Cc: <stable@vger.kernel.org>
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Acked-by: David Howells <dhowells@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Willy Tarreau <w@1wt.eu>
kernel/cred.c

index 0b5b5fc70e017ccf63a1d4f36e63e79c7c72ade9..9c06d10107c4390bac4d71cc8b9c5580413d05ae 100644 (file)
@@ -443,6 +443,8 @@ int copy_creds(struct task_struct *p, unsigned long clone_flags)
 
        mutex_init(&p->cred_guard_mutex);
 
+       p->replacement_session_keyring = NULL;
+
        if (
 #ifdef CONFIG_KEYS
                !p->cred->thread_keyring &&