Skip to content

Commit 8106adc

Browse files
namjaejeongregkh
authored andcommitted
ksmbd: fix potential use-after-free in oplock/lease break ack
commit 50f930d upstream. If ksmbd_iov_pin_rsp return error, use-after-free can happen by accessing opinfo->state and opinfo_put and ksmbd_fd_put could called twice. Reported-by: Ziyan Xu <[email protected]> Signed-off-by: Namjae Jeon <[email protected]> Signed-off-by: Steve French <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent d0195c4 commit 8106adc

1 file changed

Lines changed: 9 additions & 20 deletions

File tree

fs/smb/server/smb2pdu.c

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8535,28 +8535,22 @@ static void smb20_oplock_break_ack(struct ksmbd_work *work)
85358535
goto err_out;
85368536
}
85378537

8538-
opinfo->op_state = OPLOCK_STATE_NONE;
8539-
wake_up_interruptible_all(&opinfo->oplock_q);
8540-
opinfo_put(opinfo);
8541-
ksmbd_fd_put(work, fp);
8542-
85438538
rsp->StructureSize = cpu_to_le16(24);
85448539
rsp->OplockLevel = rsp_oplevel;
85458540
rsp->Reserved = 0;
85468541
rsp->Reserved2 = 0;
85478542
rsp->VolatileFid = volatile_id;
85488543
rsp->PersistentFid = persistent_id;
85498544
ret = ksmbd_iov_pin_rsp(work, rsp, sizeof(struct smb2_oplock_break));
8550-
if (!ret)
8551-
return;
8552-
8545+
if (ret) {
85538546
err_out:
8547+
smb2_set_err_rsp(work);
8548+
}
8549+
85548550
opinfo->op_state = OPLOCK_STATE_NONE;
85558551
wake_up_interruptible_all(&opinfo->oplock_q);
8556-
85578552
opinfo_put(opinfo);
85588553
ksmbd_fd_put(work, fp);
8559-
smb2_set_err_rsp(work);
85608554
}
85618555

85628556
static int check_lease_state(struct lease *lease, __le32 req_state)
@@ -8686,11 +8680,6 @@ static void smb21_lease_break_ack(struct ksmbd_work *work)
86868680
}
86878681

86888682
lease_state = lease->state;
8689-
opinfo->op_state = OPLOCK_STATE_NONE;
8690-
wake_up_interruptible_all(&opinfo->oplock_q);
8691-
atomic_dec(&opinfo->breaking_cnt);
8692-
wake_up_interruptible_all(&opinfo->oplock_brk);
8693-
opinfo_put(opinfo);
86948683

86958684
rsp->StructureSize = cpu_to_le16(36);
86968685
rsp->Reserved = 0;
@@ -8699,16 +8688,16 @@ static void smb21_lease_break_ack(struct ksmbd_work *work)
86998688
rsp->LeaseState = lease_state;
87008689
rsp->LeaseDuration = 0;
87018690
ret = ksmbd_iov_pin_rsp(work, rsp, sizeof(struct smb2_lease_ack));
8702-
if (!ret)
8703-
return;
8704-
8691+
if (ret) {
87058692
err_out:
8693+
smb2_set_err_rsp(work);
8694+
}
8695+
8696+
opinfo->op_state = OPLOCK_STATE_NONE;
87068697
wake_up_interruptible_all(&opinfo->oplock_q);
87078698
atomic_dec(&opinfo->breaking_cnt);
87088699
wake_up_interruptible_all(&opinfo->oplock_brk);
8709-
87108700
opinfo_put(opinfo);
8711-
smb2_set_err_rsp(work);
87128701
}
87138702

87148703
/**

0 commit comments

Comments
 (0)