public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
* [PATCH] pasta: do not leak netlink sock into child
@ 2023-02-07 15:10 Paul Holzinger
  2023-02-08 13:00 ` Stefano Brivio
  2023-02-13  1:15 ` Stefano Brivio
  0 siblings, 2 replies; 3+ messages in thread
From: Paul Holzinger @ 2023-02-07 15:10 UTC (permalink / raw)
  To: passt-dev; +Cc: Paul Holzinger

When spawning a child command with pasta command... pasta should not
leak fds that it opened. Only the fds that were already open should be
given to the child.

Run `pasta --config-net -- ls -l /proc/self/fd` from a terminal where
only stdin/out/err are open. The fd 3 was opend by ls to read the
/proc/self/fd dir. But fd 5 is the netlink socket that was opend in
pasta. To prevent such a leak we will open the socket with SOCK_CLOEXEC.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
---
 netlink.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/netlink.c b/netlink.c
index 0850cbe..b8fa2a0 100644
--- a/netlink.c
+++ b/netlink.c
@@ -56,8 +56,8 @@ static int nl_sock_init_do(void *arg)
 	if (arg)
 		ns_enter((struct ctx *)arg);
 
-	if (((*s) = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE)) < 0 ||
-	    bind(*s, (struct sockaddr *)&addr, sizeof(addr))) {
+	*s = socket(AF_NETLINK, SOCK_RAW | SOCK_CLOEXEC, NETLINK_ROUTE);
+	if (*s < 0 || bind(*s, (struct sockaddr *)&addr, sizeof(addr))) {
 		*s = -1;
 		return 0;
 	}
-- 
@@ -56,8 +56,8 @@ static int nl_sock_init_do(void *arg)
 	if (arg)
 		ns_enter((struct ctx *)arg);
 
-	if (((*s) = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE)) < 0 ||
-	    bind(*s, (struct sockaddr *)&addr, sizeof(addr))) {
+	*s = socket(AF_NETLINK, SOCK_RAW | SOCK_CLOEXEC, NETLINK_ROUTE);
+	if (*s < 0 || bind(*s, (struct sockaddr *)&addr, sizeof(addr))) {
 		*s = -1;
 		return 0;
 	}
-- 
2.39.1


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

* Re: [PATCH] pasta: do not leak netlink sock into child
  2023-02-07 15:10 [PATCH] pasta: do not leak netlink sock into child Paul Holzinger
@ 2023-02-08 13:00 ` Stefano Brivio
  2023-02-13  1:15 ` Stefano Brivio
  1 sibling, 0 replies; 3+ messages in thread
From: Stefano Brivio @ 2023-02-08 13:00 UTC (permalink / raw)
  To: Paul Holzinger; +Cc: passt-dev

On Tue,  7 Feb 2023 16:10:46 +0100
Paul Holzinger <pholzing@redhat.com> wrote:

> When spawning a child command with pasta command... pasta should not
> leak fds that it opened. Only the fds that were already open should be
> given to the child.
> 
> Run `pasta --config-net -- ls -l /proc/self/fd` from a terminal where
> only stdin/out/err are open. The fd 3 was opend by ls to read the
> /proc/self/fd dir. But fd 5 is the netlink socket that was opend in
> pasta. To prevent such a leak we will open the socket with SOCK_CLOEXEC.
> 
> Signed-off-by: Paul Holzinger <pholzing@redhat.com>

Thanks for the patch, and welcome to the git log!

I'll push this out in a bit (still sorting some unrelated test failures
first).

-- 
Stefano


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

* Re: [PATCH] pasta: do not leak netlink sock into child
  2023-02-07 15:10 [PATCH] pasta: do not leak netlink sock into child Paul Holzinger
  2023-02-08 13:00 ` Stefano Brivio
@ 2023-02-13  1:15 ` Stefano Brivio
  1 sibling, 0 replies; 3+ messages in thread
From: Stefano Brivio @ 2023-02-13  1:15 UTC (permalink / raw)
  To: Paul Holzinger; +Cc: passt-dev

On Tue,  7 Feb 2023 16:10:46 +0100
Paul Holzinger <pholzing@redhat.com> wrote:

> When spawning a child command with pasta command... pasta should not
> leak fds that it opened. Only the fds that were already open should be
> given to the child.
> 
> Run `pasta --config-net -- ls -l /proc/self/fd` from a terminal where
> only stdin/out/err are open. The fd 3 was opend by ls to read the
> /proc/self/fd dir. But fd 5 is the netlink socket that was opend in
> pasta. To prevent such a leak we will open the socket with SOCK_CLOEXEC.
> 
> Signed-off-by: Paul Holzinger <pholzing@redhat.com>

Applied.

-- 
Stefano


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

end of thread, other threads:[~2023-02-13  1:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-07 15:10 [PATCH] pasta: do not leak netlink sock into child Paul Holzinger
2023-02-08 13:00 ` Stefano Brivio
2023-02-13  1:15 ` Stefano Brivio

Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

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 IMAP folder(s).