Skip to content

Commit 2ab3d70

Browse files
Alexander Aringteigland
authored andcommitted
dlm: fix user space lkb refcounting
This patch fixes to check on the right return value if it was the last callback. The rv variable got overwritten by the return of copy_result_to_user(). Fixing it by introducing a second variable for the return value and don't let rv being overwritten. Cc: [email protected] Fixes: 61bed0b ("fs: dlm: use a non-static queue for callbacks") Reported-by: Valentin Vidić <[email protected]> Closes: https://lore.kernel.org/gfs2/[email protected] Signed-off-by: Alexander Aring <[email protected]> Signed-off-by: David Teigland <[email protected]>
1 parent d206a76 commit 2ab3d70

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

fs/dlm/user.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ static ssize_t device_read(struct file *file, char __user *buf, size_t count,
806806
struct dlm_lkb *lkb;
807807
DECLARE_WAITQUEUE(wait, current);
808808
struct dlm_callback *cb;
809-
int rv, copy_lvb = 0;
809+
int rv, ret, copy_lvb = 0;
810810
int old_mode, new_mode;
811811

812812
if (count == sizeof(struct dlm_device_version)) {
@@ -906,17 +906,17 @@ static ssize_t device_read(struct file *file, char __user *buf, size_t count,
906906
trace_dlm_ast(lkb->lkb_resource->res_ls, lkb);
907907
}
908908

909-
rv = copy_result_to_user(lkb->lkb_ua,
910-
test_bit(DLM_PROC_FLAGS_COMPAT, &proc->flags),
911-
cb->flags, cb->mode, copy_lvb, buf, count);
909+
ret = copy_result_to_user(lkb->lkb_ua,
910+
test_bit(DLM_PROC_FLAGS_COMPAT, &proc->flags),
911+
cb->flags, cb->mode, copy_lvb, buf, count);
912912

913913
kref_put(&cb->ref, dlm_release_callback);
914914

915915
/* removes ref for proc->asts, may cause lkb to be freed */
916916
if (rv == DLM_DEQUEUE_CALLBACK_LAST)
917917
dlm_put_lkb(lkb);
918918

919-
return rv;
919+
return ret;
920920
}
921921

922922
static __poll_t device_poll(struct file *file, poll_table *wait)

0 commit comments

Comments
 (0)