diff options
author | David Howells <dhowells@redhat.com> | 2019-05-15 07:09:17 -0400 |
---|---|---|
committer | David Howells <dhowells@redhat.com> | 2019-05-15 07:32:34 -0400 |
commit | a1b879eefc2b34cd3f17187ef6fc1cf3960e9518 (patch) | |
tree | 749a872254c15ad9de5a0e17a895d7d553321e99 /fs/afs | |
parent | 80f232121b69cc69a31ccb2b38c1665d770b0710 (diff) |
afs: Fix key leak in afs_release() and afs_evict_inode()
Fix afs_release() to go through the cleanup part of the function if
FMODE_WRITE is set rather than exiting through vfs_fsync() (which skips the
cleanup). The cleanup involves discarding the refs on the key used for
file ops and the writeback key record.
Also fix afs_evict_inode() to clean up any left over wb keys attached to
the inode/vnode when it is removed.
Fixes: 5a8132761609 ("afs: Do better accretion of small writes on newly created content")
Signed-off-by: David Howells <dhowells@redhat.com>
Diffstat (limited to 'fs/afs')
-rw-r--r-- | fs/afs/file.c | 7 | ||||
-rw-r--r-- | fs/afs/inode.c | 1 |
2 files changed, 5 insertions, 3 deletions
diff --git a/fs/afs/file.c b/fs/afs/file.c index e8d6619890a9..b0a43e250a9b 100644 --- a/fs/afs/file.c +++ b/fs/afs/file.c | |||
@@ -170,11 +170,12 @@ int afs_release(struct inode *inode, struct file *file) | |||
170 | { | 170 | { |
171 | struct afs_vnode *vnode = AFS_FS_I(inode); | 171 | struct afs_vnode *vnode = AFS_FS_I(inode); |
172 | struct afs_file *af = file->private_data; | 172 | struct afs_file *af = file->private_data; |
173 | int ret = 0; | ||
173 | 174 | ||
174 | _enter("{%llx:%llu},", vnode->fid.vid, vnode->fid.vnode); | 175 | _enter("{%llx:%llu},", vnode->fid.vid, vnode->fid.vnode); |
175 | 176 | ||
176 | if ((file->f_mode & FMODE_WRITE)) | 177 | if ((file->f_mode & FMODE_WRITE)) |
177 | return vfs_fsync(file, 0); | 178 | ret = vfs_fsync(file, 0); |
178 | 179 | ||
179 | file->private_data = NULL; | 180 | file->private_data = NULL; |
180 | if (af->wb) | 181 | if (af->wb) |
@@ -182,8 +183,8 @@ int afs_release(struct inode *inode, struct file *file) | |||
182 | key_put(af->key); | 183 | key_put(af->key); |
183 | kfree(af); | 184 | kfree(af); |
184 | afs_prune_wb_keys(vnode); | 185 | afs_prune_wb_keys(vnode); |
185 | _leave(" = 0"); | 186 | _leave(" = %d", ret); |
186 | return 0; | 187 | return ret; |
187 | } | 188 | } |
188 | 189 | ||
189 | /* | 190 | /* |
diff --git a/fs/afs/inode.c b/fs/afs/inode.c index c4652b42d545..f30aa5eacd39 100644 --- a/fs/afs/inode.c +++ b/fs/afs/inode.c | |||
@@ -573,6 +573,7 @@ void afs_evict_inode(struct inode *inode) | |||
573 | } | 573 | } |
574 | #endif | 574 | #endif |
575 | 575 | ||
576 | afs_prune_wb_keys(vnode); | ||
576 | afs_put_permits(rcu_access_pointer(vnode->permit_cache)); | 577 | afs_put_permits(rcu_access_pointer(vnode->permit_cache)); |
577 | key_put(vnode->silly_key); | 578 | key_put(vnode->silly_key); |
578 | vnode->silly_key = NULL; | 579 | vnode->silly_key = NULL; |