From patchwork Mon Mar 22 06:19:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Klaus Jensen X-Patchwork-Id: 1456395 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=irrelevant.dk header.i=@irrelevant.dk header.a=rsa-sha256 header.s=fm2 header.b=D/piJdB3; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm2 header.b=e3IHEmgh; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F3kw40YMHz9sVt for ; Mon, 22 Mar 2021 17:23:30 +1100 (AEDT) Received: from localhost ([::1]:59064 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lODyJ-0004Sw-1W for incoming@patchwork.ozlabs.org; Mon, 22 Mar 2021 02:23:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42488) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lODv3-00044l-Tc; Mon, 22 Mar 2021 02:20:05 -0400 Received: from wout5-smtp.messagingengine.com ([64.147.123.21]:44049) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lODuz-0007Fh-Nn; Mon, 22 Mar 2021 02:20:05 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id BFB3A11F4; Mon, 22 Mar 2021 02:19:56 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Mon, 22 Mar 2021 02:19:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=irrelevant.dk; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm2; bh=zvmOUxX3kek4y VoWEZEgSTTkeyiNBoyFAWFOrokm8r8=; b=D/piJdB3oxlQcZXKQtMy2rqS9knC8 eU0btpNyxxYKwR6uDzgnRbDh8gnyzfXvoC5QU32aRu1M9JykWWwHCDE4FNHjnQBg BmK3jloXaX1ptGEz1PusF9/uk//EdF2N9VHti4+yOjKqehBWL+NDf/F9zNDQzp+4 cUaNAJXGRAMIW8+RjJmxs1APSmw+v08yQoNf9dl8+VITPCqzZf3RGws0JAmeeZY0 8HlpTXvdmopsfmVrMlePrbwZUOV6GoRLZyHoJpd6MOQr053CxyQjRxp0tloiPIsi MQd5zu9NwFgqPd98yDYEnENNeqr33TFjqNt57Dyj+oZoaDygosKaFvgVg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=zvmOUxX3kek4yVoWEZEgSTTkeyiNBoyFAWFOrokm8r8=; b=e3IHEmgh fyR1wsovT3oc5yG+Gjzcjkn9BchBhPt5fixV2ZlK/XMYDEBD9mHTg0aWESWEqeLe bMTmOAarcNWdFyOi4vU90Uca7JkNXW8Glh9wPTx+5WfKXR/mvmzFIDfJG32XIKTO vbWJmoZLc33dBm22I0awq1NXZ+uiLSa+0eq7o+j6mT5ALUhDGTcSUxzuU40oy8cd a8Ny5qSJCF9b668uhH0KzZxErNr3l2K0WplX7Z2EXkm/gevmAF4gbIXbnLpeg5WD D11XdFKbTZz6s09Gh4r4Igmvo1LD6xW83Ifd69xOo7XHRWDSUAQoyy6tAnJA5VqS HKSseyNNGN/GdA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudegfedgleegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefmlhgruhhs ucflvghnshgvnhcuoehithhssehirhhrvghlvghvrghnthdrughkqeenucggtffrrghtth gvrhhnpeeuleetgeeiuefhgfekfefgveejiefgteekiedtgfdtieefhfdthfefueffvefg keenucfkphepkedtrdduieejrdelkedrudeltdenucevlhhushhtvghrufhiiigvpedtne curfgrrhgrmhepmhgrihhlfhhrohhmpehithhssehirhhrvghlvghvrghnthdrughk X-ME-Proxy: Received: from apples.local (80-167-98-190-cable.dk.customer.tdc.net [80.167.98.190]) by mail.messagingengine.com (Postfix) with ESMTPA id 5AEA724041D; Mon, 22 Mar 2021 02:19:55 -0400 (EDT) From: Klaus Jensen To: qemu-devel@nongnu.org Subject: [PATCH 1/2] hw/block/nvme: fix resource leak in nvme_dif_rw Date: Mon, 22 Mar 2021 07:19:50 +0100 Message-Id: <20210322061951.186748-2-its@irrelevant.dk> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210322061951.186748-1-its@irrelevant.dk> References: <20210322061951.186748-1-its@irrelevant.dk> MIME-Version: 1.0 Received-SPF: pass client-ip=64.147.123.21; envelope-from=its@irrelevant.dk; helo=wout5-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-block@nongnu.org, Klaus Jensen , Max Reitz , Keith Busch , Klaus Jensen Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Klaus Jensen If nvme_map_dptr() fails, nvme_dif_rw() will leak the bounce context. Fix this by using the same error handling as everywhere else in the function. Reported-by: Coverity (CID 1451080) Fixes: 146f720c5563 ("hw/block/nvme: end-to-end data protection") Signed-off-by: Klaus Jensen --- hw/block/nvme-dif.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/block/nvme-dif.c b/hw/block/nvme-dif.c index 2038d724bda5..e6f04faafb5f 100644 --- a/hw/block/nvme-dif.c +++ b/hw/block/nvme-dif.c @@ -432,7 +432,7 @@ uint16_t nvme_dif_rw(NvmeCtrl *n, NvmeRequest *req) status = nvme_map_dptr(n, &req->sg, mapped_len, &req->cmd); if (status) { - return status; + goto err; } ctx->data.bounce = g_malloc(len); From patchwork Mon Mar 22 06:19:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Klaus Jensen X-Patchwork-Id: 1456396 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=irrelevant.dk header.i=@irrelevant.dk header.a=rsa-sha256 header.s=fm2 header.b=Xnf2Nlt7; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm2 header.b=IIY68NCL; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F3kwK6y22z9sSC for ; Mon, 22 Mar 2021 17:23:45 +1100 (AEDT) Received: from localhost ([::1]:59516 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lODyZ-0004il-RT for incoming@patchwork.ozlabs.org; Mon, 22 Mar 2021 02:23:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42462) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lODv1-00042e-K4; Mon, 22 Mar 2021 02:20:03 -0400 Received: from wout5-smtp.messagingengine.com ([64.147.123.21]:57435) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lODuz-0007Gu-AE; Mon, 22 Mar 2021 02:20:03 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id E12DE12BA; Mon, 22 Mar 2021 02:19:57 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Mon, 22 Mar 2021 02:19:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=irrelevant.dk; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm2; bh=ZypO/r3ZlL80/ jeomDE8lGw5+jhPTLfOsFJbqgJ4nJ8=; b=Xnf2Nlt7XU1FkTjzTLKyjz8Y/4P/M RlXiw05M2B9z2MKu1JNJm/VlluxVeoQnQ444f23o/k8KXpMvb2Vh7QZE1TKzGoDp QRSUe+hWmLsTDJwDD4hmCTj1a9ycp87rLP4sf8tdN7YyzNr9GPEqUmMujIcVJxpm lO0ekj9RklL8m55POUPGGJ8OvITaAPFx/CleMQFZ4c1t6fgRbHlQ9l6GPr4qF7UM q4hFqsA7S3doaaV57vgZGE6H6fjukhTD1Ircyv4TLJUepqqPZYiR4lwhJanYKEni CfAZkj4XFq4jy7OK/nlrxbLjqX6hfmzkKAVllnSSlJU+DzcT92zTNJemQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=ZypO/r3ZlL80/jeomDE8lGw5+jhPTLfOsFJbqgJ4nJ8=; b=IIY68NCL H8jGRYYSrzaB6eUr71WQCaodHRVcXCcM9VBSbc0vml9nlSgQkuDSrgBtVDsQQYsF aBCPSoadpGwNbmfnfUMeeUltyVllVo2brSnkYvW3/HdiekhjMOlubHYYA13FFt6P iEgWMm6uPBDj1wPwXcnaz/zBmbBtOKCj63w6LFhrdXTpyJBd9qsBvyayZhqGahmi 4yKJXgY/gO834PGOxi9aaIdO9fieQ9SQNi88lOCyWUVmEUGzE3/YRaJBYnQCb3JQ 05IQhldwiA9KTwFwkEzu3KBpGHp6JaTTW99d75vY4R5F4p0Rw3trIkfQ6UlShUxp jCYqcL6NVSKIog== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudegfedgleegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefmlhgruhhs ucflvghnshgvnhcuoehithhssehirhhrvghlvghvrghnthdrughkqeenucggtffrrghtth gvrhhnpeeuleetgeeiuefhgfekfefgveejiefgteekiedtgfdtieefhfdthfefueffvefg keenucfkphepkedtrdduieejrdelkedrudeltdenucevlhhushhtvghrufhiiigvpedtne curfgrrhgrmhepmhgrihhlfhhrohhmpehithhssehirhhrvghlvghvrghnthdrughk X-ME-Proxy: Received: from apples.local (80-167-98-190-cable.dk.customer.tdc.net [80.167.98.190]) by mail.messagingengine.com (Postfix) with ESMTPA id 7D8E824033F; Mon, 22 Mar 2021 02:19:56 -0400 (EDT) From: Klaus Jensen To: qemu-devel@nongnu.org Subject: [PATCH 2/2] hw/block/nvme: fix resource leak in nvme_format_ns Date: Mon, 22 Mar 2021 07:19:51 +0100 Message-Id: <20210322061951.186748-3-its@irrelevant.dk> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210322061951.186748-1-its@irrelevant.dk> References: <20210322061951.186748-1-its@irrelevant.dk> MIME-Version: 1.0 Received-SPF: pass client-ip=64.147.123.21; envelope-from=its@irrelevant.dk; helo=wout5-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-block@nongnu.org, Klaus Jensen , Max Reitz , Keith Busch , Klaus Jensen Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Klaus Jensen In nvme_format_ns(), if the namespace is of zero size (which might be useless, but not invalid), the `count` variable will leak. Fix this by returning early in that case. Reported-by: Coverity (CID 1451082) Fixes: dc04d25e2f3f ("hw/block/nvme: add support for the format nvm command") Signed-off-by: Klaus Jensen --- hw/block/nvme.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/block/nvme.c b/hw/block/nvme.c index 6842b01ab58b..dad275971a84 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -4984,6 +4984,11 @@ static uint16_t nvme_format_ns(NvmeCtrl *n, NvmeNamespace *ns, uint8_t lbaf, ns->status = NVME_FORMAT_IN_PROGRESS; len = ns->size; + + if (!len) { + return NVME_SUCCESS; + } + offset = 0; count = g_new(int, 1);