Skip to content

Commit e9e360b

Browse files
namhyungkees
authored andcommitted
pstore: Protect unlink with read_mutex
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]>
1 parent 7a0032f commit e9e360b

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

fs/pstore/inode.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,14 @@ static int pstore_unlink(struct inode *dir, struct dentry *dentry)
199199
if (err)
200200
return err;
201201

202-
if (p->psi->erase)
202+
if (p->psi->erase) {
203+
mutex_lock(&p->psi->read_mutex);
203204
p->psi->erase(p->type, p->id, p->count,
204205
d_inode(dentry)->i_ctime, p->psi);
205-
else
206+
mutex_unlock(&p->psi->read_mutex);
207+
} else {
206208
return -EPERM;
209+
}
207210

208211
return simple_unlink(dir, dentry);
209212
}

0 commit comments

Comments
 (0)