Skip to content

Commit

Permalink
pstore: Protect unlink with read_mutex
Browse files Browse the repository at this point in the history
When update_ms is set, pstore_get_records() will be called when there's
a new entry.  But unlink can be called at the same time and might
contend with the open-read-close loop.  Depending on the implementation
of platform driver, it may be safe or not.  But I think it'd be better
to protect those race in the first place.

Cc: Stefan Hajnoczi <[email protected]>
Signed-off-by: Namhyung Kim <[email protected]>
Signed-off-by: Kees Cook <[email protected]>
  • Loading branch information
namhyung authored and kees committed Nov 16, 2016
1 parent 7a0032f commit e9e360b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions fs/pstore/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,14 @@ static int pstore_unlink(struct inode *dir, struct dentry *dentry)
if (err)
return err;

if (p->psi->erase)
if (p->psi->erase) {
mutex_lock(&p->psi->read_mutex);
p->psi->erase(p->type, p->id, p->count,
d_inode(dentry)->i_ctime, p->psi);
else
mutex_unlock(&p->psi->read_mutex);
} else {
return -EPERM;
}

return simple_unlink(dir, dentry);
}
Expand Down

0 comments on commit e9e360b

Please sign in to comment.