Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp603482pxx; Mon, 26 Oct 2020 16:34:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwXKL4Tj3U/SvSTsPhDW8h+S75iFlgvonHt7ab/Rx73e7vtRKMdumOI7YULOhytCddvDxUp X-Received: by 2002:a05:6402:503:: with SMTP id m3mr6244456edv.368.1603755278492; Mon, 26 Oct 2020 16:34:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603755278; cv=none; d=google.com; s=arc-20160816; b=y8we5jGtUC6tvBipcc7tu5OwYES4mXaiSGugViz0ypkni7OwmagRvu131tR+yU/Krh OKKb+ttEoYCp59ggFnjEwkaYCBNAEeShSW9Y0dOq5NTL+jLq7W7t+Ff3YUG3kR0cVG2U eV788zsVwPhqjJGnIxmeR5WDGR1kFFw7u1ox+kNgUg9gHuR/7ACCPvt6tBZHT8yPmOtC Kov1eRPrWZzWV3c2ZGWLHFmL9OSH0dpUZhNLkYkz6oW7kstZccKJCu+BQ39zYks0aD0m QxgDrxSijwqhGESk9v/dhx8JcElP/UfnLuQdITtgKhU/hdfbbAFY0TLCpnSAj1+3D8xA Iopg== 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=58GmRWU6X6noZfTOYnWVXWUHBMZIfooGt53V90XiD60=; b=gYx9OWQNb+RHhdKtW+ga4wywgcj49f9PlZqGRyAHuPSZMm4anjYPWm4Uw4Lj51Ilqj tNhEbuEeh15YKMr031R2NkMWj924+/KAmYzR3rza7bo8tCXnzLOEs33xI0Xl8sAJ2iW/ EKyEou/yCdqm+PP0qnr8TUB+9kgtiy+tmEygwusQLP5odCWU6uVB2W5Cb2LeZ3dN1nAW 232YEKuXFKESBUNuMQvVH+nXg4JrfT8N7+gyCvNX+uSYTu5W0LslRgBb5uY7TrOu1O6B dsbFejqqjbC+H3ueoJQY9Etj/wk/L4rduWCNs6dv7jYw345g9kK5vxmyEYDgBorQfFdt hw+Q== 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 g17si10320663ejr.134.2020.10.26.16.34.16; Mon, 26 Oct 2020 16:34:38 -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 S1788587AbgJZRwk (ORCPT + 99 others); Mon, 26 Oct 2020 13:52:40 -0400 Received: from foss.arm.com ([217.140.110.172]:46326 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1788579AbgJZRwh (ORCPT ); Mon, 26 Oct 2020 13:52:37 -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 43CD7139F; Mon, 26 Oct 2020 10:52:36 -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 B2B113F66E; Mon, 26 Oct 2020 10:52:34 -0700 (PDT) Date: Mon, 26 Oct 2020 17:52:31 +0000 From: Dave Martin To: Szabolcs Nagy Cc: Mark Rutland , systemd-devel@lists.freedesktop.org, Kees Cook , Catalin Marinas , Will Deacon , "linux-kernel@vger.kernel.org" , Jeremy Linton , Mark Brown , toiwoton@gmail.com, libc-alpha@sourceware.org, "linux-arm-kernel@lists.infradead.org" Subject: Re: BTI interaction between seccomp filters in systemd and glibc mprotect calls, causing service failures Message-ID: <20201026175230.GC27285@arm.com> References: <8584c14f-5c28-9d70-c054-7c78127d84ea@arm.com> <20201026162410.GB27285@arm.com> <20201026165755.GV3819@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201026165755.GV3819@arm.com> User-Agent: Mutt/1.5.23 (2014-03-12) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Oct 26, 2020 at 04:57:55PM +0000, Szabolcs Nagy via Libc-alpha wrote: > The 10/26/2020 16:24, Dave Martin via Libc-alpha wrote: > > Unrolling this discussion a bit, this problem comes from a few sources: > > > > 1) systemd is trying to implement a policy that doesn't fit SECCOMP > > syscall filtering very well. > > > > 2) The program is trying to do something not expressible through the > > syscall interface: really the intent is to set PROT_BTI on the page, > > with no intent to set PROT_EXEC on any page that didn't already have it > > set. > > > > > > This limitation of mprotect() was known when I originally added PROT_BTI, > > but at that time we weren't aware of a clear use case that would fail. > > > > > > Would it now help to add something like: > > > > int mchangeprot(void *addr, size_t len, int old_flags, int new_flags) > > { > > int ret = -EINVAL; > > mmap_write_lock(current->mm); > > if (all vmas in [addr .. addr + len) have > > their mprotect flags set to old_flags) { > > > > ret = mprotect(addr, len, new_flags); > > } > > > > mmap_write_unlock(current->mm); > > return ret; > > } > > if more prot flags are introduced then the exact > match for old_flags may be restrictive and currently > there is no way to query these flags to figure out > how to toggle one prot flag in a future proof way, > so i don't think this solves the issue completely. Ack -- I illustrated this model because it makes the seccomp filter's job easy, but it does have limitations. > i think we might need a new api, given that aarch64 > now has PROT_BTI and PROT_MTE while existing code > expects RWX only, but i don't know what api is best. An alternative option would be a call that sets / clears chosen flags and leaves others unchanged. The trouble with that is that the MDWX policy then becomes hard to implement again. But policies might be best set via another route, such as a prctl, rather than being implemented completely in a seccomp filter. Cheers ---Dave