[PATCH] [119/275] CRED: Fix kernel panic upon security_file_alloc() failure.

From: Andi Kleen
Date: Wed Mar 30 2011 - 17:46:21 EST


2.6.35-longterm review patch. If anyone has any objections, please let me know.

------------------
From: Tetsuo Handa <penguin-kernel@xxxxxxxxxxxxxxxxxxx>

commit 78d2978874e4e10e97dfd4fd79db45bdc0748550 upstream.

In get_empty_filp() since 2.6.29, file_free(f) is called with f->f_cred == NULL
when security_file_alloc() returned an error. As a result, kernel will panic()
due to put_cred(NULL) call within RCU callback.

Fix this bug by assigning f->f_cred before calling security_file_alloc().

Signed-off-by: Tetsuo Handa <penguin-kernel@xxxxxxxxxxxxxxxxxxx>
Signed-off-by: David Howells <dhowells@xxxxxxxxxx>
Signed-off-by: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxx>
Signed-off-by: Andi Kleen <ak@xxxxxxxxxxxxxxx>

---
fs/file_table.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

Index: linux-2.6.35.y/fs/file_table.c
===================================================================
--- linux-2.6.35.y.orig/fs/file_table.c 2011-03-29 22:51:20.759191992 -0700
+++ linux-2.6.35.y/fs/file_table.c 2011-03-29 23:03:00.692282457 -0700
@@ -123,13 +123,13 @@
goto fail;

percpu_counter_inc(&nr_files);
+ f->f_cred = get_cred(cred);
if (security_file_alloc(f))
goto fail_sec;

INIT_LIST_HEAD(&f->f_u.fu_list);
atomic_long_set(&f->f_count, 1);
rwlock_init(&f->f_owner.lock);
- f->f_cred = get_cred(cred);
spin_lock_init(&f->f_lock);
eventpoll_init_file(f);
/* f->f_version: 0 */
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/