Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp396450pxx; Mon, 26 Oct 2020 10:57:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwRjfZ7xvJ4WDaYFa+Qmrp6/mtGWZ/KeSJ08vvjcPDGSfvgYTIE1vaqjgdhzA/6nItQ1WJs X-Received: by 2002:a17:906:57c6:: with SMTP id u6mr8206169ejr.375.1603735056562; Mon, 26 Oct 2020 10:57:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603735056; cv=none; d=google.com; s=arc-20160816; b=BCaCv4LdTQk36nym9A+hXHBHf84fgSq1mRAcY+72zKUZhneQ7MPrLvg3X7W+NpxbKv ftWgRM8CQ8wJTLpmxHV2hh6aqhr/6pBItvc2LXK5gisqt0unoE6F7WmxAuRWz4x6gClO 1uMvYXp1aqpBkTzGWBS3rosHCXISbpoOzx2ocOWQiGzR2Ya5hPunSB17Q5skb6YatXmj /xb4kEZrHtscYXFfcSE2Fp6Sun6VtzxnrMJVSKpeQLuAHWGdXD8hbQD8ptrRriZ+ZRAP SxTazhE1vj73DtwruxUHBvHFcLcj/+q/MO6Ut2gqNc7vuP0pFFjCFz5Pc27sIM2oq2a3 kwQw== 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=/gweFBR5sWYAHYoqLGOtZL1BHuVdP55ad3kYW6NhoyA=; b=E0SXCFgcUHh8E7u+i6u3jbWz9dy9tOMsgeRbPrfVyeP7SWIKiI5dJVu/KaXkwRI8Qn CxY0G4CoMA66t9TI46Hg0PfsWD/hfqJQTyv79RfJ6/iG7Fdkejsgs9MvMGuwxeGfFBIO MuJOdHiNZvsy7wGt5F8uoDYiU2+gtK4BgJGFdaFuNXmekYQyk8LdfFUjskA9wRSDZ60M lPDwNopUpuEBSOqb2l760N4sAFFysNnEQIFXk1J15QDDPssnEmYApFYaU/N6le2WV3fN mG/uuqtTC2xxv/6C1c7OCBgzuHimakqSgiEpguF/8j3V9YOSQZ7OdZxz38i3BLztko8R NSmQ== 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 y26si7712782ejq.617.2020.10.26.10.57.13; Mon, 26 Oct 2020 10:57:36 -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 S1782143AbgJZOwy (ORCPT + 99 others); Mon, 26 Oct 2020 10:52:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:38014 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2442716AbgJZOwx (ORCPT ); Mon, 26 Oct 2020 10:52:53 -0400 Received: from gaia (unknown [95.145.162.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AADC720773; Mon, 26 Oct 2020 14:52:49 +0000 (UTC) Date: Mon, 26 Oct 2020 14:52:46 +0000 From: Catalin Marinas To: Topi Miettinen Cc: Kees Cook , Szabolcs Nagy , Jeremy Linton , "linux-arm-kernel@lists.infradead.org" , libc-alpha@sourceware.org, systemd-devel@lists.freedesktop.org, "linux-kernel@vger.kernel.org" , Mark Rutland , Mark Brown , Dave Martin , Will Deacon , Salvatore Mesoraca , kernel-hardening@lists.openwall.com, linux-hardening@vger.kernel.org Subject: Re: BTI interaction between seccomp filters in systemd and glibc mprotect calls, causing service failures Message-ID: <20201026145245.GD3117@gaia> References: <8584c14f-5c28-9d70-c054-7c78127d84ea@arm.com> <20201022075447.GO3819@arm.com> <78464155-f459-773f-d0ee-c5bdbeb39e5d@gmail.com> <202010221256.A4F95FD11@keescook> <20201023090232.GA25736@gaia> 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 On Sat, Oct 24, 2020 at 02:01:30PM +0300, Topi Miettinen wrote: > On 23.10.2020 12.02, Catalin Marinas wrote: > > On Thu, Oct 22, 2020 at 01:02:18PM -0700, Kees Cook wrote: > > > Regardless, it makes sense to me to have the kernel load the executable > > > itself with BTI enabled by default. I prefer gaining Catalin's suggested > > > patch[2]. :) > > [...] > > > [2] https://lore.kernel.org/linux-arm-kernel/20201022093104.GB1229@gaia/ > > > > I think I first heard the idea at Mark R ;). > > > > It still needs glibc changes to avoid the mprotect(), or at least ignore > > the error. Since this is an ABI change and we don't know which kernels > > would have it backported, maybe better to still issue the mprotect() but > > ignore the failure. > > What about kernel adding an auxiliary vector as a flag to indicate that BTI > is supported and recommended by the kernel? Then dynamic loader could use > that to detect that a) the main executable is BTI protected and there's no > need to mprotect() it and b) PROT_BTI flag should be added to all PROT_EXEC > pages. We could add a bit to AT_FLAGS, it's always been 0 for Linux. > In absence of the vector, the dynamic loader might choose to skip doing > PROT_BTI at all (since the main executable isn't protected anyway either, or > maybe even the kernel is up-to-date but it knows that it's not recommended > for some reason, or maybe the kernel is so ancient that it doesn't know > about BTI). Optionally it could still read the flag from ELF later (for > compatibility with old kernels) and then do the mprotect() dance, which may > trip seccomp filters, possibly fatally. I think the safest is for the dynamic loader to issue an mprotect() and ignore the EPERM error. Not all user deployments have this seccomp filter, so they can still benefit, and user can't tell whether the kernel change has been backported. Now, if the dynamic loader silently ignores the mprotect() failure on the main executable, is there much value in exposing a flag in the aux vectors? It saves a few (one?) mprotect() calls but I don't think it matters much. Anyway, I don't mind the flag. The only potential risk is if the dynamic loader decides not to turn PROT_BTI one because of some mix and match of objects but AFAIK BTI allows interworking. -- Catalin