From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 12558C83029 for ; Thu, 2 Sep 2021 17:35:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E75C3610E5 for ; Thu, 2 Sep 2021 17:35:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346704AbhIBRgp (ORCPT ); Thu, 2 Sep 2021 13:36:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234592AbhIBRgo (ORCPT ); Thu, 2 Sep 2021 13:36:44 -0400 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B30CCC061575 for ; Thu, 2 Sep 2021 10:35:45 -0700 (PDT) Received: by mail-pj1-x1033.google.com with SMTP id c6so1862852pjv.1 for ; Thu, 02 Sep 2021 10:35:45 -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=8Ymrvxc+hOIJEGSWo3PUPAKMd1JsWIvPvJEfp5+X584=; b=H/8pdIIe2TBQtfzQRnD7oYYk7jZaKgWznptGmMoVViWuM4xi2OPba5RRw8tIlP4HLh pNtIMQIsm8tvC1BUfhiVb6ELjbNHTZ8SHKOFsQNy+nvMBSqnEGUur4fb9NC8g7gQVBnJ 9C6mbdBxZJpOO6aB6a2T3EEbImeayvDHeYEK0= 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=8Ymrvxc+hOIJEGSWo3PUPAKMd1JsWIvPvJEfp5+X584=; b=J9iWQ0m+N232+9zSTEaYfN2BfzdNkAac8krRXPxIE9lZ2l+Yy14WV/6MQ2S4xi4p7m CDSM04O9SHhDWG2UUlyKYXNAZXlIDSxXLKT61jLg9ax2Vorg9zdNJWHSB41jy7ofkOHM xmvU+DcPmkgIysT7KbU8vaod+eC+rVEdPQM3CgtqXVBLk3/pAF47XMHhPAU1fLrHLoZP c/kwxXjfYLYUwr6L1cyLUehkPsTcRCfoTzMjeN+i6K/ebtNa/Z0S/tld0JsI14jcaPYX HL3Q5w2uTiXRtiV8utt03M4phGRI4ouLMG1GZ5xj7P1YyJHENKHtR9DtZPcM5W9rlcWt sFWA== X-Gm-Message-State: AOAM533HLC+T3KZdNE8nQXgb7crxNER3WCA+VYAk5PPGjS1aH73XKLZY svk4OjbPSCJvGva50g98vPDesw== X-Google-Smtp-Source: ABdhPJzqW728qM+O5agUjW9liMw4UajwMKdfYWX+2N+wdB0IvIs9YiCLR8LqFwmYvukT66jzbiMAMw== X-Received: by 2002:a17:90a:c89:: with SMTP id v9mr5176880pja.175.1630604145196; Thu, 02 Sep 2021 10:35:45 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id v8sm2848868pjh.24.2021.09.02.10.35.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 10:35:44 -0700 (PDT) Date: Thu, 2 Sep 2021 10:35:43 -0700 From: Kees Cook To: "Russell King (Oracle)" Cc: Keith Packard , linux-kernel@vger.kernel.org, Abbott Liu , Alexander Sverdlin , Al Viro , Andrew Morton , Anshuman Khandual , Ard Biesheuvel , Arnd Bergmann , Bjorn Andersson , Florian Fainelli , Geert Uytterhoeven , Hartley Sweeten , Jens Axboe , Jian Cai , Joe Perches , Linus Walleij , linux-arm-kernel@lists.infradead.org, Maninder Singh , Manivannan Sadhasivam , Marc Zyngier , Masahiro Yamada , Mike Rapoport , Nick Desaulniers , Nicolas Pitre , Peter Zijlstra , Thomas Gleixner , Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= , Valentin Schneider , Vaneet Narang , "Wolfram Sang (Renesas)" , YiFei Zhu , Keith Packard Subject: Re: [PATCH 0/2]: ARM: Enable THREAD_INFO_IN_TASK Message-ID: <202109021034.1FA93D2@keescook> References: <20210902155429.3987201-1-keithp@keithp.com> <20210902165353.GI22278@shell.armlinux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210902165353.GI22278@shell.armlinux.org.uk> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 02, 2021 at 05:53:53PM +0100, Russell King (Oracle) wrote: > On Thu, Sep 02, 2021 at 08:54:26AM -0700, Keith Packard wrote: > > Placing thread_info in the kernel stack leaves it vulnerable to stack > > overflow attacks. This short series addresses that by using the > > existing THREAD_INFO_IN_TASK infrastructure. > > > > As this is my first patch in this part of the kernel, I'm looking for > > feedback about the general approach as well as specific comments on > > places where I've missed something. > > > > I've only run this on armhf running under qemu, so while I've tried to > > make patches for other code paths, I haven't been able to test those. > > > > (yes, I know checkpatch.pl complains about whitespace in asm-offsets.c, I > > decided to leave the existing whitespace alone) > > > > Signed-off-by: Keith Packard > > I think you're introducing a circular dependency with this for > certain kernel configurations: > > E.g. Have you tried running this with CONFIG_CPU_V6 enabled? > > +#define raw_smp_processor_id() this_cpu_read(cpu_number) > +#define __smp_processor_id() __this_cpu_read(cpu_number) > + > +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number); > > this_cpu_read() is defined as: > > #define this_cpu_read(pcp) __pcpu_size_call_return(this_cpu_read_, pcp) > (which will call this_cpu_read_4) > > #define this_cpu_read_4(pcp) this_cpu_generic_read(pcp) > => __this_cpu_generic_read_nopreempt() > => ___ret = READ_ONCE(*raw_cpu_ptr(&(pcp))); > > #define raw_cpu_ptr(ptr) \ > ({ \ > __verify_pcpu_ptr(ptr); \ > arch_raw_cpu_ptr(ptr); \ > }) > > #ifndef arch_raw_cpu_ptr > #define arch_raw_cpu_ptr(ptr) SHIFT_PERCPU_PTR(ptr, __my_cpu_offset) > #endif > > #ifndef __my_cpu_offset > #define __my_cpu_offset per_cpu_offset(raw_smp_processor_id()) > #endif > > ... which then leads back to a use of raw_smp_processor_id(), thereby > creating a circular loop of preprocessor definitions that the compiler > can't resolve. If this isn't easy to fix, perhaps this can be a V7-only feature? -- Kees Cook From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 423A4C83028 for ; Thu, 2 Sep 2021 17:38:16 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 159E56113E for ; Thu, 2 Sep 2021 17:38:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 159E56113E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=CqjHSDH/+uwwklVwx9FbdWevc7pFU+8OxbAiZLFw4Vk=; b=WBYFbA9Kgpuhw9 LvNz65nUoT0CQP7K9WMdIw3yQ8ZslyysgLy1WbvHMLx/RESClnmTdyUsCCW21SH3Gv+6gEeGOndiy Y8pxYhWDufN5IL8AwEpSkvP/b97p5lw26ybbYWnQ4sxSdAQ8SvxPALmZzUW1SSczugA2mUCn2/RjW mpFDcpV92yU8XHmX+o2dK/cU6a5joLbC1Xv4z9oOBCEdbIPLodGfm43lAXrMbFFZSlxQy/j4j3uBF JfNasBMNmqUzeH/bgPek6RGbSjtESTfG60wYM92ntZAzxTFlHOALYoYP/dXBB5byLhKDGXN3BjGil 0qhPtD8NYnTlhzzkLZnw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mLqcw-00A7zf-AI; Thu, 02 Sep 2021 17:35:50 +0000 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mLqcs-00A7yd-Dk for linux-arm-kernel@lists.infradead.org; Thu, 02 Sep 2021 17:35:48 +0000 Received: by mail-pj1-x1032.google.com with SMTP id u13-20020a17090abb0db0290177e1d9b3f7so1988995pjr.1 for ; Thu, 02 Sep 2021 10:35:45 -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=8Ymrvxc+hOIJEGSWo3PUPAKMd1JsWIvPvJEfp5+X584=; b=H/8pdIIe2TBQtfzQRnD7oYYk7jZaKgWznptGmMoVViWuM4xi2OPba5RRw8tIlP4HLh pNtIMQIsm8tvC1BUfhiVb6ELjbNHTZ8SHKOFsQNy+nvMBSqnEGUur4fb9NC8g7gQVBnJ 9C6mbdBxZJpOO6aB6a2T3EEbImeayvDHeYEK0= 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=8Ymrvxc+hOIJEGSWo3PUPAKMd1JsWIvPvJEfp5+X584=; b=rcUntGhnvXTuVFGw7wi+c7PukYcMk9bIrnTjqN+0OSqP/A3JPrul5tvZLsZWBuB9K4 Nk7AeDGoGQ4pDURlcSBMVpLzzM698f2mvCAqhWt/SwIWVsMj4v2M5dJRXaCSn82DZ2Xo oHLID++pKG+M6Rv+Ca5GVh66IDkJl2uEuKF5cWcRr+h8wXtG2oe36Z1GxMSnOCKQfmPI gM/Q2Sj2Hw911hZA+MDCDymschmqhXRjXId0+mTBQ29cVcNdJ2E08mWX0NLAC/rvOadM F/4gK5w3W3Vjdwj94EUF1Of5ctnkh3XF2pgCr9O7nkMmFCMn0cMVtRB96Gpnq503XZjI /zcQ== X-Gm-Message-State: AOAM530kpJlVcNuSyNawWm4+XW5pNFlTawzbo86b8Sv6ciOuBPR8S8Kg fWiPmBYhtdZpQ/p6hlnCd05m0Q== X-Google-Smtp-Source: ABdhPJzqW728qM+O5agUjW9liMw4UajwMKdfYWX+2N+wdB0IvIs9YiCLR8LqFwmYvukT66jzbiMAMw== X-Received: by 2002:a17:90a:c89:: with SMTP id v9mr5176880pja.175.1630604145196; Thu, 02 Sep 2021 10:35:45 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id v8sm2848868pjh.24.2021.09.02.10.35.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 10:35:44 -0700 (PDT) Date: Thu, 2 Sep 2021 10:35:43 -0700 From: Kees Cook To: "Russell King (Oracle)" Cc: Keith Packard , linux-kernel@vger.kernel.org, Abbott Liu , Alexander Sverdlin , Al Viro , Andrew Morton , Anshuman Khandual , Ard Biesheuvel , Arnd Bergmann , Bjorn Andersson , Florian Fainelli , Geert Uytterhoeven , Hartley Sweeten , Jens Axboe , Jian Cai , Joe Perches , Linus Walleij , linux-arm-kernel@lists.infradead.org, Maninder Singh , Manivannan Sadhasivam , Marc Zyngier , Masahiro Yamada , Mike Rapoport , Nick Desaulniers , Nicolas Pitre , Peter Zijlstra , Thomas Gleixner , Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= , Valentin Schneider , Vaneet Narang , "Wolfram Sang (Renesas)" , YiFei Zhu , Keith Packard Subject: Re: [PATCH 0/2]: ARM: Enable THREAD_INFO_IN_TASK Message-ID: <202109021034.1FA93D2@keescook> References: <20210902155429.3987201-1-keithp@keithp.com> <20210902165353.GI22278@shell.armlinux.org.uk> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210902165353.GI22278@shell.armlinux.org.uk> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210902_103546_529505_990AD889 X-CRM114-Status: GOOD ( 28.53 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Sep 02, 2021 at 05:53:53PM +0100, Russell King (Oracle) wrote: > On Thu, Sep 02, 2021 at 08:54:26AM -0700, Keith Packard wrote: > > Placing thread_info in the kernel stack leaves it vulnerable to stack > > overflow attacks. This short series addresses that by using the > > existing THREAD_INFO_IN_TASK infrastructure. > > > > As this is my first patch in this part of the kernel, I'm looking for > > feedback about the general approach as well as specific comments on > > places where I've missed something. > > > > I've only run this on armhf running under qemu, so while I've tried to > > make patches for other code paths, I haven't been able to test those. > > > > (yes, I know checkpatch.pl complains about whitespace in asm-offsets.c, I > > decided to leave the existing whitespace alone) > > > > Signed-off-by: Keith Packard > > I think you're introducing a circular dependency with this for > certain kernel configurations: > > E.g. Have you tried running this with CONFIG_CPU_V6 enabled? > > +#define raw_smp_processor_id() this_cpu_read(cpu_number) > +#define __smp_processor_id() __this_cpu_read(cpu_number) > + > +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number); > > this_cpu_read() is defined as: > > #define this_cpu_read(pcp) __pcpu_size_call_return(this_cpu_read_, pcp) > (which will call this_cpu_read_4) > > #define this_cpu_read_4(pcp) this_cpu_generic_read(pcp) > => __this_cpu_generic_read_nopreempt() > => ___ret = READ_ONCE(*raw_cpu_ptr(&(pcp))); > > #define raw_cpu_ptr(ptr) \ > ({ \ > __verify_pcpu_ptr(ptr); \ > arch_raw_cpu_ptr(ptr); \ > }) > > #ifndef arch_raw_cpu_ptr > #define arch_raw_cpu_ptr(ptr) SHIFT_PERCPU_PTR(ptr, __my_cpu_offset) > #endif > > #ifndef __my_cpu_offset > #define __my_cpu_offset per_cpu_offset(raw_smp_processor_id()) > #endif > > ... which then leads back to a use of raw_smp_processor_id(), thereby > creating a circular loop of preprocessor definitions that the compiler > can't resolve. If this isn't easy to fix, perhaps this can be a V7-only feature? -- Kees Cook _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel