Skip to content

Commit 4095501

Browse files
alikhaledismfrench
authored andcommitted
ksmbd: fix use-after-free in proc_show_files due to early rcu_read_unlock
The opinfo pointer obtained via rcu_dereference(fp->f_opinfo) is dereferenced after rcu_read_unlock(), creating a use-after-free window. A concurrent opinfo_put() can free the opinfo between the unlock and the subsequent access to opinfo->is_lease, opinfo->o_lease->state, and opinfo->level. Fix this by deferring rcu_read_unlock() until after all opinfo field accesses are complete. The values needed (const_names, count, level) are copied into local variables under the RCU read lock, and the potentially-sleeping seq_printf calls happen after the lock is released. Found by AI-assisted code review (Claude Opus 4.6, Anthropic) in collaboration with Ali Khaledi. Cc: [email protected] Fixes: b38f99c ("ksmbd: add procfs interface for runtime monitoring and statistics") Signed-off-by: Ali Khaledi <[email protected]> Acked-by: Namjae Jeon <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent c15e7c6 commit 4095501

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

fs/smb/server/vfs_cache.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,7 @@ static int proc_show_files(struct seq_file *m, void *v)
8787

8888
rcu_read_lock();
8989
opinfo = rcu_dereference(fp->f_opinfo);
90-
rcu_read_unlock();
91-
92-
if (!opinfo) {
93-
seq_printf(m, " %-15s", " ");
94-
} else {
90+
if (opinfo) {
9591
const struct ksmbd_const_name *const_names;
9692
int count;
9793
unsigned int level;
@@ -105,8 +101,12 @@ static int proc_show_files(struct seq_file *m, void *v)
105101
count = ARRAY_SIZE(ksmbd_oplock_const_names);
106102
level = opinfo->level;
107103
}
104+
rcu_read_unlock();
108105
ksmbd_proc_show_const_name(m, " %-15s",
109106
const_names, count, level);
107+
} else {
108+
rcu_read_unlock();
109+
seq_printf(m, " %-15s", " ");
110110
}
111111

112112
seq_printf(m, " %#010x %#010x %s\n",

0 commit comments

Comments
 (0)