From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D691CC5517A for ; Thu, 22 Oct 2020 20:02:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 73125241A4 for ; Thu, 22 Oct 2020 20:02:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="D87aIC6R" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S370520AbgJVUCX (ORCPT ); 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-Google-Smtp-Source: ABdhPJxzFj2lWZu9IdxGeO5ZLR3jud5fxKudfnSoE1lSnvp4GFCMO24w5hRAidupXxV/3pvyIOWiyQ== 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 67C95C388F7 for ; Thu, 22 Oct 2020 20:03:54 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DAD8024182 for ; Thu, 22 Oct 2020 20:03:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="jnOITfz7"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="D87aIC6R" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DAD8024182 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=sCohd4XRo5su+Z+zQP/VQ/C2518DhmzDbpUNinLFl+A=; b=jnOITfz7baZVA68TqYvFxzHAK EXbFw13pNPrwbJgOBV6o9C0EZjeAeReEgQeeSeQMQz00x4M6f5oNiplWBjflDPd3QjfK3unq2CIh7 fryQlLv/s8v3E5e6jsj+npyRGIIPtu0Dl8916ONBWmVOLEi/4jYRwa52i+B0fssnbrY/aq/MndpzH QQrRfUx6Lie6PJghBlEv7b3PtvbQehb50py3cW90PbZhupKIU8MnKLMf9nEUHD+Yz/ZaCrSIbFfiW taxlHpaxTVOL8sv/d1Qq/l9J4Mc4VJ07ys9aUcxUYBA6PNbLv4Hql5+0XhHFirqkCbdppI/oYkIu9 upaOtH+ow==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kVgn3-00074L-OS; Thu, 22 Oct 2020 20:02:25 +0000 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kVgn1-00073g-4h for linux-arm-kernel@lists.infradead.org; Thu, 22 Oct 2020 20:02:24 +0000 Received: by mail-pf1-x444.google.com with SMTP id e10so1889725pfj.1 for ; Thu, 22 Oct 2020 13:02:22 -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=RK02/MMD6OzWjC9AC2SBSMYXh/cgHLvlOntLzIHCmEch+lg5HDmOwlVcMnKoXIx6tm a7YGipUYRB10Tu6unBscL0BPNZUotznTzNLQzR/hyvyfk6QHQqLBHypIJwUn8cMKbhbM j5b5c8KCvE4d21dIYeg3rF65XQ9JZ8QnkU0jX2jK5N6yK9kHa+2r2QeHt2xw2++mO1gW pgmSo2JC42silmW+TVq6YNEjBTy8Qx6PqNq2Ek7L9EDtZcFQe0T5yhxS+b1WRCnBALyL 9i3w+LcKoqweUXMPfdSaa6TijiMfDQfE76Gfqi9iHg9op93xhrv6NL1VIBo+3/esQ99o QvCA== X-Gm-Message-State: AOAM533ZKjCm1AfXaNqCZhzTQeb7lagXBQMkRNx3kHf/kEwySdCHxdwg AI4FnKyoAx93gRK5RIOghvPffw== X-Google-Smtp-Source: ABdhPJxzFj2lWZu9IdxGeO5ZLR3jud5fxKudfnSoE1lSnvp4GFCMO24w5hRAidupXxV/3pvyIOWiyQ== 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 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-Disposition: inline In-Reply-To: <78464155-f459-773f-d0ee-c5bdbeb39e5d@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201022_160223_326690_BE5343B6 X-CRM114-Status: GOOD ( 15.71 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Salvatore Mesoraca , systemd-devel@lists.freedesktop.org, kernel-hardening@lists.openwall.com, Szabolcs Nagy , Catalin Marinas , Will Deacon , "linux-kernel@vger.kernel.org" , Jeremy Linton , Mark Brown , linux-hardening@vger.kernel.org, libc-alpha@sourceware.org, Dave Martin , "linux-arm-kernel@lists.infradead.org" Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B0C3C388F7 for ; Thu, 22 Oct 2020 20:02:44 +0000 (UTC) Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.kernel.org (Postfix) with SMTP id 807F620759 for ; Thu, 22 Oct 2020 20:02:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="D87aIC6R" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 807F620759 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kernel-hardening-return-20252-kernel-hardening=archiver.kernel.org@lists.openwall.com Received: (qmail 17790 invoked by uid 550); 22 Oct 2020 20:02:33 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Received: (qmail 17755 invoked from network); 22 Oct 2020 20:02:32 -0000 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=BjjailMxQ9la+8you6vBCxYnYQwM2hLtc5WqxYHtjFnKKP3hwWvRABEDVJ7Cw6OQ+U VilqX9DXFDkKEQqyqdM4A66ButPj+t/lWF33zyTeF1ENwXS+cHsVcDCrwJuXV+q1CcL2 VQeb5BTbrlbrtPdyAiQiOQHciLTufumyyLQl4hh9yl5fud4O8Atkt9jIXf0EwIVzZCAE X2GAv5lo4QxhKreqOzkB1SVAPf7LB0syjrjkngVLzcsQ8X5HG22lxW1HaKl4X/WHU/Eb MbYTpmBrclLi8yyPxcQVsOVJ4dcBw6byOzF8N2tVcp51oQkWNvG9HQClKgwWfKY6jjJI U/pg== X-Gm-Message-State: AOAM530fgPzLiMxOQslwPsH6JQP7YXrc1qSM/HYjFPh93BUqRqOpHlBg BIyVUxZG3d8p5Tzzni6MuNR7Xg== X-Google-Smtp-Source: ABdhPJxzFj2lWZu9IdxGeO5ZLR3jud5fxKudfnSoE1lSnvp4GFCMO24w5hRAidupXxV/3pvyIOWiyQ== X-Received: by 2002:a63:1457:: with SMTP id 23mr3631355pgu.24.1603396940642; Thu, 22 Oct 2020 13:02:20 -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> 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