From patchwork Wed Apr 12 10:04:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Klaus Jensen X-Patchwork-Id: 1768014 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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: legolas.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=IHSJQJki; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=Er08nV03; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PxJHL6r9sz1yZk for ; Wed, 12 Apr 2023 20:05:18 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pmXLO-0004ZF-D9; Wed, 12 Apr 2023 06:04:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pmXLL-0004YM-B9; Wed, 12 Apr 2023 06:04:48 -0400 Received: from wout5-smtp.messagingengine.com ([64.147.123.21]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pmXLI-0005NL-TO; Wed, 12 Apr 2023 06:04:46 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 8ADCF32009AC; Wed, 12 Apr 2023 06:04:42 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Wed, 12 Apr 2023 06:04:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=irrelevant.dk; h=cc:cc:content-transfer-encoding:content-type:content-type :date:date:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to; s=fm2; t=1681293882; x=1681380282; bh=8Xs7tGZxZvvGjOXL4t2xmMTu6 AtYhtCimAMX5scOnIY=; b=IHSJQJki+ImOsbMHl5AR24uGeQlbf+q9GLHUCp8dT Ug6n8+lSD4xPDkJq+dcqBUUgkJhr4anP9jm2C+5LjDQh5uY2PPFDgXFNnibJ/EN5 A7b6G5LSe81tjkSx0Q2mBMPy+kzanqIj3PLavBKP+dNV/U/kJXKzx8EZkqqioG3c dgicy8JG9O2wxZoWpR1PPlvUdF4Bgdn/jbSFM10edd+RmhXA8h58cniASFlInACM SmVjhGQkmogolEGM9w4D/eIbpNrydFhCjrtUgPfFRAb2S2e+a5YpLp9wByTQhy5a IpHgiUSf8YjmAp9dTNFRFgypdO1KompdWQQBbp/fyLzVg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1681293882; x=1681380282; bh=8Xs7tGZxZvvGjOXL4t2xmMTu6AtYhtCimAM X5scOnIY=; b=Er08nV03MfFeZzTUGq03iBCkr0rWdvEjhieWZIIY3Cg1nzZgPEn eCklmO7fuYW/N735AQCfjVD3i4znIvfI7w6mitaXJvVGGkh4X1HSQIeHiJ6lq4s9 eQtqvZDJZgz593DBMpO72/XidJkY2iL5Gu8QhBLAI4nQrTP+FmVUhmltuH6CO7FF k5t3Tyn99jGyMrf9EKrVBMic9kr0sWgREtr9mQTSw0knl/aRMeGk3QBL95tI6alG LqEuyEkyBSNT02XTwJu0SJquYIQH0iKcEMT4wtVYLBC1ff+7X+wAyJY4EhJjnYtb hn1v6PyPDVUyvRBOxNEuWAYkwaSXvWFoIBg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdekiedgvdehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhggtgfgsehtkeertdertdejnecuhfhrohhmpefmlhgr uhhsucflvghnshgvnhcuoehithhssehirhhrvghlvghvrghnthdrughkqeenucggtffrrg htthgvrhhnpeefvedtueetueduffevgffgtdeftdeuleffhfeigeffkeegfeejfeffteej iefhvdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe hithhssehirhhrvghlvghvrghnthdrughk X-ME-Proxy: Feedback-ID: idc91472f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 12 Apr 2023 06:04:40 -0400 (EDT) From: Klaus Jensen To: qemu-devel@nongnu.org, Peter Maydell Cc: Keith Busch , Klaus Jensen , qemu-block@nongnu.org, Klaus Jensen , =?utf-8?q?Phili?= =?utf-8?q?ppe_Mathieu-Daud=C3=A9?= Subject: [PULL for-8.0 1/2] hw/nvme: fix memory leak in fdp ruhid parsing Date: Wed, 12 Apr 2023 12:04:35 +0200 Message-Id: <20230412100436.94038-2-its@irrelevant.dk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230412100436.94038-1-its@irrelevant.dk> References: <20230412100436.94038-1-its@irrelevant.dk> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1028; i=k.jensen@samsung.com; h=from:subject; bh=ujQBMyZ2b2XAHG5JvO+/X6wlJts9d9Ei/9hgl1BWxLI=; b=owJ4nJvAy8zAxej7cL1hrj/vS8bTakkMKWZNJuyRy28Wv5mlnn+9VaXz6Ln5AedOZxwXVi+0v ureM3dWcW4nozELAyMXg6yYIkuQhvGq0kd3ni1yTzsAM4iVCWQKAxenAEzk038OhvYdOVO1qkO6 3iVUlc5/1VqdWdnse9gm1+rO84/11yKKItsqzvxMzj/XwiNlXLzze0hP5PGWB0tqZPY5L/LT4uw rzrrh6nbdqS7nUtpyZbnb8d8nu3fyXXiRdsE34cLC65zK3vprNT+yHrlqo9GuyhDq3lz25wZfwg RNfea11jP6367V2ZIXtptvF9eqZU+jRQ8bmStFbf/9ucHvnsedb5YiIj/OcyssNzpR2v+x/5Kim 1vSL6a7C5tfsF8s/6isIBNpdvC1yeXbRpe4VQ2Ufc69+hgXeM+QJfORwZGW+Z+e5gmx2hqtmMw1 0dB0svIE3buPgjT3ZWzWyKtzdTouUBHwUmCii/8eNcaL5vEAOCCj7g== X-Developer-Key: i=k.jensen@samsung.com; a=openpgp; fpr=DDCA4D9C9EF931CC3468427263D56FC5E55DA838 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Klaus Jensen Coverity reports a memory leak of memory when parsing ruhids at namespace initialization. Since this is just working memory, not needed beyond the scope of the functions, fix this by adding a g_autofree annotation. Reported-by: Coverity (CID 1507979) Fixes: 73064edfb864 ("hw/nvme: flexible data placement emulation") Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Klaus Jensen --- hw/nvme/ns.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/nvme/ns.c b/hw/nvme/ns.c index cfac960dcf39..547c0b154312 100644 --- a/hw/nvme/ns.c +++ b/hw/nvme/ns.c @@ -399,7 +399,8 @@ static bool nvme_ns_init_fdp(NvmeNamespace *ns, Error **errp) NvmeEnduranceGroup *endgrp = ns->endgrp; NvmeRuHandle *ruh; uint8_t lbafi = NVME_ID_NS_FLBAS_INDEX(ns->id_ns.flbas); - unsigned int *ruhid, *ruhids; + g_autofree unsigned int *ruhids = NULL; + unsigned int *ruhid; char *r, *p, *token; uint16_t *ph; From patchwork Wed Apr 12 10:04:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Klaus Jensen X-Patchwork-Id: 1768015 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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: legolas.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=pStjvbZm; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=gy+HKHmF; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PxJHh63szz1yZk for ; Wed, 12 Apr 2023 20:05:35 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pmXLP-0004Zn-5H; Wed, 12 Apr 2023 06:04:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pmXLN-0004Ys-4N; Wed, 12 Apr 2023 06:04:49 -0400 Received: from wout5-smtp.messagingengine.com ([64.147.123.21]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pmXLL-0005O0-F3; Wed, 12 Apr 2023 06:04:48 -0400 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 6169D320099C; Wed, 12 Apr 2023 06:04:45 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Wed, 12 Apr 2023 06:04:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=irrelevant.dk; h=cc:cc:content-transfer-encoding:content-type:content-type :date:date:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to; s=fm2; t=1681293885; x=1681380285; bh=tphiNIweYkcl0zw7aRQKO+uVS BQX157Xly3CeKDLTkI=; b=pStjvbZm8bN6oSHk1w0xcnjJZce7pfcJNQe4MlbPm JuqMn/ZBrfvuBtwcHeZtdQXssvViUUC0Hr2DeHhc9uZdrGBBujd0uRVL63I3fIfV qaGS69VVOKkHjIzOftTdXIWv2IAQRWPxFujv8zkLvKjlqfuPovZxKvEG95iuxg+d TGgEhcgt1+ryohHI7l/fNhIvj8yyLt1B2wvnYb4T5PYTZ0S9vFogi9Y06j1ESU3m ZZ8kyMcFmMjW0LQm1u2Xux6H5vBZh3ZoQvLiFtK6KMAalO619Z0B8D8nmUZz96No k0n6E4mTnVT8jjHkFBmxo4cXUcp+5yX1wRYw3vxYfDdfg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1681293885; x=1681380285; bh=tphiNIweYkcl0zw7aRQKO+uVSBQX157Xly3 CeKDLTkI=; b=gy+HKHmF+Bq2vU5895eO0m109Gjnb6cGAYtXY7QIMVIzxZBXRUY WHMATxTFOFrFN3ZeuGZzpzELXRIVodrqoaJWRmY7qXbK8JQPjODaB6WuSQA7LiBL Kc0vd2wdqm993dRbvy/R5lGUBBOtjlUuCasZh7llG3qRooV3TxRx5lSVBHuAIpo0 IMZodKdzBL/iC/zdWL76T0RCbXQ/72EJVTVVrm/MJ+HWsXoq+nRnjmH3Joilx5hg Vx5Zg7bN+1xNKytEdtmAJwVcDK7bwN0srWawBh7MyV9wB6/VZ5SxX9ElLtnjP9Cr BWmv1SFfMfsOO9mceeRv39vMvW7Nuumw5lw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdekiedgvdehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhggtgfgsehtkeertdertdejnecuhfhrohhmpefmlhgr uhhsucflvghnshgvnhcuoehithhssehirhhrvghlvghvrghnthdrughkqeenucggtffrrg htthgvrhhnpeefvedtueetueduffevgffgtdeftdeuleffhfeigeffkeegfeejfeffteej iefhvdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe hithhssehirhhrvghlvghvrghnthdrughk X-ME-Proxy: Feedback-ID: idc91472f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 12 Apr 2023 06:04:43 -0400 (EDT) From: Klaus Jensen To: qemu-devel@nongnu.org, Peter Maydell Cc: Keith Busch , Klaus Jensen , qemu-block@nongnu.org, Klaus Jensen , =?utf-8?q?Phili?= =?utf-8?q?ppe_Mathieu-Daud=C3=A9?= Subject: [PULL for-8.0 2/2] hw/nvme: fix memory leak in nvme_dsm Date: Wed, 12 Apr 2023 12:04:36 +0200 Message-Id: <20230412100436.94038-3-its@irrelevant.dk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230412100436.94038-1-its@irrelevant.dk> References: <20230412100436.94038-1-its@irrelevant.dk> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=919; i=k.jensen@samsung.com; h=from:subject; bh=dg013DH4rtfyR99vmVe1/pFSn0W94O6mRsVtwz4hrB4=; b=owJ4nAFtAZL+kA0DAAoBTeGvMW1PDekByyZiAGQ2gjRS/N3diqeTkCG2NeIwS+F48zNIrUeRN MVs2QT1JDv6bIkBMwQAAQoAHRYhBFIoM6p14tzmokdmwE3hrzFtTw3pBQJkNoI0AAoJEE3hrzFt Tw3pKbIH/29GRL5qd3bhOWQs8M5d9bUm42T7pGl7rICO07oATZ1qu08PJKWryvhiWikhV/4keTh dZQ8v390BKbhBMyOifUlt85avAVXsivXFRxMkYQM6RuubW7B7x0GdESfjqfDuvvpY7co9sVuTy8 mQ6Unohb9RlRi7r8LDVW5KxPJr8MmyJkI9i2LG4wy+MutGx33rMXc53lJ2vd56CZ5Q3CAJZHgN8 7n8B4R2mtElpgNBF/hqOP5Y9zo9IsEecem6MaKTIvYVvh8j/qhhi/lBtM25F0GI2Myqa84APFI1 aQJ0gCY7fMXV7E5ZFrCT0VHb+7F5cla/UteDZR7eiCW/nKhmeTPGK6wM X-Developer-Key: i=k.jensen@samsung.com; a=openpgp; fpr=DDCA4D9C9EF931CC3468427263D56FC5E55DA838 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Klaus Jensen The iocb (and the allocated memory to hold LBA ranges) leaks if reading the LBA ranges fails. Fix this by adding a free and an unref of the iocb. Reported-by: Coverity (CID 1508281) Fixes: d7d1474fd85d ("hw/nvme: reimplement dsm to allow cancellation") Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Klaus Jensen --- hw/nvme/ctrl.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index 8b7be1420912..ac24eeb5ed5a 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -2619,6 +2619,9 @@ static uint16_t nvme_dsm(NvmeCtrl *n, NvmeRequest *req) status = nvme_h2c(n, (uint8_t *)iocb->range, sizeof(NvmeDsmRange) * nr, req); if (status) { + g_free(iocb->range); + qemu_aio_unref(iocb); + return status; }