Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp2259546rdb; Wed, 21 Feb 2024 01:56:33 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX0rpqIp/CKA6RbeBEIss440goX3oVfJ7xyppkwjtlP+HBrFGXhk/D6nLILMdP9YqR6ZYB9UzNwOn5OpvVhPjeq58hKJzq6V9Ku+09irQ== X-Google-Smtp-Source: AGHT+IHruXOdZkFhpqd4J+7zg4QnsXfqI+zkQeKc8uoNKMqMLsN0oJOwVE8GG5TwH+hPbFIFm33+ X-Received: by 2002:a17:906:d78b:b0:a3e:bd4e:c87e with SMTP id pj11-20020a170906d78b00b00a3ebd4ec87emr6740555ejb.36.1708509393562; Wed, 21 Feb 2024 01:56:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708509393; cv=pass; d=google.com; s=arc-20160816; b=Q0LKn/jnTaTvZe9+ODTcFxPDfqg4uZcrdlmGHopSUjYpFtLo4nr3ppEV4qmt5FSab8 yV/q4fIQTm95Vfhv0JneXXnaSl/cb1gg5BUcKF9OigCLkuCj7ZwrCmlQGYGQi664wKu/ fZiGcPWbI99F0kPIuI3B/9oSOtF6CfCIDc1ewUs/elCnf+S1/VpYFmqbiQ1MGZnXhOWl bqcfNbe8nxWyohogHXsaBVf2pNVeUi6PGPw0mdeLLAqQw0nCLGOZ9dBOjhehuQFfKvh9 1lRdKs8zg9n2CRN5svvItrk+KJsD+G5TsmnJBRfNaApQnbMjuXzqq/FhnjykrddALEvh X2rA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=subject:cc:to:from:date:references:in-reply-to:message-id :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:feedback-id:dkim-signature:dkim-signature; bh=Fw9lSJoYftih2HH5DSoXI7rUStJLYAI4RgfN/FK3Rx8=; fh=Njwj/3X1Aj0H0ONH+Tij91XDkc4pItenia0Hbn/Ske0=; b=ymhWJmDVd6mAk9RdI1wCQjmlJy2KpcPkFgplOBrn25MD86eRS2DDtoLgD+ltQgRuir Tx+TSHxpNnkYSFRH4m/aaBJA46i6Jo+3E33PH+7U9mw9cmk1XU9+/joQ7T7z2fvZPCxX dfkUsaGUrxONkI/nFj813166OQRqXMAnzSwz3WFzvTA9NeOFX8A8/37ed9I7Qgl7ms/W YVA86NwtSfWpY8Qx7jvl8NlpzQgK71MvbiNrKQIfDDisNKw8AsdD65MLbbN0Eosfh3Gz 7SeLPtgs8uQFfUrpyroYGbtHW+P0yrKyTJmJfILP3rMiQXcG4tDLgQPEEj1RtD+PA1gw aT2g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@arndb.de header.s=fm3 header.b=2gNEAT4p; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=Y+jJlUhw; arc=pass (i=1 spf=pass spfdomain=arndb.de dkim=pass dkdomain=arndb.de dkim=pass dkdomain=messagingengine.com dmarc=pass fromdomain=arndb.de); spf=pass (google.com: domain of linux-kernel+bounces-74438-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74438-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=arndb.de Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id w24-20020a170906b19800b00a3efdb61714si1383962ejy.767.2024.02.21.01.56.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 01:56:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-74438-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@arndb.de header.s=fm3 header.b=2gNEAT4p; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=Y+jJlUhw; arc=pass (i=1 spf=pass spfdomain=arndb.de dkim=pass dkdomain=arndb.de dkim=pass dkdomain=messagingengine.com dmarc=pass fromdomain=arndb.de); spf=pass (google.com: domain of linux-kernel+bounces-74438-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74438-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=arndb.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id D80A51F28000 for ; Wed, 21 Feb 2024 09:48:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 049253D3B1; Wed, 21 Feb 2024 09:48:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=arndb.de header.i=@arndb.de header.b="2gNEAT4p"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Y+jJlUhw" Received: from wout3-smtp.messagingengine.com (wout3-smtp.messagingengine.com [64.147.123.19]) (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 867533B781; Wed, 21 Feb 2024 09:48:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.19 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708508919; cv=none; b=sh8caVVozQPmhJM+J9WPNtQZWGoho5ulofqYOxSKpaoPeKNsDqJ6RDYkuIl/eTq8pXRH9gyaycRBfWKkUIQETTG9FWAY60iAeISjaxILbk8Nt+CZo0MAuVbX3mDrfVONM7+xsrYzepqHg0K3iTO7u4PUoMMQJ30MsCuQuDqOK0Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708508919; c=relaxed/simple; bh=HLE/MP1SWWxlDamRNgvoEaBeblwna1EiTKCiw4WhSCk=; h=MIME-Version:Message-Id:In-Reply-To:References:Date:From:To:Cc: Subject:Content-Type; b=qlQVm70MABritlQ+1hPoW+/GoZ4whfytwiisEdxksZp9vVn4rH/PmraoFfa01biAJpfPjE1CZdWG/KrYqJvKpo635wEF01hgIpxe6PeBccXcaiuitTh8HTs+3w/gvMzRpTif4YLf3tWFx1xw0PQFfI8PM8078SfVfuZrCkKHu4M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arndb.de; spf=pass smtp.mailfrom=arndb.de; dkim=pass (2048-bit key) header.d=arndb.de header.i=@arndb.de header.b=2gNEAT4p; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Y+jJlUhw; arc=none smtp.client-ip=64.147.123.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arndb.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arndb.de Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 2719432001AB; Wed, 21 Feb 2024 04:48:35 -0500 (EST) Received: from imap51 ([10.202.2.101]) by compute5.internal (MEProxy); Wed, 21 Feb 2024 04:48:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arndb.de; h=cc :cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1708508914; x=1708595314; bh=Fw9lSJoYft ih2HH5DSoXI7rUStJLYAI4RgfN/FK3Rx8=; b=2gNEAT4pin6JGIAnt8bwDF8i/y dxEN6bb4iHtQoqbP3lVzUxytZUW00tT3+JjWU4qg5fqI1guNgjRy68mUGWNgV+C1 1xsIejWLV5OQjEbNMzcU9ggp2RXzud15v35SiCS5UfBcpIi54yCe5dWmJzkIL9rL a85RIpRD6ZPv8sumhAKtm/SjOdRGS9qDJHCplrWv0KxQtQxIHRBgoh8JkG3gGMlF l3rZp8xOBpMN514u8tm8+XqwkMeHYVD6/TiJ1fIT+4bMBiVJBFg4ubv0kBt9unFi zyiKRdecuT7mGCXTG+ndxo47a1cBssKpv2IL+4/fXQ3YbJUnlv4N3DXldFPg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1708508914; x=1708595314; bh=Fw9lSJoYftih2HH5DSoXI7rUStJL YAI4RgfN/FK3Rx8=; b=Y+jJlUhwn2Xxw5axMqBCkm6M4C2Y/yBLWAoNSy1RShLI rH+TmCdFjkJZdQGKN3t5GMVXjg2YsNhOTxq/QE5OClC0Q78aNRlYT9fitKY4qjNh 7HdM9Zsn5R8FHlfPhM51nE3duHAaqeQFDsewCNZKoTC0jIqwE2OMZkzuso39OsBc HX7mT5kCvkWZWLq2vqUV6m7nhKZ5rNn/vDmB4snjDXQTD2/m1kvDgPB9cLTx86YH zMWH0YCJjC1c+Nmmcu67f7jfPAPR8fIakBOo40agc+LrYMynVH4lTuFuW3ZVIHJU 8db1OhMLygnZ7OzdKAjFPmg24CGKNskQTeZiovWsPA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrfedvgddtkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvvefutgesthdtredtreertdenucfhrhhomhepfdetrhhn ugcuuegvrhhgmhgrnhhnfdcuoegrrhhnugesrghrnhgusgdruggvqeenucggtffrrghtth gvrhhnpeffheeugeetiefhgeethfejgfdtuefggeejleehjeeutefhfeeggefhkedtkeet ffenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrrh hnugesrghrnhgusgdruggv X-ME-Proxy: Feedback-ID: i56a14606:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 29F20B6008D; Wed, 21 Feb 2024 04:48:34 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-153-g7e3bb84806-fm-20240215.007-g7e3bb848 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <938f3418-fd88-476d-b67f-3f7ada98e444@app.fastmail.com> In-Reply-To: <20240221020258.1210148-1-jeremy.linton@arm.com> References: <20240221020258.1210148-1-jeremy.linton@arm.com> Date: Wed, 21 Feb 2024 10:48:12 +0100 From: "Arnd Bergmann" To: "Jeremy Linton" , linux-arm-kernel@lists.infradead.org Cc: "Catalin Marinas" , "Will Deacon" , "Kees Cook" , "Gustavo A. R. Silva" , "Mark Rutland" , "Steven Rostedt" , "Mark Brown" , "Guo Hui" , Manoj.Iyer@arm.com, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, "James Yang" , "Shiyou Huang" Subject: Re: [RFC] arm64: syscall: Direct PRNG kstack randomization Content-Type: text/plain On Wed, Feb 21, 2024, at 03:02, Jeremy Linton wrote: > The existing arm64 stack randomization uses the kernel rng to acquire > 5 bits of address space randomization. This is problematic because it > creates non determinism in the syscall path when the rng needs to be > generated or reseeded. This shows up as large tail latencies in some > benchmarks and directly affects the minimum RT latencies as seen by > cyclictest. Hi Jeremy, I think from your description it's clear that reseeding the rng is a problem for predictable RT latencies, but at the same time we have too many things going on to fix this by special-casing kstack randomization on one architecture: - if reseeding latency is a problem, can we be sure that none of the other ~500 files containing a call to get_random_{bytes,long,u8,u16,u32,u64} are in an equally critical path for RT? Maybe those are just harder to hit? - CONFIG_RANDOMIZE_KSTACK_OFFSET can already be disabled at compile or at at boot time to avoid the overhead entirely, which may be the right thing to do for users that care more deeply about syscall latencies than the fairly weak stack randomization. Most architectures don't implement it at all. - It looks like the unpredictable latency from reseeding started with f5b98461cb81 ("random: use chacha20 for get_random_int/long"), which was intended to make get_random() faster and better, but it could be seen as regression for real-time latency guarantees. If this turns out to be a general problem for RT workloads, the answer might be to bring back an option to make get_random() have predictable overhead everywhere rather than special-casing the stack randomization. > Other architectures are using timers/cycle counters for this function, > which is sketchy from a randomization perspective because it should be > possible to estimate this value from knowledge of the syscall return > time, and from reading the current value of the timer/counters. > > So, a poor rng should be better than the cycle counter if it is hard > to extract the stack offsets sufficiently to be able to detect the > PRNG's period. I'm not convinced by the argument that the implementation you have here is less predictable than the cycle counter, but I have not done any particular research here and would rely on others to take a closer look. The 32 bit global state variable does appear weak, and I know that OTOH if we can show that a particular implementation is in fact better than a cycle counter, I strongly think we should use the same one across all architectures that currently use the cycle counter. Arnd