Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A614DC433F5 for ; Mon, 22 Nov 2021 16:14:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239519AbhKVQRd (ORCPT ); Mon, 22 Nov 2021 11:17:33 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:27944 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229911AbhKVQRb (ORCPT ); Mon, 22 Nov 2021 11:17:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637597664; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=oDqfdIbFIdXooJZfUJt+6LBfPzQdTcBW//aerVYbmM8=; b=PdMsEM9qwwDgbQCFooySskriUFYOnOtKh8Y2uaL7mo8cAuJvejYWj1qmrH7NjedjRjgrl8 2yUan2lKEuUWY5MXIEwUQw2nFMed7cbEsUPSwohB98hdjEM5DwwwBuFmtCTudlZAmw398a cO+kt2YweHjHI4K+pH+sm3OgVox81Ac= Received: from mail-oi1-f199.google.com (mail-oi1-f199.google.com [209.85.167.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-22-8vVClWxoOheTbgxdu5KidA-1; Mon, 22 Nov 2021 11:14:22 -0500 X-MC-Unique: 8vVClWxoOheTbgxdu5KidA-1 Received: by mail-oi1-f199.google.com with SMTP id y20-20020acaaf14000000b002a817a23a1eso12947359oie.23 for ; Mon, 22 Nov 2021 08:14:22 -0800 (PST) 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=oDqfdIbFIdXooJZfUJt+6LBfPzQdTcBW//aerVYbmM8=; b=AjTO/7y/46/ft9VdXdoH1L4mcYImjTFt/bFxyOpBy5X5KCpoAJk7b+Umh5Unt9HsKt ijKgnvlACCRYsM8LR+YlX8QO2p0UT8CQ8iBKEpbUYSPLcNUgT1UDg0p3iQPaIVvrYBrq zsoqGb/SD8L6fNtqHR23vyH92ToMgX/ohKEhUxPHRPHGgmmunZOOrrV0KEgMJ9aTFcp9 IxiLyBH6yx47f+kdpWM/HRhKmz07Ov+hK1pQRAaPB+CTf0nsX6vYskH1JCmlZ0AA6SJw Nh33nuYdkRVe+207N0TqAhD/JFnR9AxXg+8AkVIXE5cgOSbiu0zw+1/A2EvD9DAlscmo HDdw== X-Gm-Message-State: AOAM533fNrn9Lt9JJ4MoziuBqCopAchivhFoXrArPqmnQ/jt0XxPOaGk 1T1n8ATgPa5nUYrk6qsWB83BJZ9GOLE8RzpxKSBnwp0A53KuYFagdH8tjB3JLVuElRzO+hJrcKx 8xXzBIP7aD3kmnlecZOZQAPng X-Received: by 2002:a9d:7601:: with SMTP id k1mr25983692otl.356.1637597662228; Mon, 22 Nov 2021 08:14:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJxNn/JqyNoAjBIUZE9V4zkBZkxe3Q7h92hvai17oMl48w0ykwgLNgn4Hjv/oGLto3z69Uf7TA== X-Received: by 2002:a9d:7601:: with SMTP id k1mr25983660otl.356.1637597662009; Mon, 22 Nov 2021 08:14:22 -0800 (PST) Received: from treble ([2600:1700:6e32:6c00::35]) by smtp.gmail.com with ESMTPSA id bl33sm2000920oib.47.2021.11.22.08.14.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Nov 2021 08:14:20 -0800 (PST) Date: Mon, 22 Nov 2021 08:14:17 -0800 From: Josh Poimboeuf To: Peter Zijlstra Cc: Linus Torvalds , Holger Hoffst??tte , Qi Zheng , Kees Cook , Thomas Gleixner , Justin Forbes , Greg Kroah-Hartman , Linux Kernel Mailing List , Andrew Morton , Guenter Roeck , Shuah Khan , patches@kernelci.org, lkft-triage@lists.linaro.org, Pavel Machek , Jon Hunter , Florian Fainelli , stable Subject: Re: [PATCH] x86: Pin task-stack in __get_wchan() Message-ID: <20211122161417.p3yopenukxbts4gm@treble> References: <55c7b316-e03d-9e91-d74c-fea63c469b3b@applied-asynchrony.com> <20211118080627.GH174703@worktop.programming.kicks-ass.net> <20211118081852.GM174730@worktop.programming.kicks-ass.net> <20211119020427.2y5esq2czquwmvwc@treble> <20211119183544.sragh42cn2liu3pw@treble> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Nov 22, 2021 at 10:32:32AM +0100, Peter Zijlstra wrote: > On Fri, Nov 19, 2021 at 10:35:44AM -0800, Josh Poimboeuf wrote: > > On Fri, Nov 19, 2021 at 10:29:47AM +0100, Peter Zijlstra wrote: > > > On Thu, Nov 18, 2021 at 06:04:27PM -0800, Josh Poimboeuf wrote: > > > > On Thu, Nov 18, 2021 at 01:11:09PM +0100, Peter Zijlstra wrote: > > > > > > > > I now have the below, the only thing missing is that there's a > > > > > user_mode() call on a stack based regs. Now on x86_64 we can > > > > > __get_kernel_nofault() regs->cs and call it a day, but on i386 we have > > > > > to also fetch regs->flags. > > > > > > > > > > Is this really the way to go? > > > > > > > > Please no. Can we just add a check in unwind_start() to ensure the > > > > caller did try_get_task_stack()? > > > > > > I tried; but at best it's fundamentally racy and in practise its worse > > > because init_task doesn't seem to believe in refcounts and kthreads are > > > odd for some raisin. Now those are fixable, but given the fundamental > > > races, I don't see how it's ever going to be reliable. > > > > I'm probably out of the loop here, but I wonder what races you're > > referring to. > > We can do the warn as you suggest, however, it can become 0 right after > we test and then still make the unwder explode. > > That is, the test is not sufficient. Realistically there are a limited number of callers to the unwinder. If anybody calls with refcount < 2 then we can WARN() and root them out. It would have found this bug far before any weird races would have been found. True, it's not bulletproof, but task unwinder usage is (to some degree) less critical than oopses. Now I'm off to disappear for turkey week. Cheers. -- Josh