qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/2] virtfs-proxy-helper: Fix Coverity warning
@ 2014-11-13 12:17 arei.gonglei
  2014-11-13 12:17 ` [Qemu-devel] [PATCH 1/2] virtfs-proxy-helper: Fix possible socket leak arei.gonglei
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: arei.gonglei @ 2014-11-13 12:17 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-trivial, Gonglei, aneesh.kumar, peter.huangpeng

From: Gonglei <arei.gonglei@huawei.com>

Gonglei (2):
  virtfs-proxy-helper: Fix possible socket leak.
  virtfs-proxy-helper: Fix handle leak to make Coverity happy

 fsdev/virtfs-proxy-helper.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

-- 
1.7.12.4

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Qemu-devel] [PATCH 1/2] virtfs-proxy-helper: Fix possible socket leak.
  2014-11-13 12:17 [Qemu-devel] [PATCH 0/2] virtfs-proxy-helper: Fix Coverity warning arei.gonglei
@ 2014-11-13 12:17 ` arei.gonglei
  2014-11-27 12:49   ` Markus Armbruster
  2014-11-13 12:17 ` [Qemu-devel] [PATCH 2/2] virtfs-proxy-helper: Fix handle leak to make Coverity happy arei.gonglei
  2014-11-27 10:29 ` [Qemu-devel] [PATCH 0/2] virtfs-proxy-helper: Fix Coverity warning Gonglei
  2 siblings, 1 reply; 13+ messages in thread
From: arei.gonglei @ 2014-11-13 12:17 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-trivial, Gonglei, aneesh.kumar, peter.huangpeng

From: Gonglei <arei.gonglei@huawei.com>

Signed-off-by: Gonglei <arei.gonglei@huawei.com>
---
 fsdev/virtfs-proxy-helper.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/fsdev/virtfs-proxy-helper.c b/fsdev/virtfs-proxy-helper.c
index cd291d3..c1da2d7 100644
--- a/fsdev/virtfs-proxy-helper.c
+++ b/fsdev/virtfs-proxy-helper.c
@@ -749,24 +749,29 @@ static int proxy_socket(const char *path, uid_t uid, gid_t gid)
     if (bind(sock, (struct sockaddr *)&proxy,
             sizeof(struct sockaddr_un)) < 0) {
         do_perror("bind");
-        return -1;
+        goto error;
     }
     if (chown(proxy.sun_path, uid, gid) < 0) {
         do_perror("chown");
-        return -1;
+        goto error;
     }
     if (listen(sock, 1) < 0) {
         do_perror("listen");
-        return -1;
+        goto error;
     }
 
     size = sizeof(qemu);
     client = accept(sock, (struct sockaddr *)&qemu, &size);
     if (client < 0) {
         do_perror("accept");
-        return -1;
+        goto error;
     }
+    close(sock);
     return client;
+
+error:
+    close(sock);
+    return -1;
 }
 
 static void usage(char *prog)
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [Qemu-devel] [PATCH 2/2] virtfs-proxy-helper: Fix handle leak to make Coverity happy
  2014-11-13 12:17 [Qemu-devel] [PATCH 0/2] virtfs-proxy-helper: Fix Coverity warning arei.gonglei
  2014-11-13 12:17 ` [Qemu-devel] [PATCH 1/2] virtfs-proxy-helper: Fix possible socket leak arei.gonglei
