Skip to content

Commit f484a79

Browse files
mikechristiemartinkpetersen
authored andcommitted
scsi: iscsi_tcp: Fix UAF during login when accessing the shost ipaddress
If during iscsi_sw_tcp_session_create() iscsi_tcp_r2tpool_alloc() fails, userspace could be accessing the host's ipaddress attr. If we then free the session via iscsi_session_teardown() while userspace is still accessing the session we will hit a use after free bug. Set the tcp_sw_host->session after we have completed session creation and can no longer fail. Link: https://lore.kernel.org/r/20230117193937.21244-3-michael.christie@oracle.com Signed-off-by: Mike Christie <michael.christie@oracle.com> Reviewed-by: Lee Duncan <lduncan@suse.com> Acked-by: Ding Hui <dinghui@sangfor.com.cn> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 6f1d64b commit f484a79

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

drivers/scsi/iscsi_tcp.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ static int iscsi_sw_tcp_host_get_param(struct Scsi_Host *shost,
849849
enum iscsi_host_param param, char *buf)
850850
{
851851
struct iscsi_sw_tcp_host *tcp_sw_host = iscsi_host_priv(shost);
852-
struct iscsi_session *session = tcp_sw_host->session;
852+
struct iscsi_session *session;
853853
struct iscsi_conn *conn;
854854
struct iscsi_tcp_conn *tcp_conn;
855855
struct iscsi_sw_tcp_conn *tcp_sw_conn;
@@ -859,6 +859,7 @@ static int iscsi_sw_tcp_host_get_param(struct Scsi_Host *shost,
859859

860860
switch (param) {
861861
case ISCSI_HOST_PARAM_IPADDRESS:
862+
session = tcp_sw_host->session;
862863
if (!session)
863864
return -ENOTCONN;
864865

@@ -959,11 +960,13 @@ iscsi_sw_tcp_session_create(struct iscsi_endpoint *ep, uint16_t cmds_max,
959960
if (!cls_session)
960961
goto remove_host;
961962
session = cls_session->dd_data;
962-
tcp_sw_host = iscsi_host_priv(shost);
963-
tcp_sw_host->session = session;
964963

965964
if (iscsi_tcp_r2tpool_alloc(session))
966965
goto remove_session;
966+
967+
/* We are now fully setup so expose the session to sysfs. */
968+
tcp_sw_host = iscsi_host_priv(shost);
969+
tcp_sw_host->session = session;
967970
return cls_session;
968971

969972
remove_session:

0 commit comments

Comments
 (0)