Skip to content

Commit

Permalink
bsdacct: fix access to invalid filp in acct_on()
Browse files Browse the repository at this point in the history
The file opened in acct_on and freshly stored in the ns->bacct struct can
be closed in acct_file_reopen by a concurrent call after we release
acct_lock and before we call mntput(file->f_path.mnt).

Record file->f_path.mnt in a local variable and use this variable only.

Signed-off-by: Renaud Lottiaux <[email protected]>
Signed-off-by: Louis Rilling <[email protected]>
Cc: Al Viro <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Renaud Lottiaux authored and torvalds committed Jul 1, 2009
1 parent b4f9018 commit df279ca
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions kernel/acct.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ static void acct_file_reopen(struct bsd_acct_struct *acct, struct file *file,
static int acct_on(char *name)
{
struct file *file;
struct vfsmount *mnt;
int error;
struct pid_namespace *ns;
struct bsd_acct_struct *acct = NULL;
Expand Down Expand Up @@ -256,11 +257,12 @@ static int acct_on(char *name)
acct = NULL;
}

mnt_pin(file->f_path.mnt);
mnt = file->f_path.mnt;
mnt_pin(mnt);
acct_file_reopen(ns->bacct, file, ns);
spin_unlock(&acct_lock);

mntput(file->f_path.mnt); /* it's pinned, now give up active reference */
mntput(mnt); /* it's pinned, now give up active reference */
kfree(acct);

return 0;
Expand Down

0 comments on commit df279ca

Please sign in to comment.