Commit 3c21ff8
ksmbd: fix use-after-free and NULL deref in smb_grant_oplock()
smb_grant_oplock() has two issues in the oplock publication sequence:
1) opinfo is linked into ci->m_op_list (via opinfo_add) before
add_lease_global_list() is called. If add_lease_global_list()
fails (kmalloc returns NULL), the error path frees the opinfo
via __free_opinfo() while it is still linked in ci->m_op_list.
Concurrent m_op_list readers (opinfo_get_list, or direct iteration
in smb_break_all_levII_oplock) dereference the freed node.
2) opinfo->o_fp is assigned after add_lease_global_list() publishes
the opinfo on the global lease list. A concurrent
find_same_lease_key() can walk the lease list and dereference
opinfo->o_fp->f_ci while o_fp is still NULL.
Fix by restructuring the publication sequence to eliminate post-publish
failure:
- Set opinfo->o_fp before any list publication (fixes NULL deref).
- Preallocate lease_table via alloc_lease_table() before opinfo_add()
so add_lease_global_list() becomes infallible after publication.
- Keep the original m_op_list publication order (opinfo_add before
lease list) so concurrent opens via same_client_has_lease() and
opinfo_get_list() still see the in-flight grant.
- Use opinfo_put() instead of __free_opinfo() on err_out so that
the RCU-deferred free path is used.
This also requires splitting add_lease_global_list() to take a
preallocated lease_table and changing its return type from int to void,
since it can no longer fail.
Fixes: 1dfd062caa16 ("ksmbd: fix use-after-free by using call_rcu() for oplock_info")
Cc: stable@vger.kernel.org
Signed-off-by: Werner Kasselman <werner@verivus.com>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>1 parent 4834238 commit 3c21ff8
1 file changed
Lines changed: 45 additions & 28 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
91 | | - | |
| 91 | + | |
92 | 92 | | |
93 | | - | |
94 | | - | |
95 | | - | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
96 | 104 | | |
97 | 105 | | |
98 | 106 | | |
| |||
1256 | 1264 | | |
1257 | 1265 | | |
1258 | 1266 | | |
1259 | | - | |
| 1267 | + | |
| 1268 | + | |
1260 | 1269 | | |
1261 | 1270 | | |
1262 | 1271 | | |
1263 | | - | |
| 1272 | + | |
1264 | 1273 | | |
1265 | 1274 | | |
1266 | 1275 | | |
1267 | 1276 | | |
1268 | 1277 | | |
1269 | | - | |
1270 | | - | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
1271 | 1281 | | |
1272 | 1282 | | |
1273 | | - | |
1274 | | - | |
1275 | | - | |
1276 | | - | |
1277 | | - | |
1278 | | - | |
1279 | | - | |
1280 | | - | |
1281 | | - | |
1282 | | - | |
1283 | | - | |
| 1283 | + | |
1284 | 1284 | | |
1285 | | - | |
1286 | | - | |
| 1285 | + | |
| 1286 | + | |
1287 | 1287 | | |
1288 | 1288 | | |
1289 | 1289 | | |
| |||
1407 | 1407 | | |
1408 | 1408 | | |
1409 | 1409 | | |
| 1410 | + | |
1410 | 1411 | | |
1411 | 1412 | | |
1412 | 1413 | | |
| |||
1509 | 1510 | | |
1510 | 1511 | | |
1511 | 1512 | | |
1512 | | - | |
1513 | | - | |
1514 | | - | |
| 1513 | + | |
| 1514 | + | |
| 1515 | + | |
| 1516 | + | |
| 1517 | + | |
| 1518 | + | |
| 1519 | + | |
| 1520 | + | |
| 1521 | + | |
| 1522 | + | |
| 1523 | + | |
1515 | 1524 | | |
1516 | | - | |
1517 | | - | |
| 1525 | + | |
| 1526 | + | |
| 1527 | + | |
1518 | 1528 | | |
| 1529 | + | |
1519 | 1530 | | |
1520 | 1531 | | |
| 1532 | + | |
| 1533 | + | |
| 1534 | + | |
| 1535 | + | |
| 1536 | + | |
| 1537 | + | |
1521 | 1538 | | |
1522 | | - | |
1523 | 1539 | | |
1524 | 1540 | | |
1525 | 1541 | | |
1526 | | - | |
| 1542 | + | |
| 1543 | + | |
1527 | 1544 | | |
1528 | 1545 | | |
1529 | 1546 | | |
| |||
0 commit comments