Skip to content

Commit bcf3a29

Browse files
MarkMielkemartinkpetersen
authored andcommitted
scsi: iscsi: iscsi_tcp: Avoid holding spinlock while calling getpeername()
The kernel may fail to boot or devices may fail to come up when initializing iscsi_tcp devices starting with Linux 5.8. Commit a79af8a ("[SCSI] iscsi_tcp: use iscsi_conn_get_addr_param libiscsi function") introduced getpeername() within the session spinlock. Commit 1b66d25 ("bpf: Add get{peer, sock}name attach types for sock_addr") introduced BPF_CGROUP_RUN_SA_PROG_LOCK() within getpeername(), which acquires a mutex and when used from iscsi_tcp devices can now lead to "BUG: scheduling while atomic:" and subsequent damage. Ensure that the spinlock is released before calling getpeername() or getsockname(). sock_hold() and sock_put() are used to ensure that the socket reference is preserved until after the getpeername() or getsockname() complete. Link: https://bugzilla.redhat.com/show_bug.cgi?id=1877345 Link: https://lkml.org/lkml/2020/7/28/1085 Link: https://lkml.org/lkml/2020/8/31/459 Link: https://lore.kernel.org/r/[email protected] Fixes: a79af8a ("[SCSI] iscsi_tcp: use iscsi_conn_get_addr_param libiscsi function") Fixes: 1b66d25 ("bpf: Add get{peer, sock}name attach types for sock_addr") Cc: [email protected] Reported-by: Marc Dionne <[email protected]> Tested-by: Marc Dionne <[email protected]> Reviewed-by: Mike Christie <[email protected]> Signed-off-by: Mark Mielke <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 1494155 commit bcf3a29

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

drivers/scsi/iscsi_tcp.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,7 @@ static int iscsi_sw_tcp_conn_get_param(struct iscsi_cls_conn *cls_conn,
736736
struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
737737
struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
738738
struct sockaddr_in6 addr;
739+
struct socket *sock;
739740
int rc;
740741

741742
switch(param) {
@@ -747,13 +748,17 @@ static int iscsi_sw_tcp_conn_get_param(struct iscsi_cls_conn *cls_conn,
747748
spin_unlock_bh(&conn->session->frwd_lock);
748749
return -ENOTCONN;
749750
}
751+
sock = tcp_sw_conn->sock;
752+
sock_hold(sock->sk);
753+
spin_unlock_bh(&conn->session->frwd_lock);
754+
750755
if (param == ISCSI_PARAM_LOCAL_PORT)
751-
rc = kernel_getsockname(tcp_sw_conn->sock,
756+
rc = kernel_getsockname(sock,
752757
(struct sockaddr *)&addr);
753758
else
754-
rc = kernel_getpeername(tcp_sw_conn->sock,
759+
rc = kernel_getpeername(sock,
755760
(struct sockaddr *)&addr);
756-
spin_unlock_bh(&conn->session->frwd_lock);
761+
sock_put(sock->sk);
757762
if (rc < 0)
758763
return rc;
759764

@@ -775,6 +780,7 @@ static int iscsi_sw_tcp_host_get_param(struct Scsi_Host *shost,
775780
struct iscsi_tcp_conn *tcp_conn;
776781
struct iscsi_sw_tcp_conn *tcp_sw_conn;
777782
struct sockaddr_in6 addr;
783+
struct socket *sock;
778784
int rc;
779785

780786
switch (param) {
@@ -789,16 +795,18 @@ static int iscsi_sw_tcp_host_get_param(struct Scsi_Host *shost,
789795
return -ENOTCONN;
790796
}
791797
tcp_conn = conn->dd_data;
792-
793798
tcp_sw_conn = tcp_conn->dd_data;
794-
if (!tcp_sw_conn->sock) {
799+
sock = tcp_sw_conn->sock;
800+
if (!sock) {
795801
spin_unlock_bh(&session->frwd_lock);
796802
return -ENOTCONN;
797803
}
804+
sock_hold(sock->sk);
805+
spin_unlock_bh(&session->frwd_lock);
798806

799-
rc = kernel_getsockname(tcp_sw_conn->sock,
807+
rc = kernel_getsockname(sock,
800808
(struct sockaddr *)&addr);
801-
spin_unlock_bh(&session->frwd_lock);
809+
sock_put(sock->sk);
802810
if (rc < 0)
803811
return rc;
804812

0 commit comments

Comments
 (0)