From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mta1.formilux.org (mta1.formilux.org [51.159.59.229]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D5F461367 for ; Fri, 22 May 2026 09:39:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=51.159.59.229 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779442772; cv=none; b=XJ9Sx8ZGxfV8RZfl8sBJNCXQ7YB6acJSzm77I+T5p2p5eR2JnewTNjtUK24hwfZ5j1K5X/loufBZ+fl/J5Wv996NFvN7LTPsJmUsmE5g+DBHRtLYdP6ddV84YZmNbLXLdU1YsShArjjYhDK8YUuOkX7nDBk9N2yml5egQb8eglw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779442772; c=relaxed/simple; bh=nGjqHIf7aFC41VvB1rqUFNSz/VYUUGXANUZI+tQ7jWU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=TEYhQtFk+Xd2nXuQjcPui9UWJEgxRctZ0gu8t+UQDMb3QLwnqJB14DmatuYw+9j8xfxSwdAvfu21YC0mOrYZk56QYdqmJSqZ83R2+PuVxajuqzmegm/J2Zlapg52HJ1aS///p5SGf9GKNwnL0zRdzhUWKJVVvTbN1MRoR99f1wQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=1wt.eu; spf=pass smtp.mailfrom=1wt.eu; dkim=pass (1024-bit key) header.d=1wt.eu header.i=@1wt.eu header.b=DzZAX5ef; arc=none smtp.client-ip=51.159.59.229 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=1wt.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=1wt.eu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=1wt.eu header.i=@1wt.eu header.b="DzZAX5ef" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1wt.eu; s=mail; t=1779442768; bh=Gjqqkmg5gqtwZnBdWRpvY/D71NTMdbfgyd/TNL0s0Jo=; h=From:Message-ID:From; b=DzZAX5efmgsEF9V13CZ2XyHHBZPh/oUep+QIiS20K6Nn8XDUTKR8Ie2RKXFUFoSNX iqQ9GICiu7psmpfBevtBttYhRkkw05awNtH7d7cBTDB3Z3g9thRVmz2WfZ4yJrDVcN nXVwfbtOwbaraN1eF5DHfzG/87iU4mEsK9S1eo2Y= Received: from 1wt.eu (ded1.1wt.eu [163.172.96.212]) by mta1.formilux.org (Postfix) with ESMTP id 060EEC0A43; Fri, 22 May 2026 11:39:28 +0200 (CEST) Date: Fri, 22 May 2026 11:39:27 +0200 From: Willy Tarreau To: Daniel Palmer Cc: linux@weissschuh.net, linux-kernel@vger.kernel.org Subject: Re: [PATCH] tools/nolibc: stackprotector: Avoid stalling program startup if crng is not init yet Message-ID: References: <20260522090726.726985-1-daniel@thingy.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260522090726.726985-1-daniel@thingy.jp> Hi Daniel! On Fri, May 22, 2026 at 06:07:26PM +0900, Daniel Palmer wrote: > We are using the getrandom syscall to get a random seed for the > stack protector canary but we are calling it with no flags which means > it'll block until there is some real randomness to return. > > This means that if the crng is not ready yet program startup will > block and if you are unlucky that could be for a long time and > look like the program has crashed. > > There is a comment in the code about mixing in the pid to make > sure the canary isn't 0 even if getrandom fails so it seems ok > to pass the non-blocking and insecure flags so it doesn't block > and potentially return something even if the crng is not init > yet. > > Fixes: 7188d4637e95 ("tools/nolibc: add support for stack protector") > Signed-off-by: Daniel Palmer Acked-by: Willy Tarreau > --- > > The insecure flag is apparently from 5.6, I think Willy said before > we are trying to keep nolibc working on the oldest LTS kernel. > That seems to be 5.10 so I think its ok? Sounds reasonable. We could also condition the flag to its existence if it causes issues. > Anyhow, I switched compilers for my nommu target and everything > stopped working, tracked it down to this. my other compiler must > have not supported the stack protector. Possible, indeed. Thanks! Willy > > tools/include/nolibc/stackprotector.h | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/tools/include/nolibc/stackprotector.h b/tools/include/nolibc/stackprotector.h > index e11c20c75465..916a92062ba0 100644 > --- a/tools/include/nolibc/stackprotector.h > +++ b/tools/include/nolibc/stackprotector.h > @@ -42,7 +42,8 @@ uintptr_t __stack_chk_guard; > > static __nolibc_no_stack_protector void __stack_chk_init(void) > { > - __nolibc_syscall3(__NR_getrandom, &__stack_chk_guard, sizeof(__stack_chk_guard), 0); > + __nolibc_syscall3(__NR_getrandom, &__stack_chk_guard, sizeof(__stack_chk_guard), > + GRND_INSECURE | GRND_NONBLOCK); > /* a bit more randomness in case getrandom() fails, ensure the guard is never 0 */ > if (__stack_chk_guard != (uintptr_t) &__stack_chk_guard) > __stack_chk_guard ^= (uintptr_t) &__stack_chk_guard; > -- > 2.53.0 >