All of lore.kernel.org
 help / color / mirror / Atom feed
* [Patch] vfs: increase scope of critical locked path in fget_light to avoid race
@ 2005-05-20 13:23 Neil Horman
  2005-05-20 13:33 ` Al Viro
  0 siblings, 1 reply; 6+ messages in thread
From: Neil Horman @ 2005-05-20 13:23 UTC (permalink / raw)
  To: linux-kernel

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

Patch to increase the scope of the locked critical path in fget_light to include
the conditional where there is only one reference to the passed file_struct.
Currently there is no protection against someone modifying that reference count
after it has been read in fget_light and falling into a code path where the fd
array is modified.  The result is a race condition that leads to a corrupted fd
table and potential oopses.  This patch corrects that by enforcing the locking
protocol that is used by all other accessors of the fd table on the 1 reference
case in fget_light.  Smoke tested by me, with no failures.

Signed-off-by: Neil Horman <nhorman@redhat.com>

 file_table.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

 
--- linux-2.6.git/fs/file_table.c.racefix	2005-05-20 07:32:12.000000000 -0400
+++ linux-2.6.git/fs/file_table.c	2005-05-20 08:53:03.000000000 -0400
@@ -174,17 +174,17 @@ struct file fastcall *fget_light(unsigne
 	struct files_struct *files = current->files;
 
 	*fput_needed = 0;
+	spin_lock(&files->file_lock);
 	if (likely((atomic_read(&files->count) == 1))) {
 		file = fcheck_files(files, fd);
 	} else {
-		spin_lock(&files->file_lock);
 		file = fcheck_files(files, fd);
 		if (file) {
 			get_file(file);
 			*fput_needed = 1;
 		}
-		spin_unlock(&files->file_lock);
 	}
+	spin_unlock(&files->file_lock);
 	return file;
 }
 
-- 
/***************************************************
 *Neil Horman
 *Software Engineer
 *Red Hat, Inc.
 *nhorman@redhat.com
 *gpg keyid: 1024D / 0x92A74FA1
 *http://pgp.mit.edu
 ***************************************************/

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2005-05-21 13:14 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-05-20 13:23 [Patch] vfs: increase scope of critical locked path in fget_light to avoid race Neil Horman
2005-05-20 13:33 ` Al Viro
2005-05-20 13:40   ` Al Viro
2005-05-20 15:25     ` Neil Horman
2005-05-20 21:28       ` Al Viro
2005-05-21 13:14         ` Neil Horman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.