Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp226039pxu; Thu, 22 Oct 2020 21:42:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy1qrho6eGT42r6peyMGt8/u4HnFsHG6Px8YA3yUCslXhR16yrRuKWxb5jiBIn7cRPoFcCq X-Received: by 2002:a50:c38e:: with SMTP id h14mr521906edf.174.1603428122133; Thu, 22 Oct 2020 21:42:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603428122; cv=none; d=google.com; s=arc-20160816; b=nAc6CDKP2whzb7j/fSY/QQmhIv784TcY31n6fpx2L2nYJakXvYP3NPhS5iQ6eb2Jm1 NBzQsvd3nKcds82SKuGL7J0AGzzE7pxharRDHJkYmMXGzRSJOW1MGdvmXqgr4YomKqEL DSChkLblSjndYturRApPerT4pYlf+EFoMtemreGEYiE/Q4MBuXK2gZPXMlc4zKdvRTtn 1p/uvBcSiCj47VTMgGngAtGc/0gZY9uH7/RUkdUhtMoDfDz4yDTYFoN6P3zXhjs6jrLL hDqcZvvGgidoMJwmat2dESEKMgT/6BlBVnjpyx8iEVhRjSQ051/Yrqvjr6MDU1e2AIpq hvLQ== 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=cFPNRFtcPYYUxGQLBpZGVkGsffh0bPYUzGPf0AjIisE=; b=gmqxVxzoa3b4Gl+V0I7+vBjExlruq/C0bE2+7gfRGIHmPUWPMQHeQiw7bxXdOsuYG9 w4GowrfkwGr/8e0dgoZj1jNNsOxi+I7P/+qv9pJrMZrh43Ss3wGC9L/wkvLHjbJEjkBg DzC1ufm8EMilRCh8eFyRT+1hNiO4Kkwf6sw+Q5ceEJ7HsevgTD7D8anPSAkMQiyaR4Nk IO/DkOd+PJWXufGBcZoULPf3NrfaaLJ6KGDlSgnmkKfaQyDRJNqxrAftsk1ITLdCjyQ0 cOZ6tQwj2KUeUbkbnCA/E/3b1t6OxIqf+96sqyf08cv1b5PD7/jgnUDrNpFWu2hpy9u2 Frvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=D87aIC6R; 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 lm6si119191ejb.334.2020.10.22.21.41.39; Thu, 22 Oct 2020 21:42:02 -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=D87aIC6R; 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 S370516AbgJVUCX (ORCPT + 99 others); Thu, 22 Oct 2020 16:02:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S370510AbgJVUCW (ORCPT ); Thu, 22 Oct 2020 16:02:22 -0400 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42A4BC0613CE for ; Thu, 22 Oct 2020 13:02:21 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id n9so1619350pgt.8 for ; Thu, 22 Oct 2020 13:02:21 -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=cFPNRFtcPYYUxGQLBpZGVkGsffh0bPYUzGPf0AjIisE=; b=D87aIC6RhWXjIFC2wLTyA9sXgg4Ohi35vZlWc6IpsPweIMiuSuPWWV/GUDv5nHmJ85 VZHEHdDU6+v2ffn1rfa3oGSzdn/lPafbEyay3hC42oYeNVfBehGnh2LHtq3E2bneQqHm 5Cxx30ICp+zQTttpir5HjfH4xhmU5v7FgZ1Hg= 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=cFPNRFtcPYYUxGQLBpZGVkGsffh0bPYUzGPf0AjIisE=; b=cwEZTT5sXjDeH8uMpfa/lELFIoj/DrEyKRpXkfyCbdoAOoSzpH8omzwExHznCyB0xq EQziwtcvyNUNvhrZ6oZA3RnZoZcyuPTSq/qVbtzJqhCGd0rZ84OlVR5GxoVNR78siHxt kDLlrSzzAFlHh2Ba4bFY6DJuwijbE28W5wMoI7zRYgAL9KUfFo5aBGaXy8mK/MQ1LfzJ ZJ85XqniwrjiRrnuCds9Oqb9vewIUsjQ+tmAe44EWEdtP2O1k0+NqJJ0z0EpKISdVM/o rm17+AOk9eCOxoiC80wR/PYinyJcRsmq2J7NKQxjy4bA2SSh8yoWG8dayQiwpZZHSuRN dsAw== X-Gm-Message-State: AOAM533cVdrWT/5ikZrlHZFkpLM/2SvveaZHAnhtmgmTT+83hajtcMUq +ozuT406m6rZPzrRmBkxBIGoxw== X-Received: by 2002:a63:1457:: with SMTP id 23mr3631355pgu.24.1603396940642; Thu, 22 Oct 2020 13:02:20 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id m13sm46692pjr.30.2020.10.22.13.02.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Oct 2020 13:02:19 -0700 (PDT) Date: Thu, 22 Oct 2020 13:02:18 -0700 From: Kees Cook To: Topi Miettinen Cc: 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 , Catalin Marinas , 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: <202010221256.A4F95FD11@keescook> References: <8584c14f-5c28-9d70-c054-7c78127d84ea@arm.com> <20201022075447.GO3819@arm.com> <78464155-f459-773f-d0ee-c5bdbeb39e5d@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <78464155-f459-773f-d0ee-c5bdbeb39e5d@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 22, 2020 at 01:39:07PM +0300, Topi Miettinen wrote: > But I think SELinux has a more complete solution (execmem) which can track > the pages better than is possible with seccomp solution which has a very > narrow field of view. Maybe this facility could be made available to > non-SELinux systems, for example with prctl()? Then the in-kernel MDWX could > allow mprotect(PROT_EXEC | PROT_BTI) in case the backing file hasn't been > modified, the source filesystem isn't writable for the calling process and > the file descriptor isn't created with memfd_create(). Right. The problem here is that systemd is attempting to mediate a state change using only syscall details (i.e. with seccomp) instead of a stateful analysis. Using a MAC is likely the only sane way to do that. SELinux is a bit difficult to adjust "on the fly" the way systemd would like to do things, and the more dynamic approach seen with SARA[1] isn't yet in the kernel. Trying to enforce memory W^X protection correctly via seccomp isn't really going to work well, as far as I can see. 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]. :) [1] https://lore.kernel.org/kernel-hardening/1562410493-8661-1-git-send-email-s.mesoraca16@gmail.com/ [2] https://lore.kernel.org/linux-arm-kernel/20201022093104.GB1229@gaia/ -- Kees Cook