Commit f1abcb4
ksmbd: fix memory leaks and NULL deref in smb2_lock()
smb2_lock() has three error handling issues after list_del() detaches
smb_lock from lock_list at no_check_cl:
1) If vfs_lock_file() returns an unexpected error in the non-UNLOCK
path, goto out leaks smb_lock and its flock because the out:
handler only iterates lock_list and rollback_list, neither of
which contains the detached smb_lock.
2) If vfs_lock_file() returns -ENOENT in the UNLOCK path, goto out
leaks smb_lock and flock for the same reason. The error code
returned to the dispatcher is also stale.
3) In the rollback path, smb_flock_init() can return NULL on
allocation failure. The result is dereferenced unconditionally,
causing a kernel NULL pointer dereference. Add a NULL check to
prevent the crash and clean up the bookkeeping; the VFS lock
itself cannot be rolled back without the allocation and will be
released at file or connection teardown.
Fix cases 1 and 2 by hoisting the locks_free_lock()/kfree() to before
the if(!rc) check in the UNLOCK branch so all exit paths share one
free site, and by freeing smb_lock and flock before goto out in the
non-UNLOCK branch. Propagate the correct error code in both cases.
Fix case 3 by wrapping the VFS unlock in an if(rlock) guard and adding
a NULL check for locks_free_lock(rlock) in the shared cleanup.
Found via call-graph analysis using sqry.
Fixes: e2f34481b24d ("cifsd: add server-side procedures for SMB3")
Cc: stable@vger.kernel.org
Suggested-by: ChenXiaoSong <chenxiaosong@kylinos.cn>
Signed-off-by: Werner Kasselman <werner@verivus.com>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>1 parent c89936e commit f1abcb4
1 file changed
Lines changed: 19 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8197 | 8197 | | |
8198 | 8198 | | |
8199 | 8199 | | |
| 8200 | + | |
| 8201 | + | |
8200 | 8202 | | |
8201 | 8203 | | |
8202 | 8204 | | |
8203 | 8205 | | |
| 8206 | + | |
8204 | 8207 | | |
8205 | 8208 | | |
8206 | | - | |
8207 | | - | |
8208 | 8209 | | |
8209 | 8210 | | |
8210 | 8211 | | |
| |||
8273 | 8274 | | |
8274 | 8275 | | |
8275 | 8276 | | |
| 8277 | + | |
| 8278 | + | |
| 8279 | + | |
8276 | 8280 | | |
8277 | 8281 | | |
8278 | 8282 | | |
| |||
8303 | 8307 | | |
8304 | 8308 | | |
8305 | 8309 | | |
| 8310 | + | |
8306 | 8311 | | |
8307 | | - | |
| 8312 | + | |
8308 | 8313 | | |
8309 | | - | |
| 8314 | + | |
8310 | 8315 | | |
8311 | | - | |
8312 | | - | |
| 8316 | + | |
| 8317 | + | |
8313 | 8318 | | |
8314 | | - | |
8315 | | - | |
8316 | | - | |
| 8319 | + | |
| 8320 | + | |
| 8321 | + | |
| 8322 | + | |
| 8323 | + | |
| 8324 | + | |
8317 | 8325 | | |
8318 | 8326 | | |
8319 | 8327 | | |
| |||
8323 | 8331 | | |
8324 | 8332 | | |
8325 | 8333 | | |
8326 | | - | |
| 8334 | + | |
| 8335 | + | |
8327 | 8336 | | |
8328 | 8337 | | |
8329 | 8338 | | |
| |||
0 commit comments