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 D888C5A005E for ; Fri, 3 Feb 2023 15:44:45 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675435484; 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: in-reply-to:in-reply-to:references:references; bh=TgNLjgChOMAFhpcJO762mLFZOiiJ87UaY/x1Wm3EdC4=; b=ENmdnsvOvkGpQcyKdWMO6xIaX+L1aM9agx3K56f5MEAtDQYFaW7huJF3nTp48EnvoyRJ0y JQJYKjCX9Dz431dkWj1uHl3XbafLp7Dzevj6AlfTJiNSlUzUeNsfKPZRbYnSA9ZEiz+vBl jWzwJpFoX2NxjSmk4YbdXQ/baUya5Po= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-640-KErBtNBtPsa5Nj-uNQ1J9A-1; Fri, 03 Feb 2023 09:44:43 -0500 X-MC-Unique: KErBtNBtPsa5Nj-uNQ1J9A-1 Received: by mail-wm1-f71.google.com with SMTP id d18-20020a05600c34d200b003df901ab982so2763056wmq.4 for ; Fri, 03 Feb 2023 06:44:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=TgNLjgChOMAFhpcJO762mLFZOiiJ87UaY/x1Wm3EdC4=; b=AIUXK//iMr0SC1FILcB/2G/d1yk65bi4A6SyrgJqU7gV/r8FnVnvztmihta60zbLA9 xNlwujhmKJU3fIUYFDsaU0cGQfTpvylWuAqwDVDuEWsj0G0giAo1OcTvNtNAf38LOiy+ WbJaKY578xhCH4IQsAjO+vZyrYQc/APseWueu/r7jeoJzm18qnAPk62PyJNBwhTJDPDq I+anINeXDsgMvkmBIAYsFPy/RXT3MRmKSv98gZO0qPM21rdeQOVZ4HSkfsFulj50aEHH lYmkGkcLIw625a0Cr9x2WzinNlm+ccD7Wf9iztd6InOAvVbVSEeQg9LlWoxzuJlBvgFK E7cw== X-Gm-Message-State: AO0yUKWsouGNovv48VMuoxeFJJbOtg5GlBDk8U6JNCZKpy7+XzhxMwU9 F1Jj9/F5l7VoVJUYUFY6bn+Nj3gxoqiJwfgsCizhWwYxMsuENd499dNLqeLrBW6LnDCjkt641tW uXhX0eNXwQOwf X-Received: by 2002:a5d:660f:0:b0:2bf:ad43:8f08 with SMTP id n15-20020a5d660f000000b002bfad438f08mr8597462wru.14.1675435482655; Fri, 03 Feb 2023 06:44:42 -0800 (PST) X-Google-Smtp-Source: AK7set/3cJIXZJDr2KzegEgemKGhaP/VLFw1zk4oiAQ7A6FgBhuUI+EdjoLgx71PnKNC7zWIfizdOg== X-Received: by 2002:a5d:660f:0:b0:2bf:ad43:8f08 with SMTP id n15-20020a5d660f000000b002bfad438f08mr8597452wru.14.1675435482395; Fri, 03 Feb 2023 06:44:42 -0800 (PST) Received: from [192.168.188.25] ([80.243.52.134]) by smtp.gmail.com with ESMTPSA id i14-20020a0560001ace00b002bfb8f829eesm2264813wry.71.2023.02.03.06.44.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 03 Feb 2023 06:44:41 -0800 (PST) Message-ID: <7df94a05-50a5-26d8-784c-3565b6578212@redhat.com> Date: Fri, 3 Feb 2023 15:44:40 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Subject: Re: [PATCH] pasta: wait for netns setup before calling exec To: Stefano Brivio References: <20230201180116.21281-1-pholzing@redhat.com> <20230202112506.187d852e@elisabeth> From: Paul Holzinger In-Reply-To: <20230202112506.187d852e@elisabeth> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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: O5LPNETYTXZICVC3PBMDNGHGU437QOSP X-Message-ID-Hash: O5LPNETYTXZICVC3PBMDNGHGU437QOSP X-Mailman-Approved-At: Fri, 03 Feb 2023 22:46:53 +0100 CC: passt-dev@passt.top 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: On 02/02/2023 11:25, Stefano Brivio wrote: > On Wed, 1 Feb 2023 19:01:16 +0100 > Paul Holzinger wrote: > >> When a user spawns a command with pasta they expect the network to be >> ready. Currently this does not work because pasta will fork/exec >> before it will setup the network config. >> >> This patch fixes it by using a pipe to sync parent and child. The child >> will now block reading from this pipe before the exec call. The parent >> will then unblock the child only after the netns was configured. > Thanks for the patch! I'm reviewing this in a bit. > > A few considerations meanwhile: > > - there's actually a bigger issue (you're fixing here) than the > namespace configuration (via netlink) itself: the tap device isn't > ready (tap_sock_init() hasn't been called yet) when we spawn the > command in the new namespace. Oops. > > If you're wondering: we can't just reorder things, because to complete > the configuration phase (conf()) we need the namespace to be set up, > and we can't initialise the tap device before it's set up > > - pipes are more commonly used to transfer data around (hence the whole > code you need to open a communication channel, check it, close it). > Did you try with a signal? Or is there a reason why it wouldn't work? > > You could simply SIGSTOP the child, from the child itself: > > kill(getpid(), SIGSTOP); > > and send a SIGCONT to it (we already store the PID of the child in > pasta_child_pid) once we're ready. > > SIGCONT is special in that it doesn't need CAP_KILL or the processes > to run under the same UID -- just in the same session, so it wouldn't > risk interfering with the isolation_*() calls. > > I haven't tested this but I think it should lead to simpler code. > Thinking about this more STOP/CONT will not work reliably, it could stop the child forever when the parent sends SIGCONT before the child SIGSTOPs itself. While this is unlikely we have no control over how both processes are scheduled. With this pipe version there is no problem when the parent closes the fd before the child calls read, read will simply return EOF and the child can continue, thus it will work correctly in all cases.