Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2071033imm; Thu, 23 Aug 2018 13:39:22 -0700 (PDT) X-Google-Smtp-Source: AA+uWPyQSHwEWhlfEFY2y5cPNtEps2sK4oij1sw4sdzFxjG18UN9ywpsAWMWfg8QCg8mv1PQutHm X-Received: by 2002:a17:902:543:: with SMTP id 61-v6mr60493150plf.126.1535056762345; Thu, 23 Aug 2018 13:39:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535056762; cv=none; d=google.com; s=arc-20160816; b=FETel/gKC+meGLqORB1RgOxaVC5SLrH2jF2GXQl512tyLT0kXEXpCHvmC/C9M2caYA R1fH8Xqjm3fGh8/p36j31yRJB4z8pbAStoXE9ujXCXYbaR7RNcs2iQV/xxoeG9IBV7jB stfODFt+DjeP1NN/9u8qjyuNeIBFF4jESDu19iEsZtHz9UuVThSYpQVwpKdxTth++4LM NMXi7UTnhq39dYT9glPDLmJql3ZKHMOc5wt7Cn51Fgjb36zcsMJZkEvLDPeT9xAYim2q 4qOWD/hdS5iekUYeANFvv2jdJfMp16YxScE3R6hXwymvY8qsiI6kQJBy/lWxBQ8Ye17i LKkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=z84Ml9KefdO2hOQNg672IvjZmE4HtkN1KhujmMnQdzI=; b=ZlOwkdZ6jUp3qYRLfVcA4FDkFrmUg3L1Ur3ms8+upqzKdHaE09c92SJtdanX+IccMt qSGOHmW9Owjzu6HruavTYOAsOjePuhMCCUDZwwIrZGBCZLmhNe2vhAMd26XuryAwSrVV q64Kb22LV+3wJC0PJhJhzAB4VwIRJkUyrGfFIOmk3AaHtic1b9BGvEQrNAB82bNVsvQy SgRiF9etrd2uyDbTpzehlfp/0UKUs+rLY2Wr54BgFBdwOYQISWZZ1IXGnLQrRIKegF3w 4a4Yeflq2YEkAu18oTc6KX1Voo4rEydJ7QNj96AvVgaPI/QRQLYWc46Lxgf5SDyFNptz 4/Aw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c2-v6si5317339pfn.212.2018.08.23.13.39.06; Thu, 23 Aug 2018 13:39:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727372AbeHXAH7 (ORCPT + 99 others); Thu, 23 Aug 2018 20:07:59 -0400 Received: from mail-qt0-f194.google.com ([209.85.216.194]:44472 "EHLO mail-qt0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727306AbeHXAH7 (ORCPT ); Thu, 23 Aug 2018 20:07:59 -0400 Received: by mail-qt0-f194.google.com with SMTP id r13-v6so7817141qtr.11 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=sc/wW342td0TU4+uYfzCrXrBjTwyttVzzfLuvDEiaGmkUkPvHMDC0DWMZ4kwYDQ0jl RmL4Yk71rVCQqX9O6UW9Y43xc+QwKvgO4Szc5R+pWyqQtsbDEScaAbkxOuEOUlcgvLY4 HcsrXWRYKKkFvpht3bPKtc2jevwARriBWVYhe2vP5A6Myng54icyeqJlAbZkfdyh9aH+ nzjs7QciRXVh653Emebc5XgggmWczwu2v1KnzFq2b1aa/340MmZLcpc05He/2RNvB2gl BQKK7Y0/nq+Gr6bn2Mvgmx/lOzlO2wmFLgNVCxNiOyndNf/+RFWp9XwroLbjsADNrXbF SwRQ== X-Gm-Message-State: AOUpUlEkfT6jl7Fz7CBy43FAbj1ksNyaq0IfJxKu+0Je0oUC6ouHzEvQ GAp7Cq7GLg78KnWX8uBJkPqdVA== 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: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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) -- 2.17.1