Skip to content

Commit bb39ed4

Browse files
namjaejeonSteve French
authored andcommitted
ksmbd: fix use-after-free in ksmbd_free_work_struct
->interim_entry of ksmbd_work could be deleted after oplock is freed. We don't need to manage it with linked list. The interim request could be immediately sent whenever a oplock break wait is needed. Cc: stable@vger.kernel.org Reported-by: Norbert Szetei <norbert@doyensec.com> Tested-by: Norbert Szetei <norbert@doyensec.com> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 80e54e8 commit bb39ed4

File tree

4 files changed

+15
-27
lines changed

4 files changed

+15
-27
lines changed

fs/smb/server/ksmbd_work.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ struct ksmbd_work *ksmbd_alloc_work_struct(void)
2626
INIT_LIST_HEAD(&work->request_entry);
2727
INIT_LIST_HEAD(&work->async_request_entry);
2828
INIT_LIST_HEAD(&work->fp_entry);
29-
INIT_LIST_HEAD(&work->interim_entry);
3029
INIT_LIST_HEAD(&work->aux_read_list);
3130
work->iov_alloc_cnt = 4;
3231
work->iov = kcalloc(work->iov_alloc_cnt, sizeof(struct kvec),
@@ -56,8 +55,6 @@ void ksmbd_free_work_struct(struct ksmbd_work *work)
5655
kfree(work->tr_buf);
5756
kvfree(work->request_buf);
5857
kfree(work->iov);
59-
if (!list_empty(&work->interim_entry))
60-
list_del(&work->interim_entry);
6158

6259
if (work->async_id)
6360
ksmbd_release_id(&work->conn->async_ida, work->async_id);

fs/smb/server/ksmbd_work.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ struct ksmbd_work {
8989
/* List head at conn->async_requests */
9090
struct list_head async_request_entry;
9191
struct list_head fp_entry;
92-
struct list_head interim_entry;
9392
};
9493

9594
/**

fs/smb/server/oplock.c

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ static struct oplock_info *alloc_opinfo(struct ksmbd_work *work,
4646
opinfo->fid = id;
4747
opinfo->Tid = Tid;
4848
INIT_LIST_HEAD(&opinfo->op_entry);
49-
INIT_LIST_HEAD(&opinfo->interim_list);
5049
init_waitqueue_head(&opinfo->oplock_q);
5150
init_waitqueue_head(&opinfo->oplock_brk);
5251
atomic_set(&opinfo->refcount, 1);
@@ -803,7 +802,6 @@ static void __smb2_lease_break_noti(struct work_struct *wk)
803802
static int smb2_lease_break_noti(struct oplock_info *opinfo)
804803
{
805804
struct ksmbd_conn *conn = opinfo->conn;
806-
struct list_head *tmp, *t;
807805
struct ksmbd_work *work;
808806
struct lease_break_info *br_info;
809807
struct lease *lease = opinfo->o_lease;
@@ -831,16 +829,6 @@ static int smb2_lease_break_noti(struct oplock_info *opinfo)
831829
work->sess = opinfo->sess;
832830

833831
if (opinfo->op_state == OPLOCK_ACK_WAIT) {
834-
list_for_each_safe(tmp, t, &opinfo->interim_list) {
835-
struct ksmbd_work *in_work;
836-
837-
in_work = list_entry(tmp, struct ksmbd_work,
838-
interim_entry);
839-
setup_async_work(in_work, NULL, NULL);
840-
smb2_send_interim_resp(in_work, STATUS_PENDING);
841-
list_del_init(&in_work->interim_entry);
842-
release_async_work(in_work);
843-
}
844832
INIT_WORK(&work->work, __smb2_lease_break_noti);
845833
ksmbd_queue_work(work);
846834
wait_for_break_ack(opinfo);
@@ -871,7 +859,8 @@ static void wait_lease_breaking(struct oplock_info *opinfo)
871859
}
872860
}
873861

874-
static int oplock_break(struct oplock_info *brk_opinfo, int req_op_level)
862+
static int oplock_break(struct oplock_info *brk_opinfo, int req_op_level,
863+
struct ksmbd_work *in_work)
875864
{
876865
int err = 0;
877866

@@ -914,9 +903,15 @@ static int oplock_break(struct oplock_info *brk_opinfo, int req_op_level)
914903
}
915904

916905
if (lease->state & (SMB2_LEASE_WRITE_CACHING_LE |
917-
SMB2_LEASE_HANDLE_CACHING_LE))
906+
SMB2_LEASE_HANDLE_CACHING_LE)) {
907+
if (in_work) {
908+
setup_async_work(in_work, NULL, NULL);
909+
smb2_send_interim_resp(in_work, STATUS_PENDING);
910+
release_async_work(in_work);
911+
}
912+
918913
brk_opinfo->op_state = OPLOCK_ACK_WAIT;
919-
else
914+
} else
920915
atomic_dec(&brk_opinfo->breaking_cnt);
921916
} else {
922917
err = oplock_break_pending(brk_opinfo, req_op_level);
@@ -1116,7 +1111,7 @@ void smb_send_parent_lease_break_noti(struct ksmbd_file *fp,
11161111
if (ksmbd_conn_releasing(opinfo->conn))
11171112
continue;
11181113

1119-
oplock_break(opinfo, SMB2_OPLOCK_LEVEL_NONE);
1114+
oplock_break(opinfo, SMB2_OPLOCK_LEVEL_NONE, NULL);
11201115
opinfo_put(opinfo);
11211116
}
11221117
}
@@ -1152,7 +1147,7 @@ void smb_lazy_parent_lease_break_close(struct ksmbd_file *fp)
11521147

11531148
if (ksmbd_conn_releasing(opinfo->conn))
11541149
continue;
1155-
oplock_break(opinfo, SMB2_OPLOCK_LEVEL_NONE);
1150+
oplock_break(opinfo, SMB2_OPLOCK_LEVEL_NONE, NULL);
11561151
opinfo_put(opinfo);
11571152
}
11581153
}
@@ -1252,8 +1247,7 @@ int smb_grant_oplock(struct ksmbd_work *work, int req_op_level, u64 pid,
12521247
goto op_break_not_needed;
12531248
}
12541249

1255-
list_add(&work->interim_entry, &prev_opinfo->interim_list);
1256-
err = oplock_break(prev_opinfo, SMB2_OPLOCK_LEVEL_II);
1250+
err = oplock_break(prev_opinfo, SMB2_OPLOCK_LEVEL_II, work);
12571251
opinfo_put(prev_opinfo);
12581252
if (err == -ENOENT)
12591253
goto set_lev;
@@ -1322,8 +1316,7 @@ static void smb_break_all_write_oplock(struct ksmbd_work *work,
13221316
}
13231317

13241318
brk_opinfo->open_trunc = is_trunc;
1325-
list_add(&work->interim_entry, &brk_opinfo->interim_list);
1326-
oplock_break(brk_opinfo, SMB2_OPLOCK_LEVEL_II);
1319+
oplock_break(brk_opinfo, SMB2_OPLOCK_LEVEL_II, work);
13271320
opinfo_put(brk_opinfo);
13281321
}
13291322

@@ -1386,7 +1379,7 @@ void smb_break_all_levII_oplock(struct ksmbd_work *work, struct ksmbd_file *fp,
13861379
SMB2_LEASE_KEY_SIZE))
13871380
goto next;
13881381
brk_op->open_trunc = is_trunc;
1389-
oplock_break(brk_op, SMB2_OPLOCK_LEVEL_NONE);
1382+
oplock_break(brk_op, SMB2_OPLOCK_LEVEL_NONE, NULL);
13901383
next:
13911384
opinfo_put(brk_op);
13921385
rcu_read_lock();

fs/smb/server/oplock.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ struct oplock_info {
6767
bool is_lease;
6868
bool open_trunc; /* truncate on open */
6969
struct lease *o_lease;
70-
struct list_head interim_list;
7170
struct list_head op_entry;
7271
struct list_head lease_entry;
7372
wait_queue_head_t oplock_q; /* Other server threads */

0 commit comments

Comments
 (0)