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 59ADA5A0265 for ; Sat, 22 Oct 2022 10:15:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666426541; 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=/grP+F0v1zu/FPkhBiYQgwbP6M1r/pX43v1MLU7vyec=; b=FlO/gOUMMPmr06OfdcLf0rm2wjwAMKc6LE1ucU+sESlU3zD9ZpT7Xa8zrWTN4kA0A5y3Ju oa6ExUCsuqVGWKrJMZV1ApSNro4eSuWouOOEpRU3dgqJesFXMtQLbAmZ/s5N/hlzkR5+Ch tR1YkX91xvmfsLzyAkrBelRvbT0xCRA= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-416-bHosKPIFPyKSlhom_XY0pA-1; Sat, 22 Oct 2022 04:15:39 -0400 X-MC-Unique: bHosKPIFPyKSlhom_XY0pA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A22CC886063 for ; Sat, 22 Oct 2022 08:15:39 +0000 (UTC) Received: from maya.cloud.tilaa.com (ovpn-208-31.brq.redhat.com [10.40.208.31]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 75D0140C2064; Sat, 22 Oct 2022 08:15:39 +0000 (UTC) Date: Sat, 22 Oct 2022 10:15:35 +0200 From: Stefano Brivio To: passt-dev@passt.top Subject: Re: [PATCH] util: Set NS_FN_STACK_SIZE to one eighth of ulimit-reported maximum stack size Message-ID: <20221022101535.4ceda8d6@elisabeth> In-Reply-To: <20221022064503.386563-1-sbrivio@redhat.com> References: <20221022064503.386563-1-sbrivio@redhat.com> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: EHWWNEP37DT5B5IHOL572KQM5EBBDDUG X-Message-ID-Hash: EHWWNEP37DT5B5IHOL572KQM5EBBDDUG X-MailFrom: sbrivio@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Andrea Bolognani 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 Sat, 22 Oct 2022 08:45:03 +0200 Stefano Brivio wrote: > ...instead of one fourth. On the main() -> conf() -> nl_sock_init() > call path, LTO from gcc 12 on (at least) x86_64 decides to inline... > everything: nl_sock_init() is effectively part of main(), after > commit 3e2eb4337bc0 ("conf: Bind inbound ports with > CAP_NET_BIND_SERVICE before isolate_user()"). > > This means we exceed the maximum stack size, and we get SIGSEGV, > under any condition, at start time, as reported by Andrea on a recent > build for CentOS Stream 9. > > The calculation of NS_FN_STACK_SIZE, which is the stack size we > reserve for clones, was previously obtained by dividing the maximum > stack size by two, to avoid an explicit check on architecture (on > PA-RISC, also known as hppa, the stack grows up, so we point the > clone to the middle of this area), and then further divided by two > to allow for any additional usage in the caller. > > Well, if there are essentially no function calls anymore, this is > not enough. Divide it by eight, which is anyway much more than > possibly needed by any clone()d callee. > > I think this is robust, so it's a fix in some sense. Strictly > speaking, though, we have no formal guarantees that this isn't > either too little or too much. > > What we should do, eventually: check cloned() callees, there are just > thirteen of them at the moment. Note down any stack usage (they are > mostly small helpers), bonus points for an automated way at build > time, quadruple that or so, to allow for extreme clumsiness, and use > as NS_FN_STACK_SIZE. Perhaps introduce a specific condition for hppa. > > Reported-by: Andrea Bolognani > Fixes: 3e2eb4337bc0 ("conf: Bind inbound ports with CAP_NET_BIND_SERVICE before isolate_user()") > Signed-off-by: Stefano Brivio > --- I posted this in any case for (later) review, but I'm actually applying it right away, given that some builds are completely unusable otherwise. I guess it would make sense to extend build ("distro") tests with some compiler flags, common and less common. -- Stefano