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=-5.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 B8E06C433DF for ; Mon, 1 Jun 2020 01:51:46 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5D15520679 for ; Mon, 1 Jun 2020 01:51:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=amacapital-net.20150623.gappssmtp.com header.i=@amacapital-net.20150623.gappssmtp.com header.b="pP05YEqI" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5D15520679 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amacapital.net Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A7F5A8E0006; Sun, 31 May 2020 21:51:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A088D8E0003; Sun, 31 May 2020 21:51:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8AA3C8E0006; Sun, 31 May 2020 21:51:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0181.hostedemail.com [216.40.44.181]) by kanga.kvack.org (Postfix) with ESMTP id 6C4BA8E0003 for ; Sun, 31 May 2020 21:51:45 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 2CC4A181AEF07 for ; Mon, 1 Jun 2020 01:51:45 +0000 (UTC) X-FDA: 76878966570.07.snail54_2c5a3b9405227 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin07.hostedemail.com (Postfix) with ESMTP id 1188A1803F9A2 for ; Mon, 1 Jun 2020 01:51:45 +0000 (UTC) X-HE-Tag: snail54_2c5a3b9405227 X-Filterd-Recvd-Size: 6441 Received: from mail-pl1-f193.google.com (mail-pl1-f193.google.com [209.85.214.193]) by imf38.hostedemail.com (Postfix) with ESMTP for ; Mon, 1 Jun 2020 01:51:44 +0000 (UTC) Received: by mail-pl1-f193.google.com with SMTP id i17so3584924pli.13 for ; Sun, 31 May 2020 18:51:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amacapital-net.20150623.gappssmtp.com; s=20150623; h=content-transfer-encoding:from:mime-version:subject:date:message-id :references:cc:in-reply-to:to; bh=9dXvtk/r9WWB0K0puzQusMZ/JsqoKiWxqlF1sGJrjWc=; b=pP05YEqIkQxAyG4vYCDW80FpHLOizHA6onXy4Gwo4itfkUonGPoNe26IGRJawn+vDB 6xm/XLtQIvd+VQShZDf/Lv3ABN0+/LsR6M7s+H96gvXg+EBop8epLWjtsuYq46KvOk6n 0QAYtfeNxq8zpoHHI7TeM6HMKXRoigU3xvB/McCFShyraP6f0r1ISOFaKqh0YNZGtdjZ wZczeBqxjU0vErzv+Iy4JsQ6XPGHLgIBBCvsRaezOCahPeBHGKTOcN05q8++ARzlZQb0 TTj9wruO2IrFSTpw5CM/mz1LXI0BqFCN0aI6is75wz/0plhkA6m5LDVZG0hXUAIt518h bmMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:content-transfer-encoding:from:mime-version :subject:date:message-id:references:cc:in-reply-to:to; bh=9dXvtk/r9WWB0K0puzQusMZ/JsqoKiWxqlF1sGJrjWc=; b=dQ8Sxy92c5Olzi9+Lnm0cSnw3s5ICnmx69HTgk/ThAeJcMQZQ8fjmjjXyRDiCRYu7a TTshyHkX8/mDgRcjr+DJuZXFUyKDV4uIZi7rDEyJ2CCarVR4XEG2yNEPTgDvdKDTJSi8 DEFpPvSJtql9ttaXKGBqIQkhkTzry7GcVf17BBh/jgI2BVG3BpvTL4I9zfWO3HqjTPVX tUsojYxS52Wdju5zlu2EONmScj1w42kfBNHe+JSe7k3B4yA+dPee9ypW2U+3D2gCT+1M JnDMf1nyUs9kfHY2U91sfpeObZL53NCkOSX7Z9REg/4bBYfIeY7IfeeVIMQwbpv5vfP5 dR9w== X-Gm-Message-State: AOAM531OsY5tga7jI1miQ3o036/DJC44x0hEmBGTq8nT5LyMcYGUA6J7 7ohOmHyj4uYuSqH2DtNT8aVwWg== X-Google-Smtp-Source: ABdhPJyKdBvCLHLO/yUYp1MwzbdySIcglCWzDBtFYs8Uw6OMa2V55Q7KwEVOfGOGHmAQaeQTvnAfvg== X-Received: by 2002:a17:902:e903:: with SMTP id k3mr17628008pld.317.1590976303529; Sun, 31 May 2020 18:51:43 -0700 (PDT) Received: from ?IPv6:2601:646:c200:1ef2:1d33:1e7d:661b:bcd4? ([2601:646:c200:1ef2:1d33:1e7d:661b:bcd4]) by smtp.gmail.com with ESMTPSA id q28sm12946145pfg.180.2020.05.31.18.51.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 31 May 2020 18:51:42 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: Andy Lutomirski Mime-Version: 1.0 (1.0) Subject: Re: [PATCH RFC] seccomp: Implement syscall isolation based on memory areas Date: Sun, 31 May 2020 18:51:40 -0700 Message-Id: <53C0BD81-A942-4BB3-8538-D5107E84C5CD@amacapital.net> References: <8DF2868F-E756-4B33-A7AE-C61F4AB9ABB9@codeweavers.com> Cc: Andy Lutomirski , Paul Gofman , Gabriel Krisman Bertazi , Linux-MM , LKML , kernel@collabora.com, Thomas Gleixner , Kees Cook , Will Drewry , "H . Peter Anvin" , Zebediah Figura In-Reply-To: <8DF2868F-E756-4B33-A7AE-C61F4AB9ABB9@codeweavers.com> To: Brendan Shanks X-Mailer: iPhone Mail (17E262) X-Rspamd-Queue-Id: 1188A1803F9A2 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam03 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: > On May 31, 2020, at 4:50 PM, Brendan Shanks wrot= e: >=20 > =EF=BB=BF >> On May 31, 2020, at 11:57 AM, Andy Lutomirski wrote: >>=20 >> Using SECCOMP_RET_USER_NOTIF is likely to be considerably more >> expensive than my scheme. On a non-PTI system, my approach will add a >> few tens of ns to each syscall. On a PTI system, it will be worse. >> But using any kind of notifier for all syscalls will cause a context >> switch to a different user program for each syscall, and that will be >> much slower. >=20 > There=E2=80=99s also no way (at least to my understanding) to modify regis= ter state from SECCOMP_RET_USER_NOTIF, which is how the existing -staging SI= GSYS handler works: >=20 > >=20 >> I think that the implementation may well want to live in seccomp, but >> doing this as a seccomp filter isn't quite right. It's not a security >> thing -- it's an emulation thing. Seccomp is all about making >> inescapable sandboxes, but that's not what you're doing at all, and >> the fact that seccomp filters are preserved across execve() sounds >> like it'll be annoying for you. >=20 > Definitely. Regardless of what approach is taken, we don=E2=80=99t want it= to persist across execve. >=20 >> What if there was a special filter type that ran a BPF program on each >> syscall, and the program was allowed to access user memory to make its >> decisions, e.g. to look at some list of memory addresses. But this >> would explicitly *not* be a security feature -- execve() would remove >> the filter, and the filter's outcome would be one of redirecting >> execution or allowing the syscall. If the "allow" outcome occurs, >> then regular seccomp filters run. Obviously the exact semantics here >> would need some care. >=20 > Although if that=E2=80=99s running a BPF filter on every syscall, wouldn=E2= =80=99t it also incur the ~10% overhead that Paul and Gabriel have seen with= existing seccomp? >=20 >=20 Unlikely. Some benchmarking is needed, but the seccomp ptrace overhead is li= kely *huge* compared to the overhead of just a filter. As wild guess numbers on made up modern hardware, cache hot: Empty syscall: 50ns, or 300ns with PTI Empty syscall accepted by simple seccomp filter: 10ns more than an empty sys= call without seccomp Seccomp ptrace round trip: 6 us Worse with PTI Seccomp user notif round trip: 4 us Syscall hypothetically redirected back to same process: about the same as an= empty filtered accepted syscall, plus however long it takes to run the hand= ler. Add 900ns if using SIGSYS instead of plain redirection. Add an extra 50= 0ns on current kernels because signal delivery sucks, but I can fix this. Take these numbers with a huge grain of salt. But the point is that the BPF= part is the least of your worries.=