Skip to content

Commit 6f582b2

Browse files
piastrysmfrench
authored andcommitted
CIFS: Fix NULL-pointer dereference in smb2_push_mandatory_locks
Currently when the client creates a cifsFileInfo structure for a newly opened file, it allocates a list of byte-range locks with a pointer to the new cfile and attaches this list to the inode's lock list. The latter happens before initializing all other fields, e.g. cfile->tlink. Thus a partially initialized cifsFileInfo structure becomes available to other threads that walk through the inode's lock list. One example of such a thread may be an oplock break worker thread that tries to push all cached byte-range locks. This causes NULL-pointer dereference in smb2_push_mandatory_locks() when accessing cfile->tlink: [598428.945633] BUG: kernel NULL pointer dereference, address: 0000000000000038 ... [598428.945749] Workqueue: cifsoplockd cifs_oplock_break [cifs] [598428.945793] RIP: 0010:smb2_push_mandatory_locks+0xd6/0x5a0 [cifs] ... [598428.945834] Call Trace: [598428.945870] ? cifs_revalidate_mapping+0x45/0x90 [cifs] [598428.945901] cifs_oplock_break+0x13d/0x450 [cifs] [598428.945909] process_one_work+0x1db/0x380 [598428.945914] worker_thread+0x4d/0x400 [598428.945921] kthread+0x104/0x140 [598428.945925] ? process_one_work+0x380/0x380 [598428.945931] ? kthread_park+0x80/0x80 [598428.945937] ret_from_fork+0x35/0x40 Fix this by reordering initialization steps of the cifsFileInfo structure: initialize all the fields first and then add the new byte-range lock list to the inode's lock list. Cc: Stable <[email protected]> Signed-off-by: Pavel Shilovsky <[email protected]> Reviewed-by: Aurelien Aptel <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 21b26d2 commit 6f582b2

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

fs/cifs/file.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,6 @@ cifs_new_fileinfo(struct cifs_fid *fid, struct file *file,
315315
INIT_LIST_HEAD(&fdlocks->locks);
316316
fdlocks->cfile = cfile;
317317
cfile->llist = fdlocks;
318-
cifs_down_write(&cinode->lock_sem);
319-
list_add(&fdlocks->llist, &cinode->llist);
320-
up_write(&cinode->lock_sem);
321318

322319
cfile->count = 1;
323320
cfile->pid = current->tgid;
@@ -342,6 +339,10 @@ cifs_new_fileinfo(struct cifs_fid *fid, struct file *file,
342339
oplock = 0;
343340
}
344341

342+
cifs_down_write(&cinode->lock_sem);
343+
list_add(&fdlocks->llist, &cinode->llist);
344+
up_write(&cinode->lock_sem);
345+
345346
spin_lock(&tcon->open_file_lock);
346347
if (fid->pending_open->oplock != CIFS_OPLOCK_NO_CHANGE && oplock)
347348
oplock = fid->pending_open->oplock;

0 commit comments

Comments
 (0)