From patchwork Wed Aug 22 17:37:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laura Abbott X-Patchwork-Id: 10573123 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 BFC5D1390 for ; Wed, 22 Aug 2018 17:37:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ACA7B2228E for ; Wed, 22 Aug 2018 17:37:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9EA892BA31; Wed, 22 Aug 2018 17:37:23 +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 462402228E for ; Wed, 22 Aug 2018 17:37:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727716AbeHVVDK (ORCPT ); Wed, 22 Aug 2018 17:03:10 -0400 Received: from mail-qk0-f170.google.com ([209.85.220.170]:45820 "EHLO mail-qk0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727379AbeHVVDK (ORCPT ); Wed, 22 Aug 2018 17:03:10 -0400 Received: by mail-qk0-f170.google.com with SMTP id z125-v6so1765324qkb.12 for ; Wed, 22 Aug 2018 10:37:22 -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=cXbQMuUc6OWVwxJkkUPmfwxyU+IEjt3DyikGX3T4Jr4=; b=jJjM4WRwanOWBC0sLCJm5q+Qx9RPN5/cydCdMPmuSl+Oklr4ipFD5/oB3SIBKG+wVa xbyV0HrMEbAgFQP8mgSV0AHaHyofpiXhle1YUAYnMJupEr29ZMjZm1Ay4Tto6WXAfo6W +UPQZRKDaG+U6hMBw4lByVaS2CgFgPAJeBe54Ehlvv7tVp4Ppg0UZDrtScU1mCnhp+Ea VN+KGBVifOmk/3S6bfGbG2eiFGeDAhn7Svuh+NqR9RS+gSB59P1zufH/Jtjrusaz8O4h pGzYIe+UyKYOA4TB/7rsDriMraAFpPVi5C2ttmmXlPfEave7+edQ6Y1wP1dTHqiaHGZJ rKvA== X-Gm-Message-State: APzg51Axm9UQ7bEZXK1O+i9/uO7KuYSb9SFfEXAvcOPrpIoCqPZaJKqo yWkv499yNXolZd+eemKZ6BQ2gA== X-Google-Smtp-Source: ANB0VdYc8iomS56Ei6fwM+zHKtnvfhJ2+vQZuA4mMgxKD2MzcqFgVJ3nqucf2VkEZv/0LxSrHvye4w== X-Received: by 2002:a37:aa07:: with SMTP id t7-v6mr11087502qke.38.1534959441619; Wed, 22 Aug 2018 10:37:21 -0700 (PDT) Received: from labbott-redhat.redhat.com ([2601:602:9802:a8dc::7272]) by smtp.gmail.com with ESMTPSA id t11-v6sm1441081qtb.17.2018.08.22.10.37.19 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 22 Aug 2018 10:37:20 -0700 (PDT) From: Laura Abbott To: "Nicholas A. Bellinger" , Bart Van Assche , Hannes Reinecke Cc: Laura Abbott , target-devel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] iscsi-target: Don't use stack buffer for scatterlist Date: Wed, 22 Aug 2018 10:37:09 -0700 Message-Id: <20180822173709.5886-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. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1615258 Signed-off-by: Laura Abbott --- drivers/target/iscsi/iscsi_target.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c index 8e223799347a..8b40f0e99e2c 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 @@ -3985,6 +3990,8 @@ static void iscsit_get_rx_pdu(struct iscsi_conn *conn) if (ret < 0) return; } + + kfree(buffer); } int iscsi_target_rx_thread(void *arg)