Commit 9d7bba3
committed
cifs: protect access of TCP_Server_Info::{dstaddr,hostname}
jira VULN-169227
cve CVE-2023-53751
commit-author Paulo Alcantara <pc@cjr.nz>
commit 39a154f
upstream-diff Manually obtained commit. Upstream fixes appear in
multiple places, but they all cover only the `cifs_tree_connect()'
function (the CONFIG_CIFS_DFS_UPCALL=y variant) and its call tree. Same
goes for the backported version, taking into account the lack of a major
function rewrite in c88f7dc ("cifs:
support nested dfs links over reconnect").
Upstream call tree at the moment of the fix and the changes at each
level:
cifs_tree_connect()
Put `cifs_server_{lock/unlock}(server)' around `scnprintf(...,
server->hostname);' call.
tree_connect_dfs_target()
No changes.
__tree_connect_dfs_target()
Removed `extract_unc_hostname(server->hostname, ...)' call, used
full `server->hostname' instead of its substring `tcp_host'.
target_share_matches_server()
Put `cifs_server_{lock/unlock}(server)' around
`server->hostname' accesses in conditional expression and debug
message composition before the `match_target_ip()' call.
match_target_ip()
Put `spin_{lock/unlock}(&server->srv_lock)' around
`cifs_match_ipaddr(...server->dstaddr, ....)' call.
Backported version call tree:
cifs_tree_connect()
- Put `cifs_server_{lock/unlock}(server)' around `scnprintf(...,
server->hostname)' call - like in the upstream.
- Put `cifs_server_{lock/unlock}(server)' around
`server->hostname' (and its substring `tcp_host') access in
conditional expression and debug message composition before
the `match_target_ip()' call - like in the upstream. This
required moving the `extract_unc_hostname()' call inside the
loop. Unlike in the upstream it was not removed entirely,
opting for functional equivalence between the patched and
non-patched version instead of strictly preserving backported
commit's changes; perhaps at the time of the upstream fix the
equality `server->hostname' = `tcp_host' held true, allowing
for the reduction of `extract_unc_hostname()' call, but that
was not certain for the ciqlts8_6 version. If it wasn't true
then the commit mixed a bugfix with a functional change which
was simply filtered out here. Moving `extract_unc_hostname()'
call inside the loop did not create any algorithmic
inconsistencies which weren't already present (if any), merely
preventing them from ending in bad memory access. In the
upstream the value of `server->hostname' isn't saved to remain
constant for all loop iterations in the
`__tree_connect_dfs_target()' function either. A ngeligible
performance penalty associated with the calculation redundancy
was accepted given the simplicity of the fix it allowed.
match_target_ip()
Put `spin_{lock/unlock}(&cifs_tcp_ses_lock)' around the
`cifs_match_ipaddr(...server->dstaddr, ...)' call - like in the
upstream, except for the `cifs_tcp_ses_lock' instead of
`server->srv_lock'. The latter was introduced in the
non-backported commit d7d7a66
("cifs: avoid use of global locks for high contention
data"). The same pattern of protecting `server->dstaddr' with
`cifs_tcp_ses_lock' can be observed in ciqlts8_6 in the
`reconn_set_ipaddr_from_hostname()' function.
Use the appropriate locks to protect access of hostname and dstaddr
fields in cifs_tree_connect() as they might get changed by other
tasks.
Signed-off-by: Paulo Alcantara (SUSE) <pc@cjr.nz>
Reviewed-by: Enzo Matsumiya <ematsumiya@suse.de>
Signed-off-by: Steve French <stfrench@microsoft.com>
(cherry picked from commit 39a154f)
Signed-off-by: Marcin Wcisło <marcin.wcislo@conclusive.pl>1 parent 601cd8f commit 9d7bba3
2 files changed
Lines changed: 9 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4081 | 4081 | | |
4082 | 4082 | | |
4083 | 4083 | | |
| 4084 | + | |
4084 | 4085 | | |
| 4086 | + | |
4085 | 4087 | | |
4086 | 4088 | | |
4087 | 4089 | | |
| |||
4095 | 4097 | | |
4096 | 4098 | | |
4097 | 4099 | | |
4098 | | - | |
4099 | | - | |
4100 | 4100 | | |
4101 | 4101 | | |
4102 | 4102 | | |
| |||
4114 | 4114 | | |
4115 | 4115 | | |
4116 | 4116 | | |
| 4117 | + | |
| 4118 | + | |
4117 | 4119 | | |
4118 | 4120 | | |
4119 | 4121 | | |
4120 | 4122 | | |
| 4123 | + | |
4121 | 4124 | | |
4122 | 4125 | | |
4123 | 4126 | | |
| |||
4129 | 4132 | | |
4130 | 4133 | | |
4131 | 4134 | | |
4132 | | - | |
| 4135 | + | |
| 4136 | + | |
4133 | 4137 | | |
4134 | 4138 | | |
4135 | 4139 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1123 | 1123 | | |
1124 | 1124 | | |
1125 | 1125 | | |
| 1126 | + | |
1126 | 1127 | | |
1127 | 1128 | | |
| 1129 | + | |
1128 | 1130 | | |
1129 | 1131 | | |
1130 | 1132 | | |
| |||
0 commit comments