Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3364866pxk; Mon, 21 Sep 2020 11:40:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwMN70u9XxIQclHDa+qt+oPuU21UMZWA2DRG3Y/+9k+3DdODrX1cg/jGRz0JElFt6/LCo7p X-Received: by 2002:a17:906:95cf:: with SMTP id n15mr928210ejy.14.1600713631601; Mon, 21 Sep 2020 11:40:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600713631; cv=none; d=google.com; s=arc-20160816; b=QLKAH+1V5/u42itcDj5R5q4EjSAkui6zy83ud+NSDFQIwLCoPNxs08lLVI+DGWEJ29 sepx3MS2z/8kacGNXVN6iaVi4zWAU/GO1ru3+0wAa48JQhQWWmFI6FfoPkb9N1TDAUvC JVushNu/OF+AFN0qsSWgd2KwI1KvvEljmC0c2/a3CmRAXrNbBut/3Lv/i0X0gL5GMDI6 chmHwhBSTfGVK5KiEhd5aTQUN2Y19/RS8RvF1+/30SE78xo61Fhje8EGlAxrtyydAHfO LxLM8vahVhh8raxxYA5tkkEoj+KKnCTIz1uTzSsgoAN2kaT0lt5dUfbEI4IqJBwSy3T3 oTpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=C7G6A5IlEG2WC0nmoX7XdAtZ+v2I/zqqDO0euVW1SNE=; b=fh7DnO05AKk1H0+M3J6mDNsRzrUZgCSIOoy1d7keS9e5zIE7/mI60k5XObGXGWh0BJ L5P5Vn2+Cdxr1J5kfeKrzpWQ4OMsFETxWBNRXmn9kUYEc+gnDAXQrIHlzEQrBO3XFGYq RKYU0i419vwTwXO67KM725kSOy1Yp9KLrsOS0UoeuBkx4KhRdgJoUWfF2ANPrN+vGb1b aNzWeVyi963YmVZ9o2/IU3JlKBzy4lLjPwDxrDMTN0Al2ISuBSlP4CMcmKchXhRFHaws IrpgT1opphT8YcOEftxgZwG3jUxnuYKZvHP/3kDMG6baDc3raMcZtqYJKq2EL8TRCs4J 18pA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=GKj3LJZb; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n23si8515715edv.598.2020.09.21.11.40.08; Mon, 21 Sep 2020 11:40:31 -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=@google.com header.s=20161025 header.b=GKj3LJZb; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727455AbgIUSim (ORCPT + 99 others); Mon, 21 Sep 2020 14:38:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726456AbgIUSim (ORCPT ); Mon, 21 Sep 2020 14:38:42 -0400 Received: from mail-ed1-x543.google.com (mail-ed1-x543.google.com [IPv6:2a00:1450:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8874C061755 for ; Mon, 21 Sep 2020 11:38:41 -0700 (PDT) Received: by mail-ed1-x543.google.com with SMTP id k14so13860994edo.1 for ; Mon, 21 Sep 2020 11:38:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=C7G6A5IlEG2WC0nmoX7XdAtZ+v2I/zqqDO0euVW1SNE=; b=GKj3LJZbIecljJchWIPsVbgqFMg87glRuzFxDZUSnJCVadINrRQoPekzrtKM6pXFG4 jWmJoGWdPsML6lH9FjKOKPIrPw63/cKOhXUp5e0TPpKeUNin829jFNlYXC5LjVUi7psX Q8fipqI46lZkA3SDqje4ta/W4Eh+vI3SKfAi5yGK5526zHVe4lUCgrqmAQiiqMQXKcXP 2qWHELpxN3jG2I/YmRVE/92CZfYkjr2vDdMUrejhZq+rTTRxVVnar1vEZXkj/I4Nld8N b5fF2BDFiRGJmzlxKgzu9iX8XLxJoLdMWZl0/TkOILYMjMeMo1Mmy0vuKiMc4RKUduOk a9ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=C7G6A5IlEG2WC0nmoX7XdAtZ+v2I/zqqDO0euVW1SNE=; b=MbHILcZ5n+jRSfvrGWWjFCNM+YQSqqASrP08FJS/Xw3NyS61pxFTy5XBd7UmLP7qLY 8kHTcKVcVSdtDpsVofAZAHkCqqeTtrR6UwJ2JjoayCa/NcMzyTDRNhmCCoIE/ra9MtxH v3xAauXMXaopN5yeDvPCk00PBmtBqz7s0FKGuu6OWD/e7wvsjfC9G/IRmq0uRtEB8zV3 T5LCBMbVuIdIT+A4ZUa+JDJsiIUwvFb1z4Gay6MrcrRJaP6oPCS8+Hr8RamSSuzk+QPI 3G9YonaU0HJfDoLRzyxnbh82edn3zzJzWRxpkbQRv7rnT38a3bkfWURYNFWBBXHwudvE m1mA== X-Gm-Message-State: AOAM531rbjy7M9DEZ9HwRvwVtzUOA6NHFUkkhRZiJecA9taTL/hKNjBu gbVq5fAPXYq8ELOeamKE5HXJi12ZYRyIMYk9uijMtg== X-Received: by 2002:a05:6402:176c:: with SMTP id da12mr281928edb.386.1600713520102; Mon, 21 Sep 2020 11:38:40 -0700 (PDT) MIME-Version: 1.0 References: <6af89348c08a4820039e614a090d35aa1583acff.1600661419.git.yifeifz2@illinois.edu> In-Reply-To: From: Jann Horn Date: Mon, 21 Sep 2020 20:38:11 +0200 Message-ID: Subject: Re: [RFC PATCH seccomp 1/2] seccomp/cache: Add "emulator" to check if filter is arg-dependent To: YiFei Zhu Cc: Linux Containers , YiFei Zhu , bpf , Andrea Arcangeli , Dimitrios Skarlatos , Giuseppe Scrivano , Hubertus Franke , Jack Chen , Josep Torrellas , Kees Cook , Tianyin Xu , Tobin Feldman-Fitzthum , Valentin Rothberg , Andy Lutomirski , Will Drewry , Aleksa Sarai , kernel list Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 21, 2020 at 7:47 PM Jann Horn wrote: > On Mon, Sep 21, 2020 at 7:35 AM YiFei Zhu wrote: > > SECCOMP_CACHE_NR_ONLY will only operate on syscalls that do not > > access any syscall arguments or instruction pointer. To facilitate > > this we need a static analyser to know whether a filter will > > access. This is implemented here with a pseudo-emulator, and > > stored in a per-filter bitmap. Each seccomp cBPF instruction, > > aside from ALU (which should rarely be used in seccomp), gets a > > naive best-effort emulation for each syscall number. > > > > The emulator works by following all possible (without SAT solving) > > paths the filter can take. Every cBPF register / memory position > > records whether that is a constant, and of so, the value of the > > constant. Loading from struct seccomp_data is considered constant > > if it is a syscall number, else it is an unknown. For each > > conditional jump, if the both arguments can be resolved to a > > constant, the jump is followed after computing the result of the > > condition; else both directions are followed, by pushing one of > > the next states to a linked list of next states to process. We > > keep a finite number of pending states to process. > > Is this actually necessary, or can we just bail out on any branch that > we can't statically resolve? Aaaah, now I get what's going on. You statically compute a bitmask that says whether a given syscall number always has a fixed result *per architecture number*, and then use that later to decide whether results can be cached for the combination of a specific seccomp filter and a specific architecture number. Which mostly works, except that it means you end up with weird per-thread caches and you get interference between ABIs (so if a process e.g. filters the argument numbers for syscall 123 in ABI 1, the results for syscall 123 in ABI 2 also can't be cached). Anyway, even though this works, I think it's the wrong way to go about it.