linux_dsm_epyc7002/drivers/s390/scsi
Steffen Maier 2d9a2c5f58 scsi: zfcp: Fix use-after-free in request timeout handlers
Before v4.15 commit 75492a5156 ("s390/scsi: Convert timers to use
timer_setup()"), we intentionally only passed zfcp_adapter as context
argument to zfcp_fsf_request_timeout_handler(). Since we only trigger
adapter recovery, it was unnecessary to sync against races between timeout
and (late) completion.  Likewise, we only passed zfcp_erp_action as context
argument to zfcp_erp_timeout_handler(). Since we only wakeup an ERP action,
it was unnecessary to sync against races between timeout and (late)
completion.

Meanwhile the timeout handlers get timer_list as context argument and do a
timer-specific container-of to zfcp_fsf_req which can have been freed.

Fix it by making sure that any request timeout handlers, that might just
have started before del_timer(), are completed by using del_timer_sync()
instead. This ensures the request free happens afterwards.

Space time diagram of potential use-after-free:

Basic idea is to have 2 or more pending requests whose timeouts run out at
almost the same time.

req 1 timeout     ERP thread        req 2 timeout
----------------  ----------------  ---------------------------------------
zfcp_fsf_request_timeout_handler
fsf_req = from_timer(fsf_req, t, timer)
adapter = fsf_req->adapter
zfcp_qdio_siosl(adapter)
zfcp_erp_adapter_reopen(adapter,...)
                  zfcp_erp_strategy
                  ...
                  zfcp_fsf_req_dismiss_all
                  list_for_each_entry_safe
                    zfcp_fsf_req_complete 1
                    del_timer 1
                    zfcp_fsf_req_free 1
                    zfcp_fsf_req_complete 2
                                    zfcp_fsf_request_timeout_handler
                    del_timer 2
                                    fsf_req = from_timer(fsf_req, t, timer)
                    zfcp_fsf_req_free 2
                                    adapter = fsf_req->adapter
                                              ^^^^^^^ already freed

Link: https://lore.kernel.org/r/20200813152856.50088-1-maier@linux.ibm.com
Fixes: 75492a5156 ("s390/scsi: Convert timers to use timer_setup()")
Cc: <stable@vger.kernel.org> #4.15+
Suggested-by: Julian Wiedmann <jwi@linux.ibm.com>
Reviewed-by: Julian Wiedmann <jwi@linux.ibm.com>
Signed-off-by: Steffen Maier <maier@linux.ibm.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2020-08-17 22:12:09 -04:00
..
Makefile scsi: zfcp: diagnostics buffer caching and use for exchange port data 2019-10-28 22:16:14 -04:00
zfcp_aux.c scsi: zfcp: Move allocation of the shost object to after xconf- and xport-data 2020-05-11 23:19:52 -04:00
zfcp_ccw.c scsi: zfcp: Replace open-coded list move 2020-07-08 00:50:55 -04:00
zfcp_dbf.c scsi: zfcp: trace FC Endpoint Security of FCP devices and connections 2020-03-17 13:12:40 -04:00
zfcp_dbf.h scsi: zfcp: trace FC Endpoint Security of FCP devices and connections 2020-03-17 13:12:40 -04:00
zfcp_def.h scsi: zfcp: trace FC Endpoint Security of FCP devices and connections 2020-03-17 13:12:40 -04:00
zfcp_diag.c scsi: zfcp: move maximum age of diagnostic buffers into a per-adapter variable 2019-10-28 22:16:15 -04:00
zfcp_diag.h scsi: zfcp: Move allocation of the shost object to after xconf- and xport-data 2020-05-11 23:19:52 -04:00
zfcp_erp.c SCSI misc on 20200806 2020-08-06 16:50:07 -07:00
zfcp_ext.h scsi: zfcp: Move allocation of the shost object to after xconf- and xport-data 2020-05-11 23:19:52 -04:00
zfcp_fc.c scsi: zfcp: Use prandom_u32_max() for backoff 2020-07-08 00:50:52 -04:00
zfcp_fc.h scsi: zfcp: silence remaining kdoc warnings in header files 2018-11-15 15:01:18 -05:00
zfcp_fsf.c scsi: zfcp: Fix use-after-free in request timeout handlers 2020-08-17 22:12:09 -04:00
zfcp_fsf.h SCSI misc on 20200402 2020-04-02 17:03:53 -07:00
zfcp_qdio.c scsi: zfcp: Avoid benign overflow of the Request Queue's free-level 2020-07-08 00:50:56 -04:00
zfcp_qdio.h s390/qdio: fill SBALEs with absolute addresses 2020-02-19 17:26:32 +01:00
zfcp_reqlist.h scsi: zfcp: silence remaining kdoc warnings in header files 2018-11-15 15:01:18 -05:00
zfcp_scsi.c scsi: zfcp: Move allocation of the shost object to after xconf- and xport-data 2020-05-11 23:19:52 -04:00
zfcp_sysfs.c scsi: zfcp: Fence early sysfs interfaces for accesses of shost objects 2020-05-11 23:19:50 -04:00
zfcp_unit.c scsi: zfcp: fix to prevent port_remove with pure auto scan LUNs (only sdevs) 2019-05-29 21:52:31 -04:00