public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Kirill Korotaev <dev@sw.ru>
To: Andrew Morton <akpm@osdl.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: [PATCH] unserialized task->files changing
Date: Tue, 08 Aug 2006 14:07:49 +0400	[thread overview]
Message-ID: <44D86275.2080406@sw.ru> (raw)

[-- Attachment #1: Type: text/plain, Size: 294 bytes --]

Fixed race on put_files_struct on exec with proc.
Restoring files on current on error path may lead
to proc having a pointer to already kfree-d files_struct.

Found during OpenVZ stress testing.

Signed-Off-By: Pavel Emelianov <xemul@openvz.org>
Signed-Off-By: Kirill Korotaev <dev@openvz.org>

[-- Attachment #2: diff-ms-files-race-fix --]
[-- Type: text/plain, Size: 1463 bytes --]

--- ./fs/binfmt_elf.c.fsfix	2006-03-27 14:25:59.000000000 +0400
+++ ./fs/binfmt_elf.c	2006-03-28 13:26:16.000000000 +0400
@@ -1027,8 +1027,13 @@ out_free_file:
 	sys_close(elf_exec_fileno);
 out_free_fh:
 	if (files) {
-		put_files_struct(current->files);
+		struct files_struct *old;
+
+		old = current->files;
+		task_lock(current);
 		current->files = files;
+		task_unlock(current);
+		put_files_struct(old);
 	}
 out_free_ph:
 	kfree(elf_phdata);
--- ./fs/binfmt_misc.c.fsfix	2006-03-27 14:25:59.000000000 +0400
+++ ./fs/binfmt_misc.c	2006-03-28 13:27:06.000000000 +0400
@@ -216,8 +216,13 @@ _error:
 	bprm->interp_data = 0;
 _unshare:
 	if (files) {
-		put_files_struct(current->files);
+		struct files_struct *old;
+
+		old = current->files;
+		task_lock(current);
 		current->files = files;
+		task_unlock(current);
+		put_files_struct(old);
 	}
 	goto _ret;
 }
--- ./fs/exec.c.fsfix	2006-03-27 14:25:59.000000000 +0400
+++ ./fs/exec.c	2006-03-28 13:28:10.000000000 +0400
@@ -865,7 +865,7 @@ int flush_old_exec(struct linux_binprm *
 {
 	char * name;
 	int i, ch, retval;
-	struct files_struct *files;
+	struct files_struct *files, *old;
 	char tcomm[sizeof(current->comm)];
 
 	/*
@@ -946,8 +946,11 @@ int flush_old_exec(struct linux_binprm *
 	return 0;
 
 mmap_failed:
-	put_files_struct(current->files);
+	old = current->files;
+	task_lock(current);
 	current->files = files;
+	task_unlock(current);
+	put_files_struct(old);
 out:
 	return retval;
 }

             reply	other threads:[~2006-08-08 10:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-08 10:07 Kirill Korotaev [this message]
2006-08-08 10:12 ` [PATCH] unserialized task->files changing Christoph Hellwig
2006-08-08 10:23   ` Eric Dumazet
2006-08-08 10:43     ` Kirill Korotaev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=44D86275.2080406@sw.ru \
    --to=dev@sw.ru \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox