Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1802810pxb; Wed, 2 Feb 2022 12:52:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJzBFt7HY78lg6aipqKOBkmmQHkE0xC3BSQawYEAZhEFDRsMAfZIreh4EKEgpe0ZnKW/w3hI X-Received: by 2002:a17:903:2290:: with SMTP id b16mr32112888plh.103.1643835140112; Wed, 02 Feb 2022 12:52:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643835140; cv=none; d=google.com; s=arc-20160816; b=skpF2PQCiNEsTDzMcqVWivVfiP4BS3rbxNGnn7DI7EKzkDO69KIRL1RvDD40gjdB4F vhT8ngNC0zabX8s0YI52Nuk/rfUYQu5Xx3/lwaJi4slJ5kicr43i/YHOGCLb/xDuNjsj wPq4sMmZfH1e4w7u+x+yS66Fz4KIiZ8c28aGir2l7rrufEf/nVw+G9RqVfmudfzlaiB5 oBTLTpwQZ1SdIDUV8ur4HttzVX8FOiLq1oXUsNf81z2HKTccN7Bbsx1FOSfswEgaZXIM pIaMmfjkO2zTqa8XqxSpMRrKGYD6BsugQcrS4iS918Uz6zAcouJjwtZw1pn48YobHzZu b4UQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=pTZ3bVNwyGr0I6KCecwpk4q7omHPmVlpoXWo92UK+BQ=; b=SjRiTgJ5cJx74Ad+m8MvTFusuIdIIwgGNC/IyR1PON+a39l/1gQOULwVqjYVHtwUMA 6A4gSplRly8CWIfANkHsFaF/wbE6Uc4dDvMDJMgXMpkGAoG0S60fKNuG2qWE2YVKLtwR OyrlbAXCAhe9+IveKPKFXZJ2OBG96FCK7fRHAQ4/QGF1QWB8gNrCKyYQz8clWXyPW0gP fC3NQsaCpPWzQNAo/8JxNQx4r0H/p6LgQWD2CQDiISqkpR7YTp9lvQW0KAIh+mVtsqO5 eJ4p8ZI+ECYYah4FPddlyPGpvayzXZlqbdv0AcKxSBK5x+hc8wS6sW15If6/mhdlvvAS TQOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=VJDrPKs3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u12si22585987plf.562.2022.02.02.12.52.07; Wed, 02 Feb 2022 12:52:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=VJDrPKs3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S243030AbiBAX7m (ORCPT + 99 others); Tue, 1 Feb 2022 18:59:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241096AbiBAX7l (ORCPT ); Tue, 1 Feb 2022 18:59:41 -0500 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F121C061714 for ; Tue, 1 Feb 2022 15:59:41 -0800 (PST) Received: by mail-pf1-x42b.google.com with SMTP id n32so17282935pfv.11 for ; Tue, 01 Feb 2022 15:59:41 -0800 (PST) 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=pTZ3bVNwyGr0I6KCecwpk4q7omHPmVlpoXWo92UK+BQ=; b=VJDrPKs3JJ3JyjEdFMptkHnkiQgE8DFx0U7leGypaLH1eZ+CL/VQtlNrRhEWfDVc/+ 3hnv7eK4e3NE6E4JYLWfgXTRKU7XY9yzMcU4MTjp9RNhnsKEA0p0xG6qDbXVLdnhnmQc w/ik5Co1PH1C2oqQZokC4GeJf93llNRGLpBh4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=pTZ3bVNwyGr0I6KCecwpk4q7omHPmVlpoXWo92UK+BQ=; b=XTJ6IqVDH9AZEdTO137AXk6tFw4vGlavNRO2mkF0wLTJuDM8jTQF8eLTAsHmHs4M7q DVvQk+ZBUfH8M8b47q+SNfS2jUhLxX0w+R9HXhBAiBEjHuMGpH82NQQkyv26iURyMSp6 H4Rgur/LiaLckm6bcBci67QpR9ucN+68eA6BpBqlFNyM0PdRd0oQF35PnkjRQVFgK3Sg KJJPbDxSiBe7rznqyFhlL0yzVO7DL7kMP1l1njaCE6z5t7sTCWxsY/2+gyADn4epZL81 VAghrnqUA0slaUAY8FfsXGwFEkPezSqtak7lAdtM1C3pW07kqGEnZgzZGVAPS9c7P0lR K05A== X-Gm-Message-State: AOAM5318sALc4dOf6mQGKdeLrL/sEre3FcDBhXw4PetgaZZtn0hRzPmZ kPx6QwxqPBBilP0fwkoZBHQ4wA== X-Received: by 2002:a63:9149:: with SMTP id l70mr22479215pge.555.1643759980611; Tue, 01 Feb 2022 15:59:40 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id f12sm18007181pfj.37.2022.02.01.15.59.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Feb 2022 15:59:40 -0800 (PST) Date: Tue, 1 Feb 2022 15:59:39 -0800 From: Kees Cook To: Peter Zijlstra Cc: Linus Torvalds , Thomas Gleixner , Josh Poimboeuf , Linux Kernel Mailing List , the arch/x86 maintainers , Alexander Popov Subject: Re: Stackleak vs noinstr (Was: [GIT pull] objtool/core for v5.16-rc1) Message-ID: <202202011558.DAAF17D@keescook> References: <163572864256.3357115.931779940195622047.tglx@xen13> <163572864563.3357115.8793939214537874196.tglx@xen13> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 02, 2021 at 11:03:44AM +0100, Peter Zijlstra wrote: > On Tue, Nov 02, 2021 at 10:05:50AM +0100, Peter Zijlstra wrote: > > On Tue, Nov 02, 2021 at 09:00:36AM +0100, Peter Zijlstra wrote: > > > On Mon, Nov 01, 2021 at 01:44:39PM -0700, Linus Torvalds wrote: > > > > > > do_machine_check()+0x27: call to stackleak_track_stack ... > > > > do_syscall_64()+0x9: call to stackleak_track_stack ... > > > > do_int80_syscall_32()+0x9: call to stackleak_track_stack ... > > > > exc_general_protection()+0x22: call to stackleak_track_stack ... > > > > fixup_bad_iret()+0x20: call to stackleak_track_stack ... > > > > .entry.text+0x10e6: call to stackleak_erase ... > > > > .entry.text+0x143: call to stackleak_erase ... > > > > .entry.text+0x17d9: call to stackleak_erase ... > > > > > > > > most seem to be about the stackleak thing, > > > > > > Right, I recently ran into this and hacen't yet had time to look into > > > it. I suspect my normal build box doesn't have the GCC plugin crud > > > enabled or somesuch. > > > > > > I think the GCC stackleak plugin needs fixing, specifically it needs a > > > function attribute such that it will not emit instrumentation in noinstr > > > functions. I'll go chase down the developer of that thing. > > > > Alexander, is there any way to make this plugin grow a function > > attribute which we can add to noinstr ? There's a strict requirement the > > compiler doesn't add extra code to noinstr functions these days. > > > > We'll 'soon' be running noinstr C code before switching to kernel page > > tables even. > > Using my pre-release GCC-12 compiler (the only one I have with plugin > crud enabled apparently), the below seems to work. > > Having the plugin gate on section name seems a lot hacky, but given it's > already doing that, one more doesn't hurt. > > --- > diff --git a/kernel/stackleak.c b/kernel/stackleak.c > index ce161a8e8d97..135866ca8878 100644 > --- a/kernel/stackleak.c > +++ b/kernel/stackleak.c > @@ -48,7 +48,7 @@ int stack_erasing_sysctl(struct ctl_table *table, int write, > #define skip_erasing() false > #endif /* CONFIG_STACKLEAK_RUNTIME_DISABLE */ > > -asmlinkage void notrace stackleak_erase(void) > +asmlinkage noinstr void stackleak_erase(void) > { > /* It would be nice not to have 'kstack_ptr' and 'boundary' on stack */ > unsigned long kstack_ptr = current->lowest_stack; > @@ -102,7 +102,6 @@ asmlinkage void notrace stackleak_erase(void) > /* Reset the 'lowest_stack' value for the next syscall */ > current->lowest_stack = current_top_of_stack() - THREAD_SIZE/64; > } > -NOKPROBE_SYMBOL(stackleak_erase); > > void __used __no_caller_saved_registers notrace stackleak_track_stack(void) > { > diff --git a/scripts/gcc-plugins/stackleak_plugin.c b/scripts/gcc-plugins/stackleak_plugin.c > index e9db7dcb3e5f..07688a1c686b 100644 > --- a/scripts/gcc-plugins/stackleak_plugin.c > +++ b/scripts/gcc-plugins/stackleak_plugin.c > @@ -446,6 +446,8 @@ static bool stackleak_gate(void) > return false; > if (!strncmp(TREE_STRING_POINTER(section), ".meminit.text", 13)) > return false; > + if (!strncmp(TREE_STRING_POINTER(section), ".noinstr.text", 13)) > + return false; > } > > return track_frame_size >= 0; Did this ever turn into a real patch? I don't see anything in -next for it, so I assume it's still needed. -- Kees Cook