Commit a1b879ee authored by David Howells's avatar David Howells

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: 5a813276 ("afs: Do better accretion of small writes on newly created content")
Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
parent 80f23212
...@@ -170,11 +170,12 @@ int afs_release(struct inode *inode, struct file *file) ...@@ -170,11 +170,12 @@ int afs_release(struct inode *inode, struct file *file)
{ {
struct afs_vnode *vnode = AFS_FS_I(inode); struct afs_vnode *vnode = AFS_FS_I(inode);
struct afs_file *af = file->private_data; struct afs_file *af = file->private_data;
int ret = 0;
_enter("{%llx:%llu},", vnode->fid.vid, vnode->fid.vnode); _enter("{%llx:%llu},", vnode->fid.vid, vnode->fid.vnode);
if ((file->f_mode & FMODE_WRITE)) if ((file->f_mode & FMODE_WRITE))
return vfs_fsync(file, 0); ret = vfs_fsync(file, 0);
file->private_data = NULL; file->private_data = NULL;
if (af->wb) if (af->wb)
...@@ -182,8 +183,8 @@ int afs_release(struct inode *inode, struct file *file) ...@@ -182,8 +183,8 @@ int afs_release(struct inode *inode, struct file *file)
key_put(af->key); key_put(af->key);
kfree(af); kfree(af);
afs_prune_wb_keys(vnode); afs_prune_wb_keys(vnode);
_leave(" = 0"); _leave(" = %d", ret);
return 0; return ret;
} }
/* /*
......
...@@ -573,6 +573,7 @@ void afs_evict_inode(struct inode *inode) ...@@ -573,6 +573,7 @@ void afs_evict_inode(struct inode *inode)
} }
#endif #endif
afs_prune_wb_keys(vnode);
afs_put_permits(rcu_access_pointer(vnode->permit_cache)); afs_put_permits(rcu_access_pointer(vnode->permit_cache));
key_put(vnode->silly_key); key_put(vnode->silly_key);
vnode->silly_key = NULL; vnode->silly_key = NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment