From: Neil Horman <nhorman@redhat.com>
To: linux-kernel@vger.kernel.org
Subject: [Patch] vfs: increase scope of critical locked path in fget_light to avoid race
Date: Fri, 20 May 2005 09:23:25 -0400 [thread overview]
Message-ID: <20050520132325.GE19229@hmsendeavour.rdu.redhat.com> (raw)
[-- 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 --]
next reply other threads:[~2005-05-20 13:23 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-05-20 13:23 Neil Horman [this message]
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
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=20050520132325.GE19229@hmsendeavour.rdu.redhat.com \
--to=nhorman@redhat.com \
--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
all inboxes | Powered by JetHome®