Commit 9c4a232
committed
cifs: fix potential use-after-free bugs in TCP_Server_Info::hostname
jira VULN-169227
cve CVE-2023-53751
commit-author Paulo Alcantara <pc@manguebit.com>
commit 90c49fc
upstream-diff |
fs/cifs/cifsglob.h
Added `srv_lock' to the `TCP_Server_Info' struct as it was done in
the non-backported commit d7d7a66
("cifs: avoid use of global locks for high contention data").
fs/cifs/cifs_debug.c
Ignored changes in `cifs_debug_data_proc_show()' because the code
using `hostname' was only added in the non-backported commit
40f077a ("cifs: clarify hostname
vs ip address in /proc/fs/cifs/DebugData").
fs/cifs/connect.c
- Changed the `reconn_set_next_dfs_target()' function instead of
`__reconnect_target_unlocked()' which doesn't exist in LTS
8.6. The `__reconnect_target_unlocked()' is where the `hostname'
is "updated once or many times during reconnect" (see original
commit message). The "reconnect" refers to the function
`cifs_reconnect()', which calls `__reconnect_target_unlocked()'
on a third level down the call tree. Relative to LTS 8.6 the
`cifs_reconnect()' underwent major rewrites in the commits
bbcce36 ("cifs: split out dfs
code from cifs_reconnect()") and
c88f7dc ("cifs: support nested
dfs links over reconnect"). In LTS 8.6 the updating of
`hostname' can be tracked down to the
`reconn_set_next_dfs_target()' function called by
`cifs_reconnect()'. Apart from guarding the `server->hostname'
value change some elements of the commit bbcce36 were included
as well:
- Used helper local variable `hostname' to store the value of
`extract_hostname()' to avoid calling it while locked, which
could lead to a schedule while atomic.
- Avoided assigning to `server->hostname' the result of
`extract_hostname()' call in case it ended with
error. Otherwise `server->hostname' would contain
rubbish. Added a debug message informing about that case.
- Added initialization of `TCP_Server_Info::srv_lock' in
`cifs_get_tcp_session()' as it's done in d7d7a66.
- In `match_server()' sandwiched the `strcasecmp(server->hostname,
...)' call in the lock/unlock pair of `server->srv_lock',
because in LTS 8.6 the `match_server()' is not called with the
`server->srv_lock' held and yet this is the lock chosen to
protect the `server->hostname' field.
fs/cifs/sess.c
Ignored changes in `cifs_try_adding_channels()' because the code
using `hostname' was only added in the non-backported commit
9c2dc11 ("smb3: do not attempt
multichannel to server which does not support it"). As a result no
changes to the file have been made.
TCP_Server_Info::hostname may be updated once or many times during
reconnect, so protect its access outside reconnect path as well and
then prevent any potential use-after-free bugs.
Cc: stable@vger.kernel.org
Signed-off-by: Paulo Alcantara (SUSE) <pc@manguebit.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
(cherry picked from commit 90c49fc)
Signed-off-by: Marcin Wcisło <marcin.wcislo@conclusive.pl>1 parent 47e8a2d commit 9c4a232
4 files changed
Lines changed: 31 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
609 | 609 | | |
610 | 610 | | |
611 | 611 | | |
612 | | - | |
| 612 | + | |
| 613 | + | |
613 | 614 | | |
614 | 615 | | |
615 | 616 | | |
| 617 | + | |
| 618 | + | |
616 | 619 | | |
617 | 620 | | |
618 | 621 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
98 | | - | |
99 | | - | |
100 | | - | |
| 98 | + | |
101 | 99 | | |
102 | 100 | | |
103 | | - | |
| 101 | + | |
| 102 | + | |
104 | 103 | | |
105 | 104 | | |
106 | | - | |
| 105 | + | |
107 | 106 | | |
108 | 107 | | |
109 | | - | |
| 108 | + | |
110 | 109 | | |
| 110 | + | |
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
580 | 580 | | |
581 | 581 | | |
582 | 582 | | |
| 583 | + | |
583 | 584 | | |
584 | 585 | | |
585 | 586 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
| 133 | + | |
133 | 134 | | |
134 | 135 | | |
135 | 136 | | |
| |||
147 | 148 | | |
148 | 149 | | |
149 | 150 | | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
154 | 158 | | |
155 | 159 | | |
156 | | - | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
157 | 163 | | |
158 | 164 | | |
159 | 165 | | |
| |||
418 | 424 | | |
419 | 425 | | |
420 | 426 | | |
421 | | - | |
422 | | - | |
423 | | - | |
| 427 | + | |
424 | 428 | | |
425 | 429 | | |
426 | 430 | | |
| |||
1194 | 1198 | | |
1195 | 1199 | | |
1196 | 1200 | | |
1197 | | - | |
| 1201 | + | |
| 1202 | + | |
| 1203 | + | |
1198 | 1204 | | |
| 1205 | + | |
| 1206 | + | |
1199 | 1207 | | |
1200 | 1208 | | |
1201 | 1209 | | |
| |||
1343 | 1351 | | |
1344 | 1352 | | |
1345 | 1353 | | |
| 1354 | + | |
1346 | 1355 | | |
1347 | 1356 | | |
1348 | 1357 | | |
| |||
1512 | 1521 | | |
1513 | 1522 | | |
1514 | 1523 | | |
| 1524 | + | |
1515 | 1525 | | |
| 1526 | + | |
1516 | 1527 | | |
1517 | 1528 | | |
1518 | 1529 | | |
| |||
0 commit comments