From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 48197271454 for ; Tue, 18 Nov 2025 11:05:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763463931; cv=none; b=Fh+QdwJrgQpuq3PIW0WoWQ8YSv3etqDiNDg2ExExbO4oMlMfIMdVIygzzcqDXk4oLekFECgL0Y+/86PajFz3woTLBqczU9EuU1kXRSOAIMXONs2BpkOI17LzCv7QYGftkZ9ufUk6CyhBmiyP1VS2h/atboFH3TP6s6K1aLqLmh4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763463931; c=relaxed/simple; bh=0VK4AarKX+J58fO+BMqFR0iB/hnB+Chm081IhZhWdeA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=nGxICT+HTVcmlrDUabtu6mOfKTDg/hgjGGsDxxAa1SC5uvGjfVdxUR4Vg35RW2re3jaOPkZDksdEOcBak1PCxD4j/NLQn0zympZFmXZPVN7kPMxlte+fHX1rGThZUsRCTVp46Kid4cZwShRsrGojY4WEW+fEDed4+nRk+lPiXBc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 140D5FEC; Tue, 18 Nov 2025 03:05:21 -0800 (PST) Received: from J2N7QTR9R3 (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 548B23F66E; Tue, 18 Nov 2025 03:05:27 -0800 (PST) Date: Tue, 18 Nov 2025 11:05:21 +0000 From: Mark Rutland To: Kees Cook Cc: Ryan Roberts , Arnd Bergmann , Ard Biesheuvel , Jeremy Linton , Will Deacon , Catalin Marinas , "linux-arm-kernel@lists.infradead.org" , Linux Kernel Mailing List Subject: Re: [DISCUSSION] kstack offset randomization: bugs and performance Message-ID: References: <66c4e2a0-c7fb-46c2-acce-8a040a71cd8e@arm.com> <202511171221.517FC4F@keescook> 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: <202511171221.517FC4F@keescook> On Mon, Nov 17, 2025 at 12:27:36PM -0800, Kees Cook wrote: > On Mon, Nov 17, 2025 at 11:31:22AM +0000, Ryan Roberts wrote: > > On 17/11/2025 11:30, Ryan Roberts wrote: > > > I think we could just pass the random seed to add_random_kstack_offset() so that > > > we consume the old and buffer the new atomically? We would still buffer it > > > across syscalls to avoid the guessability issue that's documented. Then > > > choose_random_kstack_offset() could be removed. Or we could store > > > per-task_struct given it is only 32-bits? > > I had wanted to avoid both growing task_struct and to avoid tying the > randomness to a given task -- then unpredictability could be higher > (barring the bug above), and could be only reduced to per-thread by > pinning a thread exclusively to a single CPU. I appreciate the rationale of not growing task struct, but I think the "unpredictability could be higher" rationale doesn't hold any water. If an adversary has userspace code execution, they can pin the thread to a CPU. Regardless of whether they have that capability, in common cases the thread isn't going to migrate for a number of syscalls if those are non-blocking. The unpredictability gained by CPU migrations is slim to none. >From a thread model perspective, we need this to be unpredictable *regardless* of any pinning. >From a quick look at task struct, it appears that (on 64-bit platforms) there are several opportunities for rearranging fields to pack things together and save bytes. I think that if the state is sufficiently small, we don't actually have to grow task struct. Practically speaking, if this is small enough no-one will notice. > > > Bug 2: add_random_kstack_offset() and choose_random_kstack_offset() both > > > document their requirement to be called with interrupts and preemption disabled. > > > They use raw_cpu_*(), which require this. But on arm64, they are called from > > > invoke_syscall(), where interrupts and preemption are _enabled_. In practice, I > > > don't think this will cause functional harm for arm64's implementations of > > > raw_cpu_*(), but means that it's possible that the wrong per-cpu structure is > > > being referred to. Perhaps there is a way for user code to exploit this to > > > defeat the purpose of the feature. > > > > > > This should be straightforward to fix; if we take the task_struct approach for > > > bug 1, then that would also fix this issue too because the requirement to be in > > > atomic context goes away. Otherwsise it can be moved earlier in the callchain, > > > before interrupts are enabled. > > I can't speak to these internals, just that I'd hope to avoid forcing > the randomness down to the thread-level. >From my perspective this would be *much* nicer as a per-thread property, since it wouldn't have any problematic interactions with preemption, and wouldn't force awkward requirements on architecture code. i.e. I completely disagree -- I think this would be much better per thread. Using siphash per thread sounds fine to me. Mark.