From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTP id 301F55A005E for ; Tue, 7 Feb 2023 16:10:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675782653; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=K8fsZXXWvU159yQX+42OU414zvtTRKzJBwFqY+BwuPw=; b=hSO4IZBgO0wU3NJevwQn22GLkZ22w+3bwJusuGRqxdq6J/1S2kadLnSAfIQ9PZ5AEqWn9V +BJUsUqEsQc75XVlhQ6n1pYhVebFHr8E9ynWvR88HNuDRZ+FFS4xctaki8cpA8vAXNLG5b BrXGdEYKdui7renFyZOqOrlWQYz4WuI= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-634-GvTT_EApPB-Gz8zI-_iqDg-1; Tue, 07 Feb 2023 10:10:51 -0500 X-MC-Unique: GvTT_EApPB-Gz8zI-_iqDg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9AA6B3C18346 for ; Tue, 7 Feb 2023 15:10:51 +0000 (UTC) Received: from pholzing-fedora.redhat.com (unknown [10.39.194.147]) by smtp.corp.redhat.com (Postfix) with ESMTP id D2179C15BA0; Tue, 7 Feb 2023 15:10:50 +0000 (UTC) From: Paul Holzinger To: passt-dev@passt.top Subject: [PATCH] pasta: do not leak netlink sock into child Date: Tue, 7 Feb 2023 16:10:46 +0100 Message-Id: <20230207151046.76157-1-pholzing@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-MailFrom: pholzing@redhat.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation Message-ID-Hash: TK4KMZBASTQT4LIGNPT4JZZDSY3CLUJS X-Message-ID-Hash: TK4KMZBASTQT4LIGNPT4JZZDSY3CLUJS X-Mailman-Approved-At: Tue, 07 Feb 2023 16:22:40 +0100 CC: Paul Holzinger X-Mailman-Version: 3.3.3 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- 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; } -- 2.39.1