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 D062BC52D6F for ; Wed, 21 Aug 2024 12:40:42 +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: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:In-Reply-To:References:List-Owner; bh=4zZWe0SzbsXRz5m1EAdtZZ3vL2KvWOROiSwnfLUhtjI=; b=tFRXD69Iroz7zs5n5RQ1KseVCF kDQcz8gvheacwoEB6DdDW1swtuaN10GsiIrME3VIima1SdM+g0PxD+Ue9/fZg1wX/2KWy2wu7NzOI YpBPvpnrphGFnXPIxkSp5jBQ1z9I/Zvnslmq13buXdquWRIRNWaaYBDi2GS5Mc6iw47clnsbbEJGN IJr1BCKEsNGzHcLl/3yKckyeaoTB8tRrCyseOLLE3gDOJIXr4pXlSxRsVlBmBgKL0HTreCd0r98w9 rx4eNrv3k9dZwSoK2az5icu/wZ5aAUT2V1xQRu76gX7JYM+e5rjfNlUgo/LfRWl5Gv24MNlFrHZKQ V0y1b1oA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgkdk-00000008xD9-3o5h; Wed, 21 Aug 2024 12:40:40 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgkdi-00000008xCh-1UU4 for linux-nvme@lists.infradead.org; Wed, 21 Aug 2024 12:40:39 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724244036; 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; bh=4zZWe0SzbsXRz5m1EAdtZZ3vL2KvWOROiSwnfLUhtjI=; b=CAvrMrR5k3p/zf0YkhugpDHP4Z+73r+Z26qaPCEay1loEN7C8bWCugCV1NPKtNeaTi5KPU jcQZ3OvFDrLpV1eO9wCnc7zf36EE5y6kSbyPqrNCs4AIRfoHhNVUihtUJC9yP7MsuzasWv dFpfiIl/8W8fRRL+GXwPRIgP5EdSFaw= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-427-b7GzVh6qOD69rY7PRzAorw-1; Wed, 21 Aug 2024 08:40:32 -0400 X-MC-Unique: b7GzVh6qOD69rY7PRzAorw-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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 mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E0CD31955D48; Wed, 21 Aug 2024 12:40:30 +0000 (UTC) Received: from kinzhal.redhat.com (unknown [10.45.224.134]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3857319560AA; Wed, 21 Aug 2024 12:40:27 +0000 (UTC) From: Maurizio Lombardi To: sagi@grimberg.me Cc: hch@lst.de, kch@nvidia.com, linux-nvme@lists.infradead.org, me@yawk.at Subject: [PATCH] nvmet-tcp: fix kernel crash if commands allocation fails Date: Wed, 21 Aug 2024 14:40:26 +0200 Message-ID: <20240821124026.62999-1-mlombard@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 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-20240821_054038_485467_018D3E2C X-CRM114-Status: GOOD ( 12.59 ) 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 If the commands allocation fails in nvmet_tcp_alloc_cmds() the kernel crashes in nvmet_tcp_release_queue_work() because of a NULL pointer dereference. nvmet: failed to install queue 0 cntlid 1 ret 6 Unable to handle kernel NULL pointer dereference at virtual address 0000000000000008 Fix the bug by setting queue->nr_cmds to zero in case nvmet_tcp_alloc_cmd() fails. Signed-off-by: Maurizio Lombardi --- drivers/nvme/target/tcp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/target/tcp.c b/drivers/nvme/target/tcp.c index 5bff0d5464d1..7c51c2a8c109 100644 --- a/drivers/nvme/target/tcp.c +++ b/drivers/nvme/target/tcp.c @@ -2146,8 +2146,10 @@ static u16 nvmet_tcp_install_queue(struct nvmet_sq *sq) } queue->nr_cmds = sq->size * 2; - if (nvmet_tcp_alloc_cmds(queue)) + if (nvmet_tcp_alloc_cmds(queue)) { + queue->nr_cmds = 0; return NVME_SC_INTERNAL; + } return 0; } -- 2.43.5