From patchwork Thu Aug 23 20:36:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laura Abbott X-Patchwork-Id: 10574541 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 39813921 for ; Thu, 23 Aug 2018 20:36:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 264CF2C46D for ; Thu, 23 Aug 2018 20:36:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 181A02C613; Thu, 23 Aug 2018 20:36:41 +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 006402C46D for ; Thu, 23 Aug 2018 20:36:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727306AbeHXAIA (ORCPT ); Thu, 23 Aug 2018 20:08:00 -0400 Received: from mail-qt0-f195.google.com ([209.85.216.195]:45699 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726083AbeHXAH7 (ORCPT ); Thu, 23 Aug 2018 20:07:59 -0400 Received: by mail-qt0-f195.google.com with SMTP id g44-v6so7150943qtb.12 for ; Thu, 23 Aug 2018 13:36:37 -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; bh=z84Ml9KefdO2hOQNg672IvjZmE4HtkN1KhujmMnQdzI=; b=EGRHt0UUY8aIQWOEE8PziaPbfdpBcUs1QbFC8u41kDLZnHEGHO7wKVqtvp92jz8O99 4XjTcxnBu368KG3MpyExJ5tytDrD18/zb55p6tQKjpXYGjLxSTpxfot18o4J5Oru0lWz O+TKC9JuWvtOezp5VrNHEwTZftqyEFLzp7nwgBH3DWwO8cyzxVj9/lwdaUKsgNp0mxoB gfwD4iMotCBm7az2IOKIk4v9hKaftywLRKBc0EWygEhoAIeWfQP7uTI0GlgrjiLrojfJ 6eV/LsF4Y4ZSNH1wC9ZmSKwT2X41yTi1qQNvPxJXV1OjRcIUCwOAa6iL/ULqUJw6CcgP 9gYA== X-Gm-Message-State: AOUpUlGoxN64ZEjUFqg8WRnW4GtJSLx+08kiGs7Je1WBoyeZrp753qFo PDixamfFj7L3BNOX8YLTr/5ewg== X-Google-Smtp-Source: AA+uWPwr4ZROurU2WZkiM37+2awM4ID+Nt3NrQbWRpc191dqfCSW7Du18KFsM7Pgc1GyOCtdgxto2A== X-Received: by 2002:ac8:350f:: with SMTP id y15-v6mr19602174qtb.241.1535056597349; Thu, 23 Aug 2018 13:36:37 -0700 (PDT) Received: from labbott-redhat.redhat.com ([2601:602:9802:a8dc::7272]) by smtp.gmail.com with ESMTPSA id a34-v6sm1824644qta.56.2018.08.23.13.36.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 23 Aug 2018 13:36:36 -0700 (PDT) From: Laura Abbott To: "Nicholas A. Bellinger" , Bart Van Assche , Hannes Reinecke , Mike Christie , Maurizio Lombardi Cc: Laura Abbott , target-devel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCHv2] iscsi-target: Don't use stack buffer for scatterlist Date: Thu, 23 Aug 2018 13:36:26 -0700 Message-Id: <20180823203626.15108-1-labbott@redhat.com> X-Mailer: git-send-email 2.17.1 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 Fedora got a bug report of a crash with iSCSI: kernel BUG at include/linux/scatterlist.h:143! ... RIP: 0010:iscsit_do_crypto_hash_buf+0x154/0x180 [iscsi_target_mod] ... Call Trace: ? iscsi_target_tx_thread+0x200/0x200 [iscsi_target_mod] iscsit_get_rx_pdu+0x4cd/0xa90 [iscsi_target_mod] ? native_sched_clock+0x3e/0xa0 ? iscsi_target_tx_thread+0x200/0x200 [iscsi_target_mod] iscsi_target_rx_thread+0x81/0xf0 [iscsi_target_mod] kthread+0x120/0x140 ? kthread_create_worker_on_cpu+0x70/0x70 ret_from_fork+0x3a/0x50 This is a BUG_ON for using a stack buffer with a scatterlist. There are two cases that trigger this bug. Switch to using a dynamically allocated buffer for one case and do not assign a NULL buffer in another case. Signed-off-by: Laura Abbott --- v2: Change the returns to breaks to avoid leaking memory --- drivers/target/iscsi/iscsi_target.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c index 8e223799347a..086372e87cc6 100644 --- a/drivers/target/iscsi/iscsi_target.c +++ b/drivers/target/iscsi/iscsi_target.c @@ -1419,7 +1419,8 @@ static void iscsit_do_crypto_hash_buf(struct ahash_request *hash, sg_init_table(sg, ARRAY_SIZE(sg)); sg_set_buf(sg, buf, payload_length); - sg_set_buf(sg + 1, pad_bytes, padding); + if (padding) + sg_set_buf(sg + 1, pad_bytes, padding); ahash_request_set_crypt(hash, sg, data_crc, payload_length + padding); @@ -3913,10 +3914,14 @@ static bool iscsi_target_check_conn_state(struct iscsi_conn *conn) static void iscsit_get_rx_pdu(struct iscsi_conn *conn) { int ret; - u8 buffer[ISCSI_HDR_LEN], opcode; + u8 *buffer, opcode; u32 checksum = 0, digest = 0; struct kvec iov; + buffer = kmalloc_array(ISCSI_HDR_LEN, sizeof(*buffer), GFP_KERNEL); + if (!buffer) + return; + while (!kthread_should_stop()) { /* * Ensure that both TX and RX per connection kthreads @@ -3933,7 +3938,7 @@ static void iscsit_get_rx_pdu(struct iscsi_conn *conn) ret = rx_data(conn, &iov, 1, ISCSI_HDR_LEN); if (ret != ISCSI_HDR_LEN) { iscsit_rx_thread_wait_for_tcp(conn); - return; + break; } if (conn->conn_ops->HeaderDigest) { @@ -3943,7 +3948,7 @@ static void iscsit_get_rx_pdu(struct iscsi_conn *conn) ret = rx_data(conn, &iov, 1, ISCSI_CRC_LEN); if (ret != ISCSI_CRC_LEN) { iscsit_rx_thread_wait_for_tcp(conn); - return; + break; } iscsit_do_crypto_hash_buf(conn->conn_rx_hash, buffer, @@ -3967,7 +3972,7 @@ static void iscsit_get_rx_pdu(struct iscsi_conn *conn) } if (conn->conn_state == TARG_CONN_STATE_IN_LOGOUT) - return; + break; opcode = buffer[0] & ISCSI_OPCODE_MASK; @@ -3978,13 +3983,15 @@ static void iscsit_get_rx_pdu(struct iscsi_conn *conn) " while in Discovery Session, rejecting.\n", opcode); iscsit_add_reject(conn, ISCSI_REASON_PROTOCOL_ERROR, buffer); - return; + break; } ret = iscsi_target_rx_opcode(conn, buffer); if (ret < 0) - return; + break; } + + kfree(buffer); } int iscsi_target_rx_thread(void *arg)