Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3569622ybb; Tue, 31 Mar 2020 07:50:29 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvI1QTozfAgujHiMBIrKOvdWZ/39DTVjSZ9Lx9ANk4gO2LAj2G6OQYEW5JOXaBK3X9s1ERx X-Received: by 2002:a9d:5e9:: with SMTP id 96mr13240180otd.307.1585666229673; Tue, 31 Mar 2020 07:50:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585666229; cv=none; d=google.com; s=arc-20160816; b=vPTpBK4NMkFTJBKmFcW9+K/SGlwwa+X1iAErQKuP7bFC3CUzvGQc+Mnl4AHpTwvJoj RDXJEBPhXnbaIYmFNhnLPYU1kV3kGKtj3wBPnQj9ZMpK7WSpYHF9q5btRewGLmzqL5xl 1F7X9gyDIIhIm8b9DsVmq3PjEzDcz0ewU1/ccdal159YghdglGBGvUQrUf/HgU/oCUAO 6nxu45BLQh6gZOlKp9TamoAQU2yjamos7iRAbN24BoZEhVVapBLzNM/sAL+Vj1L9jZz8 8aPInttiprzpk8xNzxIukXZkLnBxZM0TSxgkZES6h2w5PukMFDyitRrplRibmpHcvsBE ZcFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=jIyjvWD0oZEzo4xCEedu4Z+6hX5HqofKUKUwriiXxpM=; b=N5ezkZZrVFq+4Pko8tpGLEVh0EFrW1lr+p4x1DF5hAkZbNPUsRmIkQDfE10VU7aohd uJL3kxpaF0+b4b0D+OOxUz5wEqnwODQ4yltO6ZvJpsqQ6bRmXQvUKSnbJhdXXjt0XfuI KpCXcEpWu2ceAkiuGoYWVMrnrp3yLbSnM5/r5AYXJKYZMuZ3TLUvv4ML2Cl4p7W/F1wL mLn4RFALV2K9Nuil/mEJNJroKzdKim8gz6EIGg7DmBeyVNwuxWIP4YXb0Rxu6B0t2O3Z CHZhhlQYdwlZa+ROITCXfJcR02ViIvZ/YpJc2arNgE/6M7fqOEcgYBk3QT4hh9YePrZ8 gBhQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u28si8597104otg.14.2020.03.31.07.50.17; Tue, 31 Mar 2020 07:50:29 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730589AbgCaOuB (ORCPT + 99 others); Tue, 31 Mar 2020 10:50:01 -0400 Received: from mx.sdf.org ([205.166.94.20]:53379 "EHLO mx.sdf.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726595AbgCaOuB (ORCPT ); Tue, 31 Mar 2020 10:50:01 -0400 Received: from sdf.org (IDENT:lkml@sdf.lonestar.org [205.166.94.16]) by mx.sdf.org (8.15.2/8.14.5) with ESMTPS id 02VEnFEj010261 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits) verified NO); Tue, 31 Mar 2020 14:49:16 GMT Received: (from lkml@localhost) by sdf.org (8.15.2/8.12.8/Submit) id 02VEnFfb002103; Tue, 31 Mar 2020 14:49:15 GMT Date: Tue, 31 Mar 2020 14:49:15 +0000 From: George Spelvin To: Mark Rutland Cc: linux-kernel@vger.kernel.org, Catalin Marinas , Will Deacon , linux-arm-kernel@lists.infradead.org, lkml@sdf.org Subject: Re: [RFC PATCH v1 44/50] arm64: ptr auth: Use get_random_u64 instead of _bytes Message-ID: <20200331144915.GA4303@SDF.ORG> References: <202003281643.02SGhOi3016886@sdf.org> <20200330105745.GA1309@C02TD0UTHF1T.local> <20200330193237.GC9199@SDF.ORG> <20200331101412.GA1490@C02TD0UTHF1T.local> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200331101412.GA1490@C02TD0UTHF1T.local> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 31, 2020 at 11:14:12AM +0100, Mark Rutland wrote: > On Mon, Mar 30, 2020 at 07:32:37PM +0000, George Spelvin wrote: >> On Mon, Mar 30, 2020 at 11:57:45AM +0100, Mark Rutland wrote: >>> As I am unaware, how does the cost of get_random_bytes() compare to the >>> cost of get_random_u64()? >> >> It's approximately 8 times the cost. [Of *one* get_random_u64() >> call; 4x the cost of the two needed to generate a 128-bit key.] >> >> Because get_random_bytes() implements anti-backtracking, it's a minimum >> of one global lock and one ChaCha20 operation per call. Even though >> chacha_block_generic() returns 64 bytes, for anti-backtracking we use >> 32 of them to generate a new key and discard the remainder. >> >> get_random_u64() uses the exact same generator, but amortizes the cost by >> storing the output in a per-CPU buffer which it only has to refill every >> 64 bytes generated. 7/8 of the time, it's just a fetch from a per-CPU >> data structure. > > I see; thanks for this explanation. It would be helpful to mention the > backtracking distinction explicitly in the commit message, since it > currently only alludes to it in the first sentence. Easily done, but I need to find a centralized place to say it, or I'd be repeating myself a *lot* in the series. That said, thanks for prompting me to quantify the cost ratio. I knew it, but never actually wrote it down. > It's worth noting that the key values *can* be exposed to userspace when > CONFIG_CHECKPOINT_RESTORE is selected. On such kernels, a user could > regenerate and read the keys an arbitrary number of times on a CPU of > their choice. From my limited understanding I presume backtracking may > be a concern there? No. Backtracking is an issue if the keys must remain secret *after* they are wiped from kernel memory. This applies to session *encryption* keys (assuming the plaintext should remain secret after the session is over), and to any long-lived keys which are stored encrypted or otherwise inaccessible (e.g. in dedicated hardware). The latter includes most asymmetric private keys. Since the pointer authentication keys are authentication keys, and valueless to an attacker once the kernel is done using them, there is no need for backtracking protetion. Basically, do you need to wipe the key (with memzero_explicit) when you are done with it? If that is important, you also want to know that the key cannot be reconstructed from the CRNG state. >> Yes, I went overboard, and your proposed change below is perfectly >> fine with me. > > Great. That's what I'd prefer due to clarity of the code, and I'm not > too concerned by the figures below given it only adds 12 bytes to the > contemporary text size. A modified patch will follow. Thanks for your patience.