From nobody Mon Apr 29 16:16:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1563460933; cv=none; d=zoho.com; s=zohoarc; b=cwhZM4Z00qtxIYM6HTHbHPp8Oi78L+3G79W+HwyDqc0ptD6yB1rzKZSv848aYZbdVU8HHoqkpoejFAEF8UmG2dHWOt7Vi6CHfZRJPFf4b5zSoJcmMCEZGevYDWa7d3s+kAgTa8T2LYTzRg4fGNs87GhjvuS5pQYqN5xzcEZ8QSs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563460933; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=ZQDVJ6xaaSwrPuNv8NdYIXfW61pdKwITfYwM0p26JlY=; b=UYwF/jmtOQGV7hy9Eq45KMwHiBykGghH2JzC1onVqw8ehQsnX+HWIPPHC17gt1ycsDKXy3wYsyCI/x+jyVxJBV5k2xnW/GvXF37AI07PilUwi7jE52Aufc6LdC6XXroKULK5k4oBxoy7vUCAqJ650qDolgq4VJJXMm4qqvAI/gE= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 156346093346372.52590780069227; Thu, 18 Jul 2019 07:42:13 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 19EC081F33; Thu, 18 Jul 2019 14:42:11 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B7BF71001947; Thu, 18 Jul 2019 14:42:09 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id DAC7A1800206; Thu, 18 Jul 2019 14:42:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x6IEg7ti015686 for ; Thu, 18 Jul 2019 10:42:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3BC8460A35; Thu, 18 Jul 2019 14:42:07 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id BA74460635 for ; Thu, 18 Jul 2019 14:42:06 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 18 Jul 2019 16:42:01 +0200 Message-Id: <83ad6662f61e069e407294dc82c92f5e07429d3f.1563460852.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/2] util: storage: Clean up label use in virStorageFileGetMetadataInternal X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 18 Jul 2019 14:42:11 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The function does not do any cleanup, so replace the 'cleanup' label with return of -1 and the 'done' label with return of 0. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko Reviewed-by: Michal Privoznik --- src/util/virstoragefile.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 269d0050fd..4e2e7540f1 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -973,7 +973,6 @@ virStorageFileGetMetadataInternal(virStorageSourcePtr m= eta, int *backingFormat) { int dummy; - int ret =3D -1; size_t i; if (!backingFormat) @@ -989,7 +988,7 @@ virStorageFileGetMetadataInternal(virStorageSourcePtr m= eta, meta->format >=3D VIR_STORAGE_FILE_LAST) { virReportSystemError(EINVAL, _("unknown storage file meta->format = %d"), meta->format); - goto cleanup; + return -1; } if (fileTypeInfo[meta->format].cryptInfo !=3D NULL) { @@ -999,7 +998,7 @@ virStorageFileGetMetadataInternal(virStorageSourcePtr m= eta, int expt_fmt =3D fileTypeInfo[meta->format].cryptInfo[i].f= ormat; if (!meta->encryption) { if (VIR_ALLOC(meta->encryption) < 0) - goto cleanup; + return -1; meta->encryption->format =3D expt_fmt; } else { @@ -1008,7 +1007,7 @@ virStorageFileGetMetadataInternal(virStorageSourcePtr= meta, _("encryption format %d doesn't mat= ch " "expected format %d"), meta->encryption->format, expt_fmt); - goto cleanup; + return -1; } } meta->encryption->payload_offset =3D @@ -1021,12 +1020,12 @@ virStorageFileGetMetadataInternal(virStorageSourceP= tr meta, * code into this method, for non-magic files */ if (!fileTypeInfo[meta->format].magic) - goto done; + return 0; /* Optionally extract capacity from file */ if (fileTypeInfo[meta->format].sizeOffset !=3D -1) { if ((fileTypeInfo[meta->format].sizeOffset + 8) > len) - goto done; + return 0; if (fileTypeInfo[meta->format].endian =3D=3D LV_LITTLE_ENDIAN) meta->capacity =3D virReadBufInt64LE(buf + @@ -1037,7 +1036,7 @@ virStorageFileGetMetadataInternal(virStorageSourcePtr= meta, /* Avoid unlikely, but theoretically possible overflow */ if (meta->capacity > (ULLONG_MAX / fileTypeInfo[meta->format].sizeMultiplier)) - goto done; + return 0; meta->capacity *=3D fileTypeInfo[meta->format].sizeMultiplier; } @@ -1047,25 +1046,21 @@ virStorageFileGetMetadataInternal(virStorageSourceP= tr meta, backingForm= at, buf, len); if (store =3D=3D BACKING_STORE_INVALID) - goto done; + return 0; if (store =3D=3D BACKING_STORE_ERROR) - goto cleanup; + return -1; } if (fileTypeInfo[meta->format].getFeatures !=3D NULL && fileTypeInfo[meta->format].getFeatures(&meta->features, meta->form= at, buf, len) < 0) - goto cleanup; + return -1; if (meta->format =3D=3D VIR_STORAGE_FILE_QCOW2 && meta->features && VIR_STRDUP(meta->compat, "1.1") < 0) - goto cleanup; - - done: - ret =3D 0; + return -1; - cleanup: - return ret; + return 0; } --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 16:16:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1563460933; cv=none; d=zoho.com; s=zohoarc; b=hJ1o5Sz6s1VgBmMxUJrEw5MExH3Q3rHILCT56OmJjGBNJU/jwux/iN14x2FccTOQ1cqQkUigJi1el6W4gyqH/fVqLBYFxRLKdnwTsJcqRu+oOmugeSiAZKsy54whu5F5dYWjhqovokRypFbYL4KVdektb6sfBMLYEbeZCKmaTj0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563460933; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=GYgW7rqWGlYsCuQIKKyUGoaSUjxo4jiP2vbtXLjSVVM=; b=hEX/il57ufZuEYbIwXR1tdk4DonLeUnIxEKLmw+GTvINfbS/fGM5Un7CoW/TyXAwxdj5ZVqXOUBqK2ZN5JVkaL2OEml8N6c1AU58i2MVtAffJixTaQNpzSep4HI5rH67ff/lkfA78b5LLk19iOAAtTEO0jfGDmwbIa3tZCgf0u0= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1563460933731738.5167363113385; Thu, 18 Jul 2019 07:42:13 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7F07488307; Thu, 18 Jul 2019 14:42:11 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4EAF85E7D1; Thu, 18 Jul 2019 14:42:11 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 0175E1972E; Thu, 18 Jul 2019 14:42:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x6IEg8GS015696 for ; Thu, 18 Jul 2019 10:42:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0F24160BF4; Thu, 18 Jul 2019 14:42:08 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8884C60635 for ; Thu, 18 Jul 2019 14:42:07 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 18 Jul 2019 16:42:02 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/2] util: storage: Don't leak metadata on repeated calls of virStorageFileGetMetadata X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 18 Jul 2019 14:42:12 +0000 (UTC) Content-Type: text/plain; charset="utf-8" When querying storage metadata after a block job we re-run virStorageFileGetMetadata on the top level storage file. This means that the workers (virStorageFileGetMetadataInternal) must not overwrite any pointers without freeing them. This was not considered for src->compat and src->features. Fix it and add a comment mentioning that. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko Reviewed-by: Michal Privoznik --- src/util/virstoragefile.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 4e2e7540f1..a6de6a1e45 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -965,7 +965,11 @@ virStorageFileGetEncryptionPayloadOffset(const struct = FileEncryptionInfo *info, * assuming it has the given FORMAT, populate information into META * with information about the file and its backing store. Return format * of the backing store as BACKING_FORMAT. PATH and FORMAT have to be - * pre-populated in META */ + * pre-populated in META. + * + * Note that this function may be called repeatedly on @meta, so it must + * clean up any existing allocated memory which would be overwritten. + */ int virStorageFileGetMetadataInternal(virStorageSourcePtr meta, char *buf, @@ -1052,10 +1056,13 @@ virStorageFileGetMetadataInternal(virStorageSourceP= tr meta, return -1; } + virBitmapFree(meta->features); + meta->features =3D NULL; if (fileTypeInfo[meta->format].getFeatures !=3D NULL && fileTypeInfo[meta->format].getFeatures(&meta->features, meta->form= at, buf, len) < 0) return -1; + VIR_FREE(meta->compat); if (meta->format =3D=3D VIR_STORAGE_FILE_QCOW2 && meta->features && VIR_STRDUP(meta->compat, "1.1") < 0) return -1; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list