@ 2014-11-13 12:17 ` arei.gonglei
  2014-11-27 12:47   ` Markus Armbruster
  2014-11-27 10:29 ` [Qemu-devel] [PATCH 0/2] virtfs-proxy-helper: Fix Coverity warning Gonglei
  2 siblings, 1 reply; 13+ messages in thread
From: arei.gonglei @ 2014-11-13 12:17 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-trivial, Gonglei, aneesh.kumar, peter.huangpeng

From: Gonglei <arei.gonglei@huawei.com>

Coverity report:
(94) Event open_fn:  Returning handle opened by function "proxy_socket(char const *, uid_t, gid_t)". [details]
(95) Event var_assign:  Assigning: "sock" = handle returned from "proxy_socket(sock_name, own_u, own_g)".
(103) Event leaked_handle:  Handle variable "sock" going out of scope leaks the handle.

Signed-off-by: Gonglei <arei.gonglei@huawei.com>
---
 fsdev/virtfs-proxy-helper.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/fsdev/virtfs-proxy-helper.c b/fsdev/virtfs-proxy-helper.c
index c1da2d7..2d72def 100644
--- a/fsdev/virtfs-proxy-helper.c
+++ b/fsdev/virtfs-proxy-helper.c
@@ -1150,6 +1150,9 @@ int main(int argc, char **argv)
 
     process_requests(sock);
 error:
+    if (sock_name && sock >= 0) {
+        close(sock);
+    }
     do_log(LOG_INFO, "Done\n");
     closelog();
     return 0;
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [Qemu-devel] [PATCH 0/2] virtfs-proxy-helper: Fix Coverity warning
  2014-11-13 12:17 [Qemu-devel] [PATCH 0/2] virtfs-proxy-helper: Fix Coverity warning arei.gonglei
  2014-11-13 12:17 ` [Qemu-devel] [PATCH 1/2] virtfs-proxy-helper: Fix possible socket leak arei.gonglei
  2014-11-13 12:17 ` [Qemu-devel] [PATCH 2/2] virtfs-proxy-helper: Fix handle leak to make Coverity happy arei.gonglei
@ 2014-11-27 10:29 ` Gonglei
  2014-11-28  8:31   ` Paolo Bonzini
  2 siblings, 1 reply; 13+ messages in thread
From: Gonglei @ 2014-11-27 10:29 UTC (permalink / raw)
  To: Gonglei (Arei)
  Cc: qemu-trivial@nongnu.org, Huangpeng (Peter), qemu-devel@nongnu.org,
	aneesh.kumar@linux.vnet.ibm.com

On 2014/11/13 20:17, Gonglei (Arei) wrote:

> From: Gonglei <arei.gonglei@huawei.com>
> 
> Gonglei (2):
>   virtfs-proxy-helper: Fix possible socket leak.
>   virtfs-proxy-helper: Fix handle leak to make Coverity happy
> 
>  fsdev/virtfs-proxy-helper.c | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
> 

Ping...

Thanks,
-Gonglei

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Qemu-devel] [PATCH 2/2] virtfs-proxy-helper: Fix handle leak to make Coverity happy
  2014-11-13 12:17 ` [Qemu-devel] [PATCH 2/2] virtfs-proxy-helper: Fix handle leak to make Coverity happy arei.gonglei
@ 2014-11-27 12:47   ` Markus Armbruster
  2014-11-28  1:51     ` Gonglei
  0 siblings, 1 reply; 13+ messages in thread
From: Markus Armbruster @ 2014-11-27 12:47 UTC (permalink / raw)
  To: arei.gonglei; +Cc: qemu-trivial, peter.huangpeng, qemu-devel, aneesh.kumar

<arei.gonglei@huawei.com> writes:

> From: Gonglei <arei.gonglei@huawei.com>
>
> Coverity report:
> (94) Event open_fn:  Returning handle opened by function "proxy_socket(char const *, uid_t, gid_t)". [details]
> (95) Event var_assign:  Assigning: "sock" = handle returned from "proxy_socket(sock_name, own_u, own_g)".
> (103) Event leaked_handle:  Handle variable "sock" going out of scope leaks the handle.
>
> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
> ---
>  fsdev/virtfs-proxy-helper.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/fsdev/virtfs-proxy-helper.c b/fsdev/virtfs-proxy-helper.c
> index c1da2d7..2d72def 100644
> --- a/fsdev/virtfs-proxy-helper.c
> +++ b/fsdev/virtfs-proxy-helper.c
> @@ -1150,6 +1150,9 @@ int main(int argc, char **argv)
>  
>      process_requests(sock);
>  error:
> +    if (sock_name && sock >= 0) {
> +        close(sock);
> +    }
>      do_log(LOG_INFO, "Done\n");
>      closelog();
>      return 0;

Why if sock_name?  What about sock gotten from -f?

