From: Dave Hansen <dave-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
To: Oren Laadan <orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
Cc: containers
<containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org>,
Dave Hansen
<dave-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
Subject: [RFC][PATCH 3/4] checkpoint/restart: fix 'struct file' references
Date: Tue, 02 Dec 2008 10:57:39 -0800 [thread overview]
Message-ID: <20081202185739.15E85A9A@kernel> (raw)
In-Reply-To: <20081202185734.F740150C@kernel>
We must hold a reference to 'file' when it get passed in to
fd_install(). After fd_install() the entry in the fdtable
takes on the reference. If we don't hold a reference to
it, another thread can come along after fd_install() and
fput() it before we've done the get_file().
In cr_read_fd_data(), the cr_obj_add_ref() code does the
get_file() internally. But, we need to do this (and get
the ref) before we do the cr_attach_file(). Otherwise,
the file can go away after the cr_attach_file() and before
the cr_obj_add_ref().
---
linux-2.6.git-dave/checkpoint/rstr_file.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff -puN checkpoint/rstr_file.c~fix-refs-order-in-cr_attach_get_file checkpoint/rstr_file.c
--- linux-2.6.git/checkpoint/rstr_file.c~fix-refs-order-in-cr_attach_get_file 2008-12-02 10:22:17.000000000 -0800
+++ linux-2.6.git-dave/checkpoint/rstr_file.c 2008-12-02 10:22:17.000000000 -0800
@@ -59,8 +59,8 @@ static int cr_attach_get_file(struct fil
if (fd >= 0) {
fsnotify_open(file->f_path.dentry);
- fd_install(fd, file);
get_file(file);
+ fd_install(fd, file);
}
return fd;
}
@@ -107,6 +107,11 @@ cr_read_fd_data(struct cr_ctx *ctx, stru
/* FIX: need to restore uid, gid, owner etc */
+ /* register new <objref, file> tuple in hash table */
+ ret = cr_obj_add_ref(ctx, file, parent, CR_OBJ_FILE, 0);
+ if (ret < 0)
+ goto out;
+
fd = cr_attach_file(file); /* no need to cleanup 'file' below */
if (fd < 0) {
filp_close(file, NULL);
@@ -114,10 +119,6 @@ cr_read_fd_data(struct cr_ctx *ctx, stru
goto out;
}
- /* register new <objref, file> tuple in hash table */
- ret = cr_obj_add_ref(ctx, file, parent, CR_OBJ_FILE, 0);
- if (ret < 0)
- goto out;
ret = sys_fcntl(fd, F_SETFL, hh->f_flags & CR_SETFL_MASK);
if (ret < 0)
goto out;
_
next prev parent reply other threads:[~2008-12-02 18:57 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-12-02 18:57 [RFC][PATCH 1/4] checkpoint/restart: fix code to handle open symlinks Dave Hansen
2008-12-02 18:57 ` [RFC][PATCH 2/4] checkpoint/restart: fix cr_ctx_checkpoint() locking Dave Hansen
2008-12-02 22:22 ` Oren Laadan
[not found] ` <4935B52D.6050706-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
2008-12-02 22:25 ` Dave Hansen
2008-12-02 18:57 ` Dave Hansen [this message]
2008-12-02 18:57 ` [RFC][PATCH 4/4] checkpoint/restart: simplify cr_scan_fds() Dave Hansen
2008-12-03 4:21 ` Serge E. Hallyn
2008-12-03 9:48 ` Oren Laadan
[not found] ` <493655E2.7040304-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
2008-12-03 16:23 ` Dave Hansen
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=20081202185739.15E85A9A@kernel \
--to=dave-23vcf4htsmix0ybbhkvfkdbpr1lh4cv8@public.gmane.org \
--cc=containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
--cc=orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.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