Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp909280yba; Fri, 26 Apr 2019 10:45:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqwQIUFI5pzNtC1HNpuhel6hsOckh/48XfCC0WHac8+4tQn+EiFrS4OGUx3uaEnCmIbsTRT3 X-Received: by 2002:a17:902:820c:: with SMTP id x12mr45913674pln.199.1556300730071; Fri, 26 Apr 2019 10:45:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556300730; cv=none; d=google.com; s=arc-20160816; b=zWGTVpHRhhUU5gA86X/7Jwv6i4P/gsVmmxSkqf/T0BkWWLm4wINx+Mx89kOprq/prA o2Z5r4VkxBXKawc45PyTSqukHC8wYPsxBrIiWS86oPf6OX0CIiArDV40ZNNa10ZdOmpw Lu/GloFuS3BoH4ahBl/523+PS3vd6X+RrYQAjaCpPs6x91V++QVc2v0GZ/opT4XFrtFQ /ypOvwvBQZNv3G1FLEvFt+zOK4bC3STBNePHhED4NO2sKimhNDwxyhhHSD658znWYk3M Rhe8VsgrwiiOchcE/HQB1Edeurx4khXXmC5uQxKn0lP7uog+5YkzFFn2+NwCZSRp2RoU ZFPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:to :from:date:dkim-signature; bh=HjGhszG3Wg5CLyR31sc4wM+C5CAO36/zIz1iB0Pa0bY=; b=EKbayNJGVAogMyZklKrNVE/JqrHXLd+VH7ZW5oe4bbaRAffVX9r5+IP8TuiBqudPXG eDULBsxDzQXx77Hbo0Hoos827UckVdUTV7VYgIx9dJA71vud/Kgk//IUNgcr5yQgi1rM QNN3K/3agE5WXLbEpeG3+bMp7OKBceTVbAtLsNMgXE1KSeh+tjcF8d5z//wCrpEx9I3e 1kiixNCqW8PMg06fpgNN81U1l9u54q9kK8xKZDFmq8xy7sf/knPYugvbP1KP1tq7m+gB r4v/gOgrTimwEMjB2jwQPIoodLEY/+Uq6NJsK2th0tKIIj9Ue8GVh9RhVFiwhjT7qgQC UCuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=f00dlNCw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o33si26351772plb.189.2019.04.26.10.45.14; Fri, 26 Apr 2019 10:45:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=f00dlNCw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726193AbfDZRoY (ORCPT + 99 others); Fri, 26 Apr 2019 13:44:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:58290 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726053AbfDZRoY (ORCPT ); Fri, 26 Apr 2019 13:44:24 -0400 Received: from sol.localdomain (c-24-5-143-220.hsd1.ca.comcast.net [24.5.143.220]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3F9582077B; Fri, 26 Apr 2019 17:44:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556300662; bh=f/og59YkYC9ApZwrq1CuOoaeZXfjmj4D8LdPICM0l0g=; h=Date:From:To:Subject:References:In-Reply-To:From; b=f00dlNCwhDELLIrmHlCPV6JItu/FK9OR9/Y22oUmiiACSEVaZTUbn38SMhl3QuhJf Q/Yfa/o+PSBq60FcuzQ4SXgZxTbMVkrKaR+bbfAVb92cbH083Va/f4QNy3Qe62fCsS 4MSHxFGWkxbP2RNoulgHwd8ogVIDf12LbmXkGI5A= Date: Fri, 26 Apr 2019 10:44:20 -0700 From: Eric Biggers To: Theodore Ts'o , "Reshetova, Elena" , "herbert@gondor.apana.org.au" , David Laight , Ingo Molnar , 'Peter Zijlstra' , "keescook@chromium.org" , Daniel Borkmann , "luto@kernel.org" , "luto@amacapital.net" , "linux-kernel@vger.kernel.org" , "jpoimboe@redhat.com" , "jannh@google.com" , "Perla, Enrico" , "mingo@redhat.com" , "bp@alien8.de" , "tglx@linutronix.de" , "gregkh@linuxfoundation.org" , "Edgecombe, Rick P" Subject: Re: [PATCH] x86/entry/64: randomize kernel stack offset upon syscall Message-ID: <20190426174419.GB691@sol.localdomain> References: <20190416120822.GV11158@hirez.programming.kicks-ass.net> <01914abbfc1a4053897d8d87a63e3411@AcuMS.aculab.com> <20190416154348.GB3004@mit.edu> <2236FBA76BA1254E88B949DDB74E612BA4C52338@IRSMSX102.ger.corp.intel.com> <9cf586757eb44f2c8f167abf078da921@AcuMS.aculab.com> <20190417151555.GG4686@mit.edu> <99e045427125403ba2b90c2707d74e02@AcuMS.aculab.com> <2236FBA76BA1254E88B949DDB74E612BA4C5E473@IRSMSX102.ger.corp.intel.com> <2236FBA76BA1254E88B949DDB74E612BA4C63E24@IRSMSX102.ger.corp.intel.com> <20190426140102.GA4922@mit.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190426140102.GA4922@mit.edu> User-Agent: Mutt/1.11.4 (2019-03-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Apr 26, 2019 at 10:01:02AM -0400, Theodore Ts'o wrote: > On Fri, Apr 26, 2019 at 11:33:09AM +0000, Reshetova, Elena wrote: > > Adding Eric and Herbert to continue discussion for the chacha part. > > So, as a short summary I am trying to find out a fast (fast enough to be used per syscall > > invocation) source of random bits with good enough security properties. > > I started to look into chacha kernel implementation and while it seems that it is designed to > > work with any number of rounds, it does not expose less than 12 rounds primitive. > > I guess this is done for security sake, since 12 is probably the lowest bound we want people > > to use for the purpose of encryption/decryption, but if we are to build an efficient RNG, > > chacha8 probably is a good tradeoff between security and speed. > > > > What are people's opinions/perceptions on this? Has it been considered before to create a > > kernel RNG based on chacha? > > Well, sure. The get_random_bytes() kernel interface and the > getrandom(2) system call uses a CRNG based on chacha20. See > extract_crng() and crng_reseed() in drivers/char/random.c. > > It *is* possible to use an arbitrary number of rounds if you use the > low level interface exposed as chacha_block(), which is an > EXPORT_SYMBOL interface so even modules can use it. "Does not expose > less than 12 rounds" applies only if you are using the high-level > crypto interface. chacha_block() actually WARNs if the round count isn't 12 or 20, because I didn't want people to sneak in uses of other variants without discussion :-) (Possibly I should have made chacha_block() 'static' and only exported chacha12_block() and chacha20_block(). But the 'nrounds' parameter is convenient for crypto/chacha_generic.c.) > > We have used cut down crypto algorithms for performance critical > applications before; at one point, we were using a cut down MD4(!) for > initial TCP sequence number generation. But that was getting rekeyed > every five minutes, and the goal was to make it just hard enough that > there were other easier ways of DOS attacking a server. > > I'm not a cryptographer, so I'd really us to hear from multiple > experts about the security level of, say, ChaCha8 so we understand > exactly kind of security we'd offering. And I'd want that interface > to be named so that it's clear it's only intended for a very specific > use case, since it will be tempting for other kernel developers to use > it in other contexts, with undue consideration. > > - Ted The best attack on ChaCha is against 7 rounds and has time complexity 2^235. So while there's no publicly known attack on ChaCha8, its security margin is too small for it to be recommended for typical cryptographic use. I wouldn't be suprised to see an attack published on ChaCha8 in the not-too-distant future. (*Probably* not a practical one, but the crypto will be technically "broken" regardless.) I don't think it's completely out of the question for this specific use case, since apparently you only need random numbers that are used temporarily for runtime memory layout. Thus the algorithm can be upgraded at any time without spending decades deprecating it from network protocols and on-disk formats. But if you actually need cryptographically secure random numbers, it would be much better to start with something with a higher security margin like ChaCha20, optimizing it, and only going lower if you actually need to. Would it be possibly to call ChaCha20 through the actual crypto API so that SIMD instructions (e.g. AVX-2) could be used? That would make it *much* faster. Also consider AES-CTR with AES-NI instructions. - Eric