Changeset
tests/qemuxml2argvtest.c | 2 ++
1 file changed, 2 insertions(+)
Git apply log
Switched to a new branch 'eb37d2944dc6bda1314090b1813c6e6a20d6bfcd.1528898300.git.mprivozn@redhat.com'
Applying: qemuxml2argvtest: Don't leak TPM unix path
To https://github.com/patchew-project/libvirt
 + f9f66a6...7cf8eae patchew/eb37d2944dc6bda1314090b1813c6e6a20d6bfcd.1528898300.git.mprivozn@redhat.com -> patchew/eb37d2944dc6bda1314090b1813c6e6a20d6bfcd.1528898300.git.mprivozn@redhat.com (forced update)
Test passed: syntax-check

loading

[libvirt] [PATCH] qemuxml2argvtest: Don't leak TPM unix path
Posted by Michal Privoznik, 1 week ago
When testing a domain XML with TPM we overwrite UNIX socket path
to mimic what qemuTPMEmulatorPrepareHost() is doing (because
*PrepareHost() functions are not called from the test). But we
are not doing it fully - we need to set the chardev's type too so
that virDomainTPMDefFree() can free the path.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 tests/qemuxml2argvtest.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index f630185de1..daa8d4ceeb 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -551,9 +551,11 @@ testCompareXMLToArgv(const void *data)
     if (vm->def->tpm) {
         switch (vm->def->tpm->type) {
         case VIR_DOMAIN_TPM_TYPE_EMULATOR:
+            VIR_FREE(vm->def->tpm->data.emulator.source.data.file.path);
             if (VIR_STRDUP(vm->def->tpm->data.emulator.source.data.file.path,
                            "/dev/test") < 0)
                 goto cleanup;
+            vm->def->tpm->data.emulator.source.type = VIR_DOMAIN_CHR_TYPE_UNIX;
             break;
         case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
         case VIR_DOMAIN_TPM_TYPE_LAST:
-- 
2.16.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] qemuxml2argvtest: Don't leak TPM unix path
Posted by Andrea Bolognani, 1 week ago
On Wed, 2018-06-13 at 15:58 +0200, Michal Privoznik wrote:
> When testing a domain XML with TPM we overwrite UNIX socket path
> to mimic what qemuTPMEmulatorPrepareHost() is doing (because
> *PrepareHost() functions are not called from the test). But we
> are not doing it fully - we need to set the chardev's type too so
> that virDomainTPMDefFree() can free the path.
> 
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>  tests/qemuxml2argvtest.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
> index f630185de1..daa8d4ceeb 100644
> --- a/tests/qemuxml2argvtest.c
> +++ b/tests/qemuxml2argvtest.c
> @@ -551,9 +551,11 @@ testCompareXMLToArgv(const void *data)
>      if (vm->def->tpm) {
>          switch (vm->def->tpm->type) {
>          case VIR_DOMAIN_TPM_TYPE_EMULATOR:
> +            VIR_FREE(vm->def->tpm->data.emulator.source.data.file.path);
>              if (VIR_STRDUP(vm->def->tpm->data.emulator.source.data.file.path,
>                             "/dev/test") < 0)
>                  goto cleanup;
> +            vm->def->tpm->data.emulator.source.type = VIR_DOMAIN_CHR_TYPE_UNIX;

Looking at virDomainChrSourceDefClear(), called by
virDomainTPMDefFree(), when type is CHR_TYPE_UNIX data.nix.path
will be VIR_FREE()d, so I think you want to set type to
CHR_TYPE_FILE instead.

-- 
Andrea Bolognani / Red Hat / Virtualization

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] qemuxml2argvtest: Don't leak TPM unix path
Posted by Michal Privoznik, 1 week ago
On 06/14/2018 10:39 AM, Andrea Bolognani wrote:
> On Wed, 2018-06-13 at 15:58 +0200, Michal Privoznik wrote:
>> When testing a domain XML with TPM we overwrite UNIX socket path
>> to mimic what qemuTPMEmulatorPrepareHost() is doing (because
>> *PrepareHost() functions are not called from the test). But we
>> are not doing it fully - we need to set the chardev's type too so
>> that virDomainTPMDefFree() can free the path.
>>
>> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
>> ---
>>  tests/qemuxml2argvtest.c | 2 ++
>>  1 file changed, 2 insertions(+)
>>
>> diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
>> index f630185de1..daa8d4ceeb 100644
>> --- a/tests/qemuxml2argvtest.c
>> +++ b/tests/qemuxml2argvtest.c
>> @@ -551,9 +551,11 @@ testCompareXMLToArgv(const void *data)
>>      if (vm->def->tpm) {
>>          switch (vm->def->tpm->type) {
>>          case VIR_DOMAIN_TPM_TYPE_EMULATOR:
>> +            VIR_FREE(vm->def->tpm->data.emulator.source.data.file.path);
>>              if (VIR_STRDUP(vm->def->tpm->data.emulator.source.data.file.path,
>>                             "/dev/test") < 0)
>>                  goto cleanup;
>> +            vm->def->tpm->data.emulator.source.type = VIR_DOMAIN_CHR_TYPE_UNIX;
> 
> Looking at virDomainChrSourceDefClear(), called by
> virDomainTPMDefFree(), when type is CHR_TYPE_UNIX data.nix.path
> will be VIR_FREE()d, so I think you want to set type to
> CHR_TYPE_FILE instead.
> 

Ah, good point. Do you trust me enough that I can fix this before
pushing or do you want to see v2? ;-)

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] qemuxml2argvtest: Don't leak TPM unix path
Posted by Andrea Bolognani, 1 week ago
On Thu, 2018-06-14 at 11:09 +0200, Michal Privoznik wrote:
> On 06/14/2018 10:39 AM, Andrea Bolognani wrote:
> > On Wed, 2018-06-13 at 15:58 +0200, Michal Privoznik wrote:
> > > When testing a domain XML with TPM we overwrite UNIX socket path
> > > to mimic what qemuTPMEmulatorPrepareHost() is doing (because
> > > *PrepareHost() functions are not called from the test). But we
> > > are not doing it fully - we need to set the chardev's type too so
> > > that virDomainTPMDefFree() can free the path.
> > > 
> > > Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> > > ---
> > >  tests/qemuxml2argvtest.c | 2 ++
> > >  1 file changed, 2 insertions(+)
> > > 
> > > diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
> > > index f630185de1..daa8d4ceeb 100644
> > > --- a/tests/qemuxml2argvtest.c
> > > +++ b/tests/qemuxml2argvtest.c
> > > @@ -551,9 +551,11 @@ testCompareXMLToArgv(const void *data)
> > >      if (vm->def->tpm) {
> > >          switch (vm->def->tpm->type) {
> > >          case VIR_DOMAIN_TPM_TYPE_EMULATOR:
> > > +            VIR_FREE(vm->def->tpm->data.emulator.source.data.file.path);
> > >              if (VIR_STRDUP(vm->def->tpm->data.emulator.source.data.file.path,
> > >                             "/dev/test") < 0)
> > >                  goto cleanup;
> > > +            vm->def->tpm->data.emulator.source.type = VIR_DOMAIN_CHR_TYPE_UNIX;
> > 
> > Looking at virDomainChrSourceDefClear(), called by
> > virDomainTPMDefFree(), when type is CHR_TYPE_UNIX data.nix.path
> > will be VIR_FREE()d, so I think you want to set type to
> > CHR_TYPE_FILE instead.
> 
> Ah, good point. Do you trust me enough that I can fix this before
> pushing or do you want to see v2? ;-)

No need for a v2, just fix it and push O:-)

Reviewed-by: Andrea Bolognani <abologna@redhat.com>

-- 
Andrea Bolognani / Red Hat / Virtualization

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list