Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp592615pxb; Thu, 2 Sep 2021 10:39:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzIXhOwTubd3lmISguoyOq4hpYqZ1tS74/JC9dCtRHrh0sp/H3ZfQusG6312z+OeRz5jsv1 X-Received: by 2002:a6b:8bcf:: with SMTP id n198mr3803445iod.178.1630604374936; Thu, 02 Sep 2021 10:39:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630604374; cv=none; d=google.com; s=arc-20160816; b=vjh0hl50L3+fEb4cP+A5k7UuOzJb77kX1hmH18/QjpTRzO1QAABB1Uz0uzhy2LM45+ jQCW6P2YRSCA5bednb0ri8nnecKH/lEWOMANC/wIFtZaLuFUEAQO2vV9+CEWMTcfUDkJ 0rjHt2Bx4ss6e452ICLu/HTX8zpFktRcyAhAnr6byAj9bf+XgOiobj3h/P+r7BB38BGb ZJdfoZ5AaVNVgiIf4SDRSEGDR8WqYk0l8Xwsa/GLgK/mvus63Dj/szLr8wER0Z0BliUY KDT54oLMxcLReyQA968UNzXC7lzL+4g7rvSRPn5HmfCtFlaO3WtD4cpJrnZKCOtFu1Y6 MQCQ== 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=8Ymrvxc+hOIJEGSWo3PUPAKMd1JsWIvPvJEfp5+X584=; b=UyOj8N3y8cKy0KQOWATe3co/SkbjS0VeDxAcFHhZVrxOb6mf936jVGlW34nV8R7ngF HuZuXwOblokoYeNpfAGk5kgdErDbfdb7fR9027x3hcy3nccuf6AWNZnDc82PpDA+jNRa Ca/7bvhUArId2PqC3XXJKWNk4eIrPrQ+/4kqi2lbA0hlzJWayKVxxN7E3cUOv90jOKXJ jc0UvsPAjgz8skxCBcA2w7hpp5e13zEID9M04VDpf3Nz7haUUJ/UTFrOahYnehhVM3RB 6f0V1sVj8QgwdPPaQuHKBlkG0KKkHOyYpyZ9Jiu4oESfqmN8iEREkiJlExYpUhdd9tUQ 2POA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="H/8pdIIe"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id j14si2500587iok.53.2021.09.02.10.39.22; Thu, 02 Sep 2021 10:39:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="H/8pdIIe"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1346697AbhIBRgo (ORCPT + 99 others); Thu, 2 Sep 2021 13:36:44 -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-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