]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
afs: Fix key refcounting in file locking code
authorDavid Howells <dhowells@redhat.com>
Wed, 9 Jan 2019 17:23:54 +0000 (17:23 +0000)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Wed, 14 Aug 2019 09:18:49 +0000 (11:18 +0200)
BugLink: https://bugs.launchpad.net/bugs/1837813
[ Upstream commit 59d49076ae3e6912e6d7df2fd68e2337f3d02036 ]

Fix the refcounting of the authentication keys in the file locking code.
The vnode->lock_key member points to a key on which it expects to be
holding a ref, but it isn't always given an extra ref, however.

Fixes: 0fafdc9f888b ("afs: Fix file locking")
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
fs/afs/flock.c
fs/afs/inode.c

index c40ba2fe3cbeee50d1b529d5e1e9d2960633f995..43f4ef8c1853aa0d71c2d593ee7e85303de69c52 100644 (file)
@@ -208,7 +208,7 @@ again:
                /* The new front of the queue now owns the state variables. */
                next = list_entry(vnode->pending_locks.next,
                                  struct file_lock, fl_u.afs.link);
-               vnode->lock_key = afs_file_key(next->fl_file);
+               vnode->lock_key = key_get(afs_file_key(next->fl_file));
                vnode->lock_type = (next->fl_type == F_RDLCK) ? AFS_LOCK_READ : AFS_LOCK_WRITE;
                vnode->lock_state = AFS_VNODE_LOCK_WAITING_FOR_CB;
                goto again;
@@ -413,7 +413,7 @@ static void afs_dequeue_lock(struct afs_vnode *vnode, struct file_lock *fl)
        /* The new front of the queue now owns the state variables. */
        next = list_entry(vnode->pending_locks.next,
                          struct file_lock, fl_u.afs.link);
-       vnode->lock_key = afs_file_key(next->fl_file);
+       vnode->lock_key = key_get(afs_file_key(next->fl_file));
        vnode->lock_type = (next->fl_type == F_RDLCK) ? AFS_LOCK_READ : AFS_LOCK_WRITE;
        vnode->lock_state = AFS_VNODE_LOCK_WAITING_FOR_CB;
        afs_lock_may_be_available(vnode);
index 1e81864ef0b29bffcc10944c30bc57796815025d..06d894beb2108fead3b11c763ca052ed6f19c414 100644 (file)
@@ -499,6 +499,8 @@ void afs_evict_inode(struct inode *inode)
 #endif
 
        afs_put_permits(vnode->permit_cache);
+       key_put(vnode->lock_key);
+       vnode->lock_key = NULL;
        _leave("");
 }