From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 445923858CDA for ; Tue, 26 Jul 2022 09:55:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 445923858CDA 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-625-O0gK7D1XNvOgFWuF2-J-Fw-1; Tue, 26 Jul 2022 05:55:27 -0400 X-MC-Unique: O0gK7D1XNvOgFWuF2-J-Fw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A11203817A63; Tue, 26 Jul 2022 09:55:26 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.193.56]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1AA172166B26; Tue, 26 Jul 2022 09:55:24 +0000 (UTC) From: Florian Weimer To: "Jason A. Donenfeld" Cc: libc-alpha@sourceware.org, Adhemerval Zanella Netto , Cristian =?utf-8?Q?Rodr=C3=ADguez?= , Paul Eggert , linux-crypto@vger.kernel.org Subject: Re: [PATCH v2] arc4random: simplify design for better safety References: <20220725225728.824128-1-Jason@zx2c4.com> <20220725232810.843433-1-Jason@zx2c4.com> Date: Tue, 26 Jul 2022 11:55:23 +0200 In-Reply-To: <20220725232810.843433-1-Jason@zx2c4.com> (Jason A. Donenfeld's message of "Tue, 26 Jul 2022 01:28:10 +0200") Message-ID: <87k080i4fo.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Spam-Status: No, score=-5.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Jul 2022 09:55:35 -0000 * Jason A. Donenfeld: > + pfd.fd = TEMP_FAILURE_RETRY ( > + __open64_nocancel ("/dev/random", O_RDONLY | O_CLOEXEC | O_NOCTTY)); > + if (pfd.fd < 0) > + arc4random_getrandom_failure (); > + if (__poll (&pfd, 1, -1) < 0) > + arc4random_getrandom_failure (); > + if (__close_nocancel (pfd.fd) < 0) > + arc4random_getrandom_failure (); What happens if /dev/random is actually /dev/urandom? Will the poll call fail? I think we need a no-cancel variant of poll here, and we also need to handle EINTR gracefully. Performance-wise, my 1000 element shuffle benchmark runs about 14 times slower without userspace buffering. (For comparison, just removing ChaCha20 while keeping a 256-byte buffer makes it run roughly 25% slower than current master.) Our random() implementation is quite slow, so arc4random() as a replacement call is competitive. The unbuffered version, not so much. Running the benchmark, I see 40% of the time spent in chacha_permute in the kernel, that is really quite odd. Why doesn't the system call overhead dominate? Thanks, Florian