Skip to content

Commit 4b57abe

Browse files
dankamongmengregkh
authored andcommitted
scsi: iscsi: Don't destroy session if there are outstanding connections
[ Upstream commit 54155ed ] A faulty userspace that calls destroy_session() before destroying the connections can trigger the failure. This patch prevents the issue by refusing to destroy the session if there are outstanding connections. ------------[ cut here ]------------ kernel BUG at mm/slub.c:306! invalid opcode: 0000 [#1] SMP PTI CPU: 1 PID: 1224 Comm: iscsid Not tainted 5.4.0-rc2.iscsi+ khadas#7 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.12.0-1 04/01/2014 RIP: 0010:__slab_free+0x181/0x350 [...] [ 1209.686056] RSP: 0018:ffffa93d4074fae0 EFLAGS: 00010246 [ 1209.686694] RAX: ffff934efa5ad800 RBX: 000000008010000a RCX: ffff934efa5ad800 [ 1209.687651] RDX: ffff934efa5ad800 RSI: ffffeb4041e96b00 RDI: ffff934efd402c40 [ 1209.688582] RBP: ffffa93d4074fb80 R08: 0000000000000001 R09: ffffffffbb5dfa26 [ 1209.689425] R10: ffff934efa5ad800 R11: 0000000000000001 R12: ffffeb4041e96b00 [ 1209.690285] R13: ffff934efa5ad800 R14: ffff934efd402c40 R15: 0000000000000000 [ 1209.691213] FS: 00007f7945dfb540(0000) GS:ffff934efda80000(0000) knlGS:0000000000000000 [ 1209.692316] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 1209.693013] CR2: 000055877fd3da80 CR3: 0000000077384000 CR4: 00000000000006e0 [ 1209.693897] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 1209.694773] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 [ 1209.695631] Call Trace: [ 1209.695957] ? __wake_up_common_lock+0x8a/0xc0 [ 1209.696712] iscsi_pool_free+0x26/0x40 [ 1209.697263] iscsi_session_teardown+0x2f/0xf0 [ 1209.698117] iscsi_sw_tcp_session_destroy+0x45/0x60 [ 1209.698831] iscsi_if_rx+0xd88/0x14e0 [ 1209.699370] netlink_unicast+0x16f/0x200 [ 1209.699932] netlink_sendmsg+0x21a/0x3e0 [ 1209.700446] sock_sendmsg+0x4f/0x60 [ 1209.700902] ___sys_sendmsg+0x2ae/0x320 [ 1209.701451] ? cp_new_stat+0x150/0x180 [ 1209.701922] __sys_sendmsg+0x59/0xa0 [ 1209.702357] do_syscall_64+0x52/0x160 [ 1209.702812] entry_SYSCALL_64_after_hwframe+0x44/0xa9 [ 1209.703419] RIP: 0033:0x7f7946433914 [...] [ 1209.706084] RSP: 002b:00007fffb99f2378 EFLAGS: 00000246 ORIG_RAX: 000000000000002e [ 1209.706994] RAX: ffffffffffffffda RBX: 000055bc869eac20 RCX: 00007f7946433914 [ 1209.708082] RDX: 0000000000000000 RSI: 00007fffb99f2390 RDI: 0000000000000005 [ 1209.709120] RBP: 00007fffb99f2390 R08: 000055bc84fe9320 R09: 00007fffb99f1f07 [ 1209.710110] R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000038 [ 1209.711085] R13: 000055bc8502306e R14: 0000000000000000 R15: 0000000000000000 Modules linked in: ---[ end trace a2d933ede7f730d8 ]--- Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Nick Black <[email protected]> Co-developed-by: Salman Qazi <[email protected]> Signed-off-by: Salman Qazi <[email protected]> Co-developed-by: Junho Ryu <[email protected]> Signed-off-by: Junho Ryu <[email protected]> Co-developed-by: Khazhismel Kumykov <[email protected]> Signed-off-by: Khazhismel Kumykov <[email protected]> Co-developed-by: Gabriel Krisman Bertazi <[email protected]> Signed-off-by: Gabriel Krisman Bertazi <[email protected]> Reviewed-by: Lee Duncan <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 712ae1c commit 4b57abe

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

drivers/scsi/iscsi_tcp.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,10 @@ iscsi_sw_tcp_session_create(struct iscsi_endpoint *ep, uint16_t cmds_max,
882882
static void iscsi_sw_tcp_session_destroy(struct iscsi_cls_session *cls_session)
883883
{
884884
struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
885+
struct iscsi_session *session = cls_session->dd_data;
886+
887+
if (WARN_ON_ONCE(session->leadconn))
888+
return;
885889

886890
iscsi_tcp_r2tpool_free(cls_session->dd_data);
887891
iscsi_session_teardown(cls_session);

drivers/scsi/scsi_transport_iscsi.c

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2964,6 +2964,24 @@ iscsi_set_path(struct iscsi_transport *transport, struct iscsi_uevent *ev)
29642964
return err;
29652965
}
29662966

2967+
static int iscsi_session_has_conns(int sid)
2968+
{
2969+
struct iscsi_cls_conn *conn;
2970+
unsigned long flags;
2971+
int found = 0;
2972+
2973+
spin_lock_irqsave(&connlock, flags);
2974+
list_for_each_entry(conn, &connlist, conn_list) {
2975+
if (iscsi_conn_get_sid(conn) == sid) {
2976+
found = 1;
2977+
break;
2978+
}
2979+
}
2980+
spin_unlock_irqrestore(&connlock, flags);
2981+
2982+
return found;
2983+
}
2984+
29672985
static int
29682986
iscsi_set_iface_params(struct iscsi_transport *transport,
29692987
struct iscsi_uevent *ev, uint32_t len)
@@ -3538,10 +3556,12 @@ iscsi_if_recv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, uint32_t *group)
35383556
break;
35393557
case ISCSI_UEVENT_DESTROY_SESSION:
35403558
session = iscsi_session_lookup(ev->u.d_session.sid);
3541-
if (session)
3542-
transport->destroy_session(session);
3543-
else
3559+
if (!session)
35443560
err = -EINVAL;
3561+
else if (iscsi_session_has_conns(ev->u.d_session.sid))
3562+
err = -EBUSY;
3563+
else
3564+
transport->destroy_session(session);
35453565
break;
35463566
case ISCSI_UEVENT_UNBIND_SESSION:
35473567
session = iscsi_session_lookup(ev->u.d_session.sid);

0 commit comments

Comments
 (0)