From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6FCA1C41535 for ; Fri, 22 Dec 2023 15:18:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date :Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=4HcPYkatrhoPy/DGvj2g1+rTRv/QLrDtJzmpxwO4d5Q=; b=dq7cOSAZdsTa158lU6S7vMxyjv dTGktJmnbAYhLSx+Ze8oFc0RG0DkGmdyJPxnI+BYg7BTtRWr76xgR2lMjnV07dHkwoAeL7U5+E/Ta Q/1eBgjdboyBjGKXCkFosGTz7HI1GGr6/NsZMX3QKN9M37meMXXNWKYXmbKghQoz5RIZU/41or1B3 HLGMEjCQKwdMayJT3+7NQIV2a3zEHCHfUh3DNwA1JIVmN6f6hT6sVT/okDRxGp8QYA2NN3kDshRwk AzwOhWTo3h/gTHMLqFBzDni+N1U1wxr/uThnbXkJ24DaAfNGhloGx0UohTUQEJRkvzbq4aHkccCDG wvc3+6Cw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rGhHt-006DdG-37; Fri, 22 Dec 2023 15:18:09 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rGhHp-006DaP-3B for linux-nvme@lists.infradead.org; Fri, 22 Dec 2023 15:18:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1703258285; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4HcPYkatrhoPy/DGvj2g1+rTRv/QLrDtJzmpxwO4d5Q=; b=dsD8ZrQ6EDx2SpMpPDJU9SntrgwX9JcduOHvieF/cq3qT8rJXJlgEVv25dpSPlv4ur2i5b nG0pjB5ACWMA8NCt+Mv51vO//aF9BXDQovDRRpgnPC4csQFhgKrtUODFEehmFYejjpqsb2 b+vanYauWc4JWNx5iHmPhApEMpdSSOs= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-683-KtT2EXDSOyWewhLQi9DUEw-1; Fri, 22 Dec 2023 10:17:58 -0500 X-MC-Unique: KtT2EXDSOyWewhLQi9DUEw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7BAD5101CC76; Fri, 22 Dec 2023 15:17:58 +0000 (UTC) Received: from kalibr.redhat.com (unknown [10.47.238.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 849A52166B31; Fri, 22 Dec 2023 15:17:56 +0000 (UTC) From: Maurizio Lombardi To: sagi@grimberg.me Cc: zahavi.alon@gmail.com, hch@lst.de, chaitanyak@nvidia.com, linux-nvme@lists.infradead.org, kbusch@kernel.org Subject: [PATCH V2 2/3] nvmet-tcp: fix a crash in nvmet_req_complete() Date: Fri, 22 Dec 2023 16:17:49 +0100 Message-Id: <20231222151750.655751-3-mlombard@redhat.com> In-Reply-To: <20231222151750.655751-1-mlombard@redhat.com> References: <20231222151750.655751-1-mlombard@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231222_071806_088031_BD3ECB56 X-CRM114-Status: GOOD ( 12.39 ) X-BeenThere: linux-nvme@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-nvme" Errors-To: linux-nvme-bounces+linux-nvme=archiver.kernel.org@lists.infradead.org in nvmet_tcp_handle_h2c_data_pdu(), if the host sends a data_offset different from rbytes_done, the driver ends up calling nvmet_req_complete() passing a status error. The problem is that at this point cmd->req is not yet initialized, the kernel will crash after dereferencing a NULL pointer. Fix the bug by replacing the call to nvmet_req_complete() with nvmet_tcp_fatal_error(). Fixes: 872d26a391da ("nvmet-tcp: add NVMe over TCP target driver") Reviewed-by: Keith Busch Signed-off-by: Maurizio Lombardi --- drivers/nvme/target/tcp.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/nvme/target/tcp.c b/drivers/nvme/target/tcp.c index ad16795934b8..b4b6a8ac8089 100644 --- a/drivers/nvme/target/tcp.c +++ b/drivers/nvme/target/tcp.c @@ -998,8 +998,7 @@ static int nvmet_tcp_handle_h2c_data_pdu(struct nvmet_tcp_queue *queue) data->ttag, le32_to_cpu(data->data_offset), cmd->rbytes_done); /* FIXME: use path and transport errors */ - nvmet_req_complete(&cmd->req, - NVME_SC_INVALID_FIELD | NVME_SC_DNR); + nvmet_tcp_fatal_error(queue); return -EPROTO; } -- 2.39.3