If sock >= 0 is pointless, too, but needed to hush up Coverity.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Qemu-devel] [PATCH 1/2] virtfs-proxy-helper: Fix possible socket leak.
  2014-11-13 12:17 ` [Qemu-devel] [PATCH 1/2] virtfs-proxy-helper: Fix possible socket leak arei.gonglei
@ 2014-11-27 12:49   ` Markus Armbruster
  2015-01-21  8:00     ` Gonglei
  0 siblings, 1 reply; 13+ messages in thread
From: Markus Armbruster @ 2014-11-27 12:49 UTC (permalink / raw)
  To: arei.gonglei; +Cc: qemu-trivial, peter.huangpeng, qemu-devel, aneesh.kumar

<arei.gonglei@huawei.com> writes:

> From: Gonglei <arei.gonglei@huawei.com>
>
> Signed-off-by: Gonglei <arei.gonglei@huawei.com>

Reviewed-by: Markus Armbruster <armbru@redhat.com>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Qemu-devel] [PATCH 2/2] virtfs-proxy-helper: Fix handle leak to make Coverity happy
  2014-11-27 12:47   ` Markus Armbruster
@ 2014-11-28  1:51     ` Gonglei
  2014-11-28  7:29       ` Markus Armbruster
  0 siblings, 1 reply; 13+ messages in thread
From: Gonglei @ 2014-11-28  1:51 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: qemu-trivial@nongnu.org, Huangpeng (Peter), qemu-devel@nongnu.org,
	aneesh.kumar@linux.vnet.ibm.com

On 2014/11/27 20:47, Markus Armbruster wrote:

> <arei.gonglei@huawei.com> writes:
> 
>> From: Gonglei <arei.gonglei@huawei.com>
>>
>> Coverity report:
>> (94) Event open_fn:  Returning handle opened by function "proxy_socket(char const *, uid_t, gid_t)". [details]
>> (95) Event var_assign:  Assigning: "sock" = handle returned from "proxy_socket(sock_name, own_u, own_g)".
>> (103) Event leaked_handle:  Handle variable "sock" going out of scope leaks the handle.
>>
>> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
>> ---
>>  fsdev/virtfs-proxy-helper.c | 3 +++
>>  1 file changed, 3 insertions(+)
>>
>> diff --git a/fsdev/virtfs-proxy-helper.c b/fsdev/virtfs-proxy-helper.c
>> index c1da2d7..2d72def 100644
>> --- a/fsdev/virtfs-proxy-helper.c
>> +++ b/fsdev/virtfs-proxy-helper.c
>> @@ -1150,6 +1150,9 @@ int main(int argc, char **argv)
>>  
>>      process_requests(sock);
>>  error:
>> +    if (sock_name && sock >= 0) {
>> +        close(sock);
>> +    }
>>      do_log(LOG_INFO, "Done\n");
>>      closelog();
>>      return 0;
> 
> Why if sock_name?  What about sock gotten from -f?
>

Thanks for your review, Makus :)

 

Because only sock_name is non-NULL, the sock returned from
"proxy_socket(sock_name, own_u, own_g)", then will leak fd.
If sock gotten from -f, maybe the caller will free it IMO.

> If sock >= 0 is pointless, too, but needed to hush up Coverity.

You mean do not check sock_name is NULL or not?

