From patchwork Tue Apr 2 19:58:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10882277 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B50D2139A for ; Tue, 2 Apr 2019 19:58:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9FABD2875F for ; Tue, 2 Apr 2019 19:58:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 94571288D7; Tue, 2 Apr 2019 19:58:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3D1F12875F for ; Tue, 2 Apr 2019 19:58:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726396AbfDBT6g (ORCPT ); Tue, 2 Apr 2019 15:58:36 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:39088 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726157AbfDBT6g (ORCPT ); Tue, 2 Apr 2019 15:58:36 -0400 Received: by mail-pg1-f196.google.com with SMTP id k3so7079001pga.6 for ; Tue, 02 Apr 2019 12:58:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=o/1TOsKw9dGiw9Lvusb7zBcwbGG0jQBnLmV36q+mCqk=; b=T79Pi0WVlDvcoDQ89nYWcaU7oAjelKlpdgOzJYHIPVLvQwynUKoEeVMGCAhiqpVSJo RkgkTiiXbJOzsQ/FYXo28Ltt1V3gDiNkupDZla9RCUv6mISeZoQfaS581rONMzo++B5d of9BpL15cEOYjakQyMO0WhwubkIZza0JEr5bdRTmQsJqdSiYlNbypQzsovhRKwM1HbUr voHk09GPuJA2L2KO0TRnER6uYjFZ4xqCYKVMqRnlh9OfYObmWp7P+CnFJ9aw+rOVDLPv 5lR5QB180SkvtStaBDMB6Ds0HHFYoJBkJ6466YOvKLzzlgfi7/WZtG35mqKHHhlziMVn Aodg== X-Gm-Message-State: APjAAAW7rMoWKr7Xg9PxMXg9ZuyWLvgRO5IuV7cwiDfoeS3kcyR1o4sr tIwYRbj4ASd2S+josEeqKLc= X-Google-Smtp-Source: APXvYqzwNfaWapmprMO3p0frps3AFlR3ieWkoxjJDs8/LLDdKHbxW7SVt6GvNT9WDlK9PyRiMWx3Wg== X-Received: by 2002:a63:7e10:: with SMTP id z16mr15280604pgc.40.1554235115873; Tue, 02 Apr 2019 12:58:35 -0700 (PDT) Received: from desktop-bart.svl.corp.google.com ([2620:15c:2cd:203:5cdc:422c:7b28:ebb5]) by smtp.gmail.com with ESMTPSA id o5sm49055490pfa.135.2019.04.02.12.58.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Apr 2019 12:58:34 -0700 (PDT) From: Bart Van Assche To: "Martin K . Petersen" Cc: Mike Christie , Christoph Hellwig , target-devel@vger.kernel.org, Bart Van Assche , Mike Christie , Hannes Reinecke , Nicholas Bellinger Subject: [PATCH 07/11] target/iscsi: Detect conn_cmd_list corruption early Date: Tue, 2 Apr 2019 12:58:11 -0700 Message-Id: <20190402195815.254796-8-bvanassche@acm.org> X-Mailer: git-send-email 2.20.GIT In-Reply-To: <20190402195815.254796-1-bvanassche@acm.org> References: <20190402195815.254796-1-bvanassche@acm.org> MIME-Version: 1.0 Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Certain behavior of an initiator can cause the target driver to send both a reject and a SCSI response. If that happens two target_put_sess_cmd() calls will occur without the command having been removed from conn_cmd_list. In other words, conn_cmd_list will get corrupted once the freed memory is reused. Although the Linux kernel can detect list corruption if list debugging is enabled, in this case the context in which list corruption is detected is not related to the context that caused list corruption. Hence add WARN_ON() statements that report the context that is causing list corruption. Cc: Mike Christie Cc: Christoph Hellwig Cc: Hannes Reinecke Cc: Nicholas Bellinger Signed-off-by: Bart Van Assche --- drivers/target/iscsi/iscsi_target_util.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/target/iscsi/iscsi_target_util.c b/drivers/target/iscsi/iscsi_target_util.c index 3ac494f63a0b..3da062ccd2ab 100644 --- a/drivers/target/iscsi/iscsi_target_util.c +++ b/drivers/target/iscsi/iscsi_target_util.c @@ -769,6 +769,8 @@ void iscsit_free_cmd(struct iscsi_cmd *cmd, bool shutdown) struct se_cmd *se_cmd = cmd->se_cmd.se_tfo ? &cmd->se_cmd : NULL; int rc; + WARN_ON(!list_empty(&cmd->i_conn_node)); + __iscsit_free_cmd(cmd, shutdown); if (se_cmd) { rc = transport_generic_free_cmd(se_cmd, shutdown);