Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp119604ybg; Sun, 31 May 2020 18:56:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy1RqHn9Wi0QdgEv8PBKelJmg0V6hPod47A8axdMFqe8txcr2AFOWu4Wdy32YoTnr66/oWr X-Received: by 2002:a17:906:2b04:: with SMTP id a4mr18016087ejg.98.1590976562662; Sun, 31 May 2020 18:56:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590976562; cv=none; d=google.com; s=arc-20160816; b=comJ/+Eaiymy4p4e+pyAAfBSsXK7QjVq3fROmaELllrX7sdY7hFaxr4ri7+LJKmX6L hpxM1TDa6nFIX1ahF5Fz3y7pi0gwrMKvav4Vv3rI15YTqwj5JxYkX+ubxo8noFKcBEpE Sv32ZNCoiQKtubyiRV0sapxnjgHEdy4T1M3EKSmko19MWx+i227dd7wcxDnTeAmLs8Nt GGj7xYg8SSzK7Tv/g9GJpOEBj43ZDyy1Fw0Zlv2kilxrQt7KOZoj5rziitNiIGTjS/60 ht0FUsdl+dtxdLF1FLpJFx+gPM2daxrhv1XLAG5opa8V8bHXvYNw7V+FnrrLtBl0gmdj frZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:in-reply-to:cc:references:message-id :date:subject:mime-version:from:content-transfer-encoding :dkim-signature; bh=9dXvtk/r9WWB0K0puzQusMZ/JsqoKiWxqlF1sGJrjWc=; b=KV0w0G1A5OAQuh5ZRKEd95AOL9mkmfepfjzpcM5ZmUU9mg+afdRhtEjcggayUt0fAJ NrcQ56XoVJDP2vwPFg/oNaUjwKPtYO96VGvQ2+5TEoq6nLorkh0Fw+2sRECuvaImNRL9 7LtN2AA0F6e76uEZkh4/sEXi574ZvN7CObZFqDxNlMxXQdAatandO9I5+UJOZmiwsmhQ 9YO47/Ab+G4Ta2DUsMSofuNTptZOyg1kotdrGXJoXUniChwTGVG0zToPRJxt8ejCL1HK 3WRbHlmEwvTUddw2sIOqos8YfTV7wJN9cjZd4oBehHzZem0CXoBqgIkY1qbwb/hSXrdJ 889A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=pP05YEqI; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n60si10844134edc.186.2020.05.31.18.55.39; Sun, 31 May 2020 18:56: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=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=pP05YEqI; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727004AbgFABvq (ORCPT + 99 others); Sun, 31 May 2020 21:51:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726555AbgFABvp (ORCPT ); Sun, 31 May 2020 21:51:45 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA63FC061A0E for ; Sun, 31 May 2020 18:51:44 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id t8so4228865pju.3 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=X7aT3y9XU85OKLYbF/Ot/2T1BEn0juLg6fJV/p/K527OuBJDqiKcQM3jyiP0gE068P t8jm3qv9iWjgAZ3/DuX8YWxZk+i/i5fJoiVefYOMV9Ivrz2tAnqUA/Vlp9dmoirb1cuz +vIX4+v9XprUE45rI7L5Ck2PEnYiad8cG3WO5xFrXTh9vafcQN0kAIPOQcdQDg2RKfaJ fj9sA0UphkJhxvI/gD/YsyHfmhHyjCsU1VKBUzH2J1fghyUUQZWDfJG3nls/gEowsETL FPstQ+kRErsxTmE+7n+4TszvZ2dxOZ6hGqJNLA68tY+W62CGG9jDzZkMLHef9RKabuEO PfEA== X-Gm-Message-State: AOAM532JTxuCVRkba5Ecig+MkVq4kaUpiV8tRMxoZOwTQ+d8i4nikP/A TD83Ilt4cnGWIRdZLt63AMhATQ== 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) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > 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.=