Regards,
-Gonglei

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Qemu-devel] [PATCH 2/2] virtfs-proxy-helper: Fix handle leak to make Coverity happy
  2014-11-28  1:51     ` Gonglei
@ 2014-11-28  7:29       ` Markus Armbruster
  2014-11-28  7:41         ` Gonglei
  0 siblings, 1 reply; 13+ messages in thread
From: Markus Armbruster @ 2014-11-28  7:29 UTC (permalink / raw)
  To: Gonglei
  Cc: qemu-trivial@nongnu.org, aneesh.kumar@linux.vnet.ibm.com,
	Huangpeng (Peter), qemu-devel@nongnu.org

Gonglei <arei.gonglei@huawei.com> writes:

> On 2014/11/27 20:47, Markus Armbruster wrote:
>
>> <arei.gonglei@huawei.com> writes:
>> 
>>> From: Gonglei <arei.gonglei@huawei.com>
>>>
>>> Coverity report:
>>> (94) Event open_fn:  Returning handle opened by function "proxy_socket(char const *, uid_t, gid_t)". [details]
>>> (95) Event var_assign:  Assigning: "sock" = handle returned from "proxy_socket(sock_name, own_u, own_g)".
>>> (103) Event leaked_handle:  Handle variable "sock" going out of scope leaks the handle.
>>>
>>> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
>>> ---
>>>  fsdev/virtfs-proxy-helper.c | 3 +++
>>>  1 file changed, 3 insertions(+)
>>>
>>> diff --git a/fsdev/virtfs-proxy-helper.c b/fsdev/virtfs-proxy-helper.c
>>> index c1da2d7..2d72def 100644
>>> --- a/fsdev/virtfs-proxy-helper.c
>>> +++ b/fsdev/virtfs-proxy-helper.c
>>> @@ -1150,6 +1150,9 @@ int main(int argc, char **argv)
>>>  
>>>      process_requests(sock);
>>>  error:
>>> +    if (sock_name && sock >= 0) {
>>> +        close(sock);
>>> +    }
>>>      do_log(LOG_INFO, "Done\n");
>>>      closelog();
>>>      return 0;
>> 
>> Why if sock_name?  What about sock gotten from -f?
>>
>
> Thanks for your review, Makus :)
>
>  
>
> Because only sock_name is non-NULL, the sock returned from
> "proxy_socket(sock_name, own_u, own_g)", then will leak fd.
> If sock gotten from -f, maybe the caller will free it IMO.

Since this is main(), the "caller" is the OS.  And yes, the OS closes
the -f file descriptor when main() returns, because it closes *all* file
descriptors.  Calling close() before return from main() is pointless,
unless you check for errors.

Unfortunately, Coverity doesn't understand this.  Calling close() in
main() suppresses its bogus defect report.

>> If sock >= 0 is pointless, too, but needed to hush up Coverity.
>
> You mean do not check sock_name is NULL or not?

Yes, unless it causes another bogus Coverity defect.

Or simply mark the defect as invalid and move on without patching the
code.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Qemu-devel] [PATCH 2/2] virtfs-proxy-helper: Fix handle leak to make Coverity happy
  2014-11-28  7:29       ` Markus Armbruster
@ 2014-11-28  7:41         ` Gonglei
  0 siblings, 0 replies; 13+ messages in thread
From: Gonglei @ 2014-11-28  7:41 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: qemu-trivial@nongnu.org, aneesh.kumar@linux.vnet.ibm.com,
	Huangpeng (Peter), qemu-devel@nongnu.org

On 2014/11/28 15:29, Markus Armbruster wrote:

> Since this is main(), the "caller" is the OS.  And yes, the OS closes
> the -f file descriptor when main() returns, because it closes *all* file
> descriptors.  Calling close() before return from main() is pointless,
> unless you check for errors.
> 
> Unfortunately, Coverity doesn't understand this.  Calling close() in
> main() suppresses its bogus defect report.
> 

Yes.

>>> >> If sock >= 0 is pointless, too, but needed to hush up Coverity.
>> >
>> > You mean do not check sock_name is NULL or not?
> Yes, unless it causes another bogus Coverity defect.
> 
> Or simply mark the defect as invalid and move on without patching the
> code.

Let's drop this patch, thanks.

Regards,
-Gonglei

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Qemu-devel] [PATCH 0/2] virtfs-proxy-helper: Fix Coverity warning
  2014-11-27 10:29 ` [Qemu-devel] [PATCH 0/2] virtfs-proxy-helper: Fix Coverity warning Gonglei
@ 2014-11-28  8:31   ` Paolo Bonzini
  2014-11-28  8:34     ` Gonglei
  0 siblings, 1 reply; 13+ messages in thread
From: Paolo Bonzini @ 2014-11-28  8:31 UTC (permalink / raw)
  To: Gonglei
  Cc: qemu-trivial@nongnu.org, aneesh.kumar@linux.vnet.ibm.com,
	Huangpeng (Peter), qemu-devel@nongnu.org



On 27/11/2014 11:29, Gonglei wrote:
> On 2014/11/13 20:17, Gonglei (Arei) wrote:
> 
>> From: Gonglei <arei.gonglei@huawei.com>
>>
>> Gonglei (2):
>>   virtfs-proxy-helper: Fix possible socket leak.
>>   virtfs-proxy-helper: Fix handle leak to make Coverity happy
>>
>>  fsdev/virtfs-proxy-helper.c | 16 ++++++++++++----
>>  1 file changed, 12 insertions(+), 4 deletions(-)
>>
> 
> Ping...

Hi Gonglei---thanks, I had missed this and Michael is probably not
sending qemu-trivial patches because we're so close to the release.
I'll pick up patch 1.

Paolo

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Qemu-devel] [PATCH 0/2] virtfs-proxy-helper: Fix Coverity warning
  2014-11-28  8:31   ` Paolo Bonzini
@ 2014-11-28  8:34     ` Gonglei
  0 siblings, 0 replies; 13+ messages in thread
From: Gonglei @ 2014-11-28  8:34 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: qemu-trivial@nongnu.org, aneesh.kumar@linux.vnet.ibm.com,
	Huangpeng (Peter), qemu-devel@nongnu.org

On 2014/11/28 16:31, Paolo Bonzini wrote:

> 
> 
> On 27/11/2014 11:29, Gonglei wrote:
>> On 2014/11/13 20:17, Gonglei (Arei) wrote:
>>
>>> From: Gonglei <arei.gonglei@huawei.com>
>>>
>>> Gonglei (2):
>>>   virtfs-proxy-helper: Fix possible socket leak.
>>>   virtfs-proxy-helper: Fix handle leak to make Coverity happy
>>>
>>>  fsdev/virtfs-proxy-helper.c | 16 ++++++++++++----
>>>  1 file changed, 12 insertions(+), 4 deletions(-)
>>>
>>
>> Ping...
> 
> Hi Gonglei---thanks, I had missed this and Michael is probably not
> sending qemu-trivial patches because we're so close to the release.
> I'll pick up patch 1.
> 
> Paolo

Thanks.
As Markus's suggestion, we drop patch 2.  :)

Regards,
-Gonglei

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Qemu-devel] [PATCH 1/2] virtfs-proxy-helper: Fix possible socket leak.
  2014-11-27 12:49   ` Markus Armbruster
@ 2015-01-21  8:00     ` Gonglei
  2015-01-21  8:06       ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
  0 siblings, 1 reply; 13+ messages in thread
From: Gonglei @ 2015-01-21  8:00 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: qemu-trivial@nongnu.org, Huangpeng (Peter), Michael Tokarev,
	qemu-devel@nongnu.org, aneesh.kumar@linux.vnet.ibm.com

On 2014/11/27 20:49, Markus Armbruster wrote:

> <arei.gonglei@huawei.com> writes:
> 
>> From: Gonglei <arei.gonglei@huawei.com>
>>
>> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
> 
> Reviewed-by: Markus Armbruster <armbru@redhat.com>

Hi, Michael

I guess Paolo forgot this patch :(
Maybe this one can be picked up by qemu-trivial. Thanks.

Regards,
-Gonglei

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Qemu-devel] [Qemu-trivial] [PATCH 1/2] virtfs-proxy-helper: Fix possible socket leak.
  2015-01-21  8:00     ` Gonglei
@ 2015-01-21  8:06       ` Michael Tokarev
  0 siblings, 0 replies; 13+ messages in thread
From: Michael Tokarev @ 2015-01-21  8:06 UTC (permalink / raw)
  To: Gonglei, Markus Armbruster
  Cc: qemu-trivial@nongnu.org, aneesh.kumar@linux.vnet.ibm.com,
	Huangpeng (Peter), qemu-devel@nongnu.org

21.01.2015 11:00, Gonglei wrote:
[]
> Hi, Michael
> 
> I guess Paolo forgot this patch :(
> Maybe this one can be picked up by qemu-trivial. Thanks.

I picked it up and applied to -trivial.
It is not a problem if the same patch will be applied to
several trees at once, so if Paolo will send a pull request
for it together with me it all will work ok.

Thanks,

/mjt

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2015-01-21  8:06 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-13 12:17 [Qemu-devel] [PATCH 0/2] virtfs-proxy-helper: Fix Coverity warning arei.gonglei
2014-11-13 12:17 ` [Qemu-devel] [PATCH 1/2] virtfs-proxy-helper: Fix possible socket leak arei.gonglei
2014-11-27 12:49   ` Markus Armbruster
2015-01-21  8:00     ` Gonglei
2015-01-21  8:06       ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
2014-11-13 12:17 ` [Qemu-devel] [PATCH 2/2] virtfs-proxy-helper: Fix handle leak to make Coverity happy arei.gonglei
2014-11-27 12:47   ` Markus Armbruster
2014-11-28  1:51     ` Gonglei
2014-11-28  7:29       ` Markus Armbruster
2014-11-28  7:41         ` Gonglei
2014-11-27 10:29 ` [Qemu-devel] [PATCH 0/2] virtfs-proxy-helper: Fix Coverity warning Gonglei
2014-11-28  8:31   ` Paolo Bonzini
2014-11-28  8:34     ` Gonglei

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).