Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4212385yba; Sun, 12 May 2019 07:34:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqz25J7mV80zueabOsqscUemZk0ptFvzN7c74LkOUXbcWWTywkEhvpjkZ3qeg8YisSnzzGCe X-Received: by 2002:a62:e501:: with SMTP id n1mr6013747pff.17.1557671675261; Sun, 12 May 2019 07:34:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557671675; cv=none; d=google.com; s=arc-20160816; b=UBn2w2K+66ZlGwnTOxCTgzZ3EhKBN7ZI+t4vV8qM0FKo86F6/O1LrgR2IJAcd5vPlY hfUUG7PzLFtpWWuWp86JG9dkhMTXmyHOLUe177cnu49zDSjGqh1fF3nE3CRRyBXB26YO UBA5F+s19lt5iTXK6WjMQOxaP92VRqFrQfakMORJm7gq9HEo4pOiI4qlsPVClViMGYHY Shaas+a82xX7Eh5iDHYpcJD4FnuSYhTYbZpK+cytjf7aE2tDgxDk3l2engc8H0qvxhRG mQ5KqGHVWs788WePcpM+ja/UIUNfakIOwoq2cpKaAc4bgphw0FehM2LAhzIvtW/XBG1q O8Iw== 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 :dkim-signature; bh=4lzMzXcIlsMyvnIM+cP+rdR98k+/37nVWWDJQ9nyZiU=; b=jbvZ8L9gF17BD5Pvf1LnMQ8IekBbJaezXPIth8gevmxIsb50danIG3TyM/JQxFNxcw eEYgBdJqA8M1d21RQ93u4b5aLyn+iy4k9aL7lfxuCMO1L6ZN7ePBNLlwVoFagYvr+g+r +9kCDl9HZ7T0QqOO7x11Fs/ZHiAJR4muKY1aWH6sqioeL4lExHXXovRwOdwgpC9zv+N9 Z3Ud9TuWGbmjcIQQ9nZZ4IjeP/c3/xqtElgGh20BPtGcr16tfFDAeJyExV1+Tpw5h+/j 8HfDAM6eNvzWGguZJXcllQAzp3YVkBGuWtqcAW+2aZAWHZ38tm6wz1JgiHIvXKXvQ3iu TCmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="QY/1IxGG"; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r15si2538345pgi.16.2019.05.12.07.34.18; Sun, 12 May 2019 07:34:35 -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=@chromium.org header.s=google header.b="QY/1IxGG"; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726769AbfELOdO (ORCPT + 99 others); Sun, 12 May 2019 10:33:14 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:45579 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726442AbfELOdO (ORCPT ); Sun, 12 May 2019 10:33:14 -0400 Received: by mail-pf1-f194.google.com with SMTP id s11so5729258pfm.12 for ; Sun, 12 May 2019 07:33:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=4lzMzXcIlsMyvnIM+cP+rdR98k+/37nVWWDJQ9nyZiU=; b=QY/1IxGGWk2J9aunJr+Apbe78b1IgbER4zCNvy7hNHL+Y3KZHfAhUKS4jI+TjEKMwA zSM2u2WZQKjM623dDZC3JfKcgTb9/hwU8+mxzPgrpIIDWjQod30+vXa8JL/Lp3yqdT/Y CBmFjjImooUcH0KbM9Ki/mQAgmfwnUAwzpDP4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=4lzMzXcIlsMyvnIM+cP+rdR98k+/37nVWWDJQ9nyZiU=; b=DG0H48+rEkQw+adivKPFNKxX9KyRGwSaG4PWPeaBOmzKnogEUfw+3Zte1Z7gEoQ18k DKjUUb0+tjunj/EtWuLwN7qFVttSC01+Ug/Dx67nMl3gGTMltbbz43ujFpM/5U9hy7Ky InENgLEXA5uOXT/gZyZF1dsfoaWsd/ICSNuifSITVweGlUsRSdfrjOYH0vcaAYG58yX5 aVMsBol0tMcrcbQtbY413Y87oRPQwc+u6LVU/uVz0T1038JRAU6ctDEbllb9Q2xBAbxt UQGc+A/xZKajGuNNV/jmWc4cgBEPL2KZ/LRKodIAe1++mTHuvLJ836W1OXGShBp7/a1P 3Wfw== X-Gm-Message-State: APjAAAWDoIVK36/V/8zIZpxM5srvu0pUH7Q+Tn2ud50Mr/jm7A1ynFqH 1yiE0qUJcwEQhJUAKoPkIVJQAA== X-Received: by 2002:a63:6ac1:: with SMTP id f184mr26503055pgc.25.1557671593324; Sun, 12 May 2019 07:33:13 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id r74sm18981716pfa.71.2019.05.12.07.33.12 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 12 May 2019 07:33:12 -0700 (PDT) Date: Sun, 12 May 2019 07:33:11 -0700 From: Kees Cook To: Ingo Molnar Cc: Andy Lutomirski , "Reshetova, Elena" , David Laight , Theodore Ts'o , Eric Biggers , "ebiggers@google.com" , "herbert@gondor.apana.org.au" , Peter Zijlstra , Daniel Borkmann , "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" , Linus Torvalds , Peter Zijlstra Subject: Re: [PATCH] x86/entry/64: randomize kernel stack offset upon syscall Message-ID: <201905120705.4F27DF3244@keescook> References: <2236FBA76BA1254E88B949DDB74E612BA4C760A7@IRSMSX102.ger.corp.intel.com> <20190508113239.GA33324@gmail.com> <2236FBA76BA1254E88B949DDB74E612BA4C762F7@IRSMSX102.ger.corp.intel.com> <20190509055915.GA58462@gmail.com> <2236FBA76BA1254E88B949DDB74E612BA4C7741F@IRSMSX102.ger.corp.intel.com> <20190509084352.GA96236@gmail.com> <201905111703.5998DF5F@keescook> <20190512080245.GA7827@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190512080245.GA7827@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, May 12, 2019 at 10:02:45AM +0200, Ingo Molnar wrote: > * Kees Cook wrote: > > I still think just using something very simply like rdtsc would be good > > enough. > > > > This isn't meant to be a perfect defense: it's meant to disrupt the > > ability to trivially predict (usually another thread's) stack offset. > > But aren't most local kernel exploit attacks against the current task? > Are there any statistics about this? I don't think I have any meaningful statistics on this any more. As mentioned ealier, virtually all the known stack-based attack methods have been mitigated: - stack canaries: no linear buffer overflows - thread_info moved: no more addr_limit games - VMAP_STACK (i.e. guard page): no more linear overflows/exhaustion overwriting neighboring memory - no VLAs: no more index overflows of stack arrays - stack variable initialization: vastly reduced chance of memory exposures or use of "uninitialized" variables One thing we don't have is a shadow call stack. i.e. the return addresses are still mixed in with local variables, argument spills, etc. This is still a potential target for attack, as ROP would need to get at the return addresses. (Though creating a shadow stack just moves the problem, but in theory to a place where there would be better control over it.) As for current vs not, yes, many past exploits have been against the current thread, though it's always been via the various low-hanging fruit we've hopefully eliminated now. What I think remains interesting are the attacks where there is some level of "spraying". It seems like this happens more as mitigations land. For example, while trying to overwrite a close() function pointer and an attacker can't target a specific heap allocation, they make lots of sockets, and just close them all after blindly poking memory. Similar things have been seen for thread-based attacks (though that predated VMAP_STACK). So, right now this mitigation remains a "what are we able to do to disrupt the reliability of an attack that is targetting the stack?" without a specific threat model in mind. I don't want the answer to be "we do nothing because we can't find a way to perfectly construct entropy that resists one threat model of many possible threats." > > And any sufficiently well-positioned local attacker can defeat this no > > matter what the entropy source, given how small the number of bits > > actually ends up being, assuming they can just keep launching whatever > > they're trying to attack. (They can just hold still and try the same > > offset until the randomness aligns: but that comes back to us also > > needing a brute-force exec deterance, which is a separate subject...) > > > > The entropy source bikeshedding doesn't seem helpful given how few bits > > we're dealing with. > > The low number of bits is still useful in terms of increasing the > probability of crashing the system if the attacker cannot guess the stack > offset. Right, we have the benefit of many attacks in the kernel being fragile, but it's possible that it may only wreck the thread and not take out the kernel itself. (Or the attack is depending on some kind of stack information exposure, not a write.) > With 5 bits there's a ~96.9% chance of crashing the system in an attempt, > the exploit cannot be used for a range of attacks, including spear > attacks and fast-spreading worms, right? A crashed and inaccessible > system also increases the odds of leaving around unfinished attack code > and leaking a zero-day attack. Yup, which is why I'd like to have _something_ here without us getting lost in the "perfect entropy" weeds. :) -- Kees Cook