Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp663159pxu; Thu, 3 Dec 2020 09:33:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJwvL98351YLxBOZP/05J9hu1m/cCHx3E13EAdWKmNzefcg8bqmSKbpijFGzJTpNw5iWgc7A X-Received: by 2002:a17:906:f949:: with SMTP id ld9mr3543548ejb.401.1607016807690; Thu, 03 Dec 2020 09:33:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607016807; cv=none; d=google.com; s=arc-20160816; b=HIaxiwoWIWWMvudKobCMO/qwCT+zaX3XnQ2HvUH0GqgBTPdPaERqcl9rQJbm8+RemH wVxWLyne8iD7OzY+sJl7u6dFATt0yCHP2NVeR9kS2mGgYi6FUxUHNtW7x89dG8Z3v2NR bOxTGmH/MOPVN9HYzmleP6PEvWbMehb5g85xKxF6uxovm9cgUeYupL43e5Ye83C8n7Hk 8qJ5QMuER0PdTDUP7iLaICoTQiAkk5X6YHsHzQs3O74dglEjJ7JinlXCtfYI/66RakF1 l7tbPqktiCu7tBEcnSPVh2T96yA1X4AqIFMcS3feBaN4D3FPn+uyxqxhZu20QRNesYWQ ogwQ== 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=u26pJKrgRct0Iam217oKqpYabWqzmuDS4T3uWLnkG1Y=; b=KRuY0QnlNK5a/r5N2T3vDVhIvTck0GqL8/aHCFoiCQzzAHAH4sHvNrr2rHlB6+duFm /V4yE4gRVbk+1cuGeKck728nX9cRdkv40azbZL6Ecau7iwFEQmjU4rPRb1XrZeVAqb+7 b73/hrg9WboP3daq/6kPc6q4qG3t6tRDi0EcONwrLEgF8j+B+MO9i8bBTWIJvCs6326z CK1oYa7ktlRqK610a1IMK9EcgWnvYx75wq5bfFX3bPPMuJE7njlYz6oTgBBdj4nLb208 jlRpRI4gn8ZpQa7UBxnitPUHt5j3J57V21J9TMMY8D28ghsMrjs6E3nNHfqP/fN7kFbb d+7Q== 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 cz22si1319050edb.241.2020.12.03.09.33.03; Thu, 03 Dec 2020 09:33:27 -0800 (PST) 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 S1730287AbgLCRax (ORCPT + 99 others); Thu, 3 Dec 2020 12:30:53 -0500 Received: from mail.kernel.org ([198.145.29.99]:41140 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726066AbgLCRax (ORCPT ); Thu, 3 Dec 2020 12:30:53 -0500 Date: Thu, 3 Dec 2020 17:30:06 +0000 From: Catalin Marinas To: Szabolcs Nagy Cc: libc-alpha@sourceware.org, Mark Rutland , Will Deacon , linux-kernel@vger.kernel.org, Jeremy Linton , Mark Brown , kernel-hardening@lists.openwall.com, Topi Miettinen , linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH v2 0/6] aarch64: avoid mprotect(PROT_BTI|PROT_EXEC) [BZ #26831] Message-ID: <20201203173006.GH2830@gaia> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Szabolcs, On Fri, Nov 27, 2020 at 01:19:16PM +0000, Szabolcs Nagy wrote: > This is v2 of > https://sourceware.org/pipermail/libc-alpha/2020-November/119305.html > > To enable BTI support, re-mmap executable segments instead of > mprotecting them in case mprotect is seccomp filtered. > > I would like linux to change to map the main exe with PROT_BTI when > that is marked as BTI compatible. From the linux side i heard the > following concerns about this: > - it's an ABI change so requires some ABI bump. (this is fine with > me, i think glibc does not care about backward compat as nothing > can reasonably rely on the current behaviour, but if we have a > new bit in auxv or similar then we can save one mprotect call.) I'm not concerned about the ABI change but there are workarounds like a new auxv bit. > - in case we discover compatibility issues with user binaries it's > better if userspace can easily disable BTI (e.g. removing the > mprotect based on some env var, but if kernel adds PROT_BTI and > mprotect is filtered then we have no reliable way to remove that > from executables. this problem already exists for static linked > exes, although admittedly those are less of a compat concern.) This is our main concern. For static binaries, the linker could detect, in theory, potential issues when linking and not set the corresponding ELF information. At runtime, a dynamic linker could detect issues and avoid enabling BTI. In both cases, it's a (static or dynamic) linker decision that belongs in user-space. > - ideally PROT_BTI would be added via a new syscall that does not > interfere with PROT_EXEC filtering. (this does not conflict with > the current patches: even with a new syscall we need a fallback.) This can be discussed as a long term solution. > - solve it in systemd (e.g. turn off the filter, use better filter): > i would prefer not to have aarch64 (or BTI) specific policy in > user code. and there was no satisfying way to do this portably. I agree. I think the best for now (as a back-portable glibc fix) is to ignore the mprotect(PROT_EXEC|PROT_BTI) error that the dynamic loader gets. BTI will be disabled if MDWX is enabled. In the meantime, we should start (continue) looking at a solution that works for both systemd and the kernel and be generic enough for other architectures. The stateless nature of the current SECCOMP approach is not suitable for this W^X policy. Kees had some suggestions here but the thread seems to have died: https://lore.kernel.org/kernel-hardening/202010221256.A4F95FD11@keescook/ -- Catalin