Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp293756pxu; Wed, 7 Oct 2020 03:21:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw41FfFFk9GCKc5LsGq9/RrOM/C84MiJecn0pDNRG7oUPqsXd5jpcUwhQ+r1//gwRJu2UiG X-Received: by 2002:a17:906:340b:: with SMTP id c11mr2588598ejb.213.1602066092601; Wed, 07 Oct 2020 03:21:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602066092; cv=none; d=google.com; s=arc-20160816; b=WsCvlws05qLFoCGdvXhZTlg0HfIgBkmASNm7x0pa69vXJew5Ibj2WbXK1YDYjTScJI owra+E95I04kP14+S4GrFsmYnXdfcHRrOl+J3Gn1f2rrNsEPW6Duaj+KCqVreeEvWuqr DNXgDBzPW54iU1ihFTgZLQ99RKCENg/QAdT5w3YANtiLWVtLNUpHNonIwTWmKk74iJJu 253S6SAxFl0juZt2LEJWZT4tm/zcmXf9kG6E0VteIqYK5rfn9I7gwW1zsUh1rpDChgsK zlxsUxZaaNmj2whQJdA5eUnytw1BFjTTXEL7nMtU9hO3ZePwswPhjaEKt3o8H2wjNZ6k v3gg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=CL0LGRiipSaelxayKtwqbpqr3/jIpG4NvQtijV2IWE8=; b=gkUIBs2Te2nhwsZaXVDY3vaj1juZZOA+jUXMfPK2WHN9NWHpPPCARHHp139UiVHr1v 12Cx0PpG/jG8rcMrb3SVp9dfn6EqHZQeAq2Fin2wjuxuNJjnwEZqIIBuXvTaMWu+ZhH8 L21pdQRqgVNfPAORwqKELgbDr9X+J97hHyyb9EK7Jm2I4/rZIK1uVuDtDHzsLWjW8hOH e7rY/GO1R5DeYSPNFc7Hy+eaM/VPRPNXEt2bDTLRRyO/UGcLHq+u6Oo2dz0GqvR8wt3K y1jDk+jR9AkSkhiQPGOmZpzlAb0Q5kBGzAJD7xlTsssDJbS9KmGhMB/KfRP19Sk2df4p w4pg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gs18si1372478ejb.8.2020.10.07.03.21.10; Wed, 07 Oct 2020 03:21:32 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727906AbgJGKTk (ORCPT + 99 others); Wed, 7 Oct 2020 06:19:40 -0400 Received: from foss.arm.com ([217.140.110.172]:41398 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727297AbgJGKTk (ORCPT ); Wed, 7 Oct 2020 06:19:40 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4407D11B3; Wed, 7 Oct 2020 03:19:39 -0700 (PDT) Received: from arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 61C433F71F; Wed, 7 Oct 2020 03:19:37 -0700 (PDT) Date: Wed, 7 Oct 2020 11:19:34 +0100 From: Dave Martin To: Florian Weimer Cc: Dave Martin via Libc-alpha , Dave Hansen , linux-arch , Tony Luck , "Ravi V. Shankar" , Len Brown , "Chang S. Bae" , the arch/x86 maintainers , LKML , Andy Lutomirski , Linux API , Thomas Gleixner , Borislav Petkov , Ingo Molnar Subject: Re: [RFC PATCH 0/4] x86: Improve Minimum Alternate Stack Size Message-ID: <20201007101933.GF6642@arm.com> References: <20200929205746.6763-1-chang.seok.bae@intel.com> <20201005134534.GT6642@arm.com> <20201006092532.GU6642@arm.com> <20201006152553.GY6642@arm.com> <7663eff0-6c94-f6bf-f3e2-93ede50e75ed@intel.com> <20201006170020.GB6642@arm.com> <87362rp65v.fsf@oldenburg2.str.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87362rp65v.fsf@oldenburg2.str.redhat.com> User-Agent: Mutt/1.5.23 (2014-03-12) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 06, 2020 at 08:21:00PM +0200, Florian Weimer wrote: > * Dave Martin via Libc-alpha: > > > On Tue, Oct 06, 2020 at 08:33:47AM -0700, Dave Hansen wrote: > >> On 10/6/20 8:25 AM, Dave Martin wrote: > >> > Or are people reporting real stack overruns on x86 today? > >> > >> We have real overruns. We have ~2800 bytes of XSAVE (regisiter) state > >> mostly from AVX-512, and a 2048 byte MINSIGSTKSZ. > > > > Right. Out of interest, do you believe that's a direct consequence of > > the larger kernel-generated signal frame, or does the expansion of > > userspace stack frames play a role too? > > I must say that I do not quite understand this question. > > 32 64-*byte* registers simply need 2048 bytes of storage space worst > case, there is really no way around that. If the architecture grows more or bigger registers, and if those registers are used in general-purpose code, then all stack frames will tend to grow, not just the signal frame. So a stack overflow might be caused by the larger signal frame by itself; or it might be caused by the growth of the stack of 20 function frames created by someone's signal handler. In the latter case, this is just a "normal" stack overflow, and nothing really to do with signals or SIGSTKSZ. Rebuilding with different compiler flags could also grow the stack usage and cause just the same problem. I also strongly suspect that people often don't think about signal nesting when allocating signal stacks. So, there might be a pre- existing potential overflow that just becomes more likely when the signal frame grows. That's not really SIGSTKSZ's fault. Of course, AVX-512 might never be used in general-purpose code. On AArch64, SVE can be used in general-purpose code, but it's too early to say what its prevalence will be in signal handlers. Probably low. > > In practice software just assumes SIGSTKSZ and then ignores the problem > > until / unless an actual stack overflow is seen. > > > > There's probably a lot of software out there whose stack is > > theoretically too small even without AVX-512 etc. in the mix, especially > > when considering the possibility of nested signals... > > That is certainly true. We have seen problems with ntpd, which > requested a 16 KiB stack, at a time when there were various deductions > from the stack size, and since the glibc dynamic loader also uses XSAVE, > ntpd exceeded the remaining stack space. But in this case, we just > fudged the stack size computation in pthread_create and made it less > likely that the dynamic loader was activated, which largely worked > around this particular problem. For MINSIGSTKSZ, we just don't have > this option because it's simply too small in the first place. > > I don't immediately recall a bug due to SIGSTKSZ being too small. The > test cases I wrote for this were all artificial, to raise awareness of > this issue (applications treating these as recommended values, rather > than minimum value to avoid immediately sigaltstack/phtread_create > failures, same issue with PTHREAD_STACK_MIN). Ack, I think if SIGSTKSZ was too small significantly often, there would be more awareness of the issue. Cheers ---Dave