Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp2538227pxu; Fri, 9 Oct 2020 22:07:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwD0KHfl+8KvL/y2rMkdeVqXuuW7oP+k6cTsO6p9htVZjC9gk6/w/cSm3QC3wU7IPHhQBu5 X-Received: by 2002:a05:6402:187:: with SMTP id r7mr2654629edv.360.1602306463237; Fri, 09 Oct 2020 22:07:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602306463; cv=none; d=google.com; s=arc-20160816; b=FojsztKmsiAmlZ1ZU+sNjIY2mSdSVU6MpWouuD8cLfwlbWBVhuTV0wdkQrnnLd+Yb8 woC/YaGOBxJL22b/O/1Vazyj9H3XzNOgMzdbDk1h9jT4z+i0z3qNiqV+C/jYXqr57Q+K 1dB8num6kyre/2Ick78reizFbjYjlF8iPqQpfH93s2kHCzXr/tsrEMfxlqMqE5V8Uzch LJWUHJ9QhpNQNS0wvtEKqtp00e3fDtnMHaUpGqJt5kjQLfD7NElVdH32m+zJcIXaU/ep 4EGlLhaQQwG+KkG6846U8zxTtrXk9vAvyTIYHoJha2hW35kPZNWnfexF93+q5cmF3LkD uKeA== 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=M3QASBM0PyBqWV4qYi2/juWl30Ro5T5ehsILkUh0Mms=; b=F6Dbn80Q3H/1LjE1JpOZsPfJwgPGLtdxIo1uE5Qvw9TvUjJe70Lma97r+2a02RFfV7 ks5/5JnF/cMzOXyNdOhbDZqpJonCx90lCTW6I6n7ObzXSrm1vYVFmAJw2q5bywTCr2N9 OpDx0cUZm5rdl7lGQ0as8YVdiUdCEVjpXuhUKq6zVYp3iyvZy4FFtli/cJE8EZFZfVwQ GiNxPr03TC2URiVmd9jiDrcCL2NWkKYDbP9b+fFb78XsRpifv8/6Y0zlQAzgm3iVms1o 4LAIFUNQtkZdo42MTx/8X8wsyoQ0tMP7Es60Sb/Qf9F8RX3LKCR4ny4FMHLLn9U4aX/3 ertw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=VeVHFmly; 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 t24si7603575ejd.39.2020.10.09.22.07.20; Fri, 09 Oct 2020 22:07:43 -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=VeVHFmly; 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 S2389116AbgJIVp3 (ORCPT + 99 others); Fri, 9 Oct 2020 17:45:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732056AbgJIVp2 (ORCPT ); Fri, 9 Oct 2020 17:45:28 -0400 Received: from mail-ej1-x642.google.com (mail-ej1-x642.google.com [IPv6:2a00:1450:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B4DDC0613D2 for ; Fri, 9 Oct 2020 14:45:28 -0700 (PDT) Received: by mail-ej1-x642.google.com with SMTP id h24so15162099ejg.9 for ; Fri, 09 Oct 2020 14:45:28 -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=M3QASBM0PyBqWV4qYi2/juWl30Ro5T5ehsILkUh0Mms=; b=VeVHFmlydw44XMQ0jlUmjz9257sBoMcSb5kNBMm+/I8yNF1mq+Isl0FguqOpyiZKE/ Y+aPx4AUvkVLLePrLlaTWIQ31nAAC9X4APGGLo3mVwcz+Vy9L7qQXJU9USVA/1alpFOc igtne+lu0FvEXxR4DTncx4DdoY4ADZqHTALlTUsbGyugfoOvGSc2sMtuIop4N0/FZhQQ esRZ6kzNRqnZ5zg27AN3U6lj8G19zmAlHXNVazZJ+AbThUZjti1lfTGrMftco6w+V00D yQ7y3Ce6BYhi1fynlsr0e4dzvttbb8ZD+yXjcskUQwKBwsX8dRJR8UY+UiO3wVY/Xywj xSRA== 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=M3QASBM0PyBqWV4qYi2/juWl30Ro5T5ehsILkUh0Mms=; b=sIhHdPJOTKWROBkp9acMqZARj6NiEEaDB8J0dPWQIpaimaGyrkuXFM9olHCLZcJN5W Wjr4Cwx2OHaS1J5KDecWnIfWIljEco91bXOPvLUdh2IMLuK/fs+EsGNgTdya6LtIauoW JCBkPaFO+pI5jf6+JB8kwDuLZccFfcnjm7Hv7IREnDpIkckLq8zxazSOgURkVj/73ead U3tzzB2+h3Mz0YkAIDzoE7hMT96Yb7zNBKHdmwnB1B/Oqswb8nXwhiksOZWIC7I1Ewp/ j/fI9re3vqB1VsZiGqWsVwsm6iO50ygMOIByuxS4WJY97Q6YbaYjelOfvZsMyL0DorC4 mKuA== X-Gm-Message-State: AOAM5335aGahEkdVmf5Djv7YvV6xYxxfx3MNcniSGINeny3hUJNhBbOJ uUwERQKR7sxjvlk2YhIu+gvknbOPhwWuIe/zK/1mgg== X-Received: by 2002:a17:906:394:: with SMTP id b20mr15967989eja.513.1602279926518; Fri, 09 Oct 2020 14:45:26 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Jann Horn Date: Fri, 9 Oct 2020 23:45:00 +0200 Message-ID: Subject: Re: [PATCH v4 seccomp 5/5] seccomp/cache: Report cache data through /proc/pid/seccomp_cache To: YiFei Zhu Cc: Linux Containers , YiFei Zhu , bpf , kernel list , Aleksa Sarai , Andrea Arcangeli , Andy Lutomirski , David Laight , Dimitrios Skarlatos , Giuseppe Scrivano , Hubertus Franke , Jack Chen , Josep Torrellas , Kees Cook , Tianyin Xu , Tobin Feldman-Fitzthum , Tycho Andersen , Valentin Rothberg , Will Drewry Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 9, 2020 at 7:15 PM YiFei Zhu wrote: > Currently the kernel does not provide an infrastructure to translate > architecture numbers to a human-readable name. Translating syscall > numbers to syscall names is possible through FTRACE_SYSCALL > infrastructure but it does not provide support for compat syscalls. > > This will create a file for each PID as /proc/pid/seccomp_cache. > The file will be empty when no seccomp filters are loaded, or be > in the format of: > > where ALLOW means the cache is guaranteed to allow the syscall, > and filter means the cache will pass the syscall to the BPF filter. > > For the docker default profile on x86_64 it looks like: > x86_64 0 ALLOW > x86_64 1 ALLOW > x86_64 2 ALLOW > x86_64 3 ALLOW > [...] > x86_64 132 ALLOW > x86_64 133 ALLOW > x86_64 134 FILTER > x86_64 135 FILTER > x86_64 136 FILTER > x86_64 137 ALLOW > x86_64 138 ALLOW > x86_64 139 FILTER > x86_64 140 ALLOW > x86_64 141 ALLOW > [...] > > This file is guarded by CONFIG_SECCOMP_CACHE_DEBUG with a default > of N because I think certain users of seccomp might not want the > application to know which syscalls are definitely usable. For > the same reason, it is also guarded by CAP_SYS_ADMIN. > > Suggested-by: Jann Horn > Link: https://lore.kernel.org/lkml/CAG48ez3Ofqp4crXGksLmZY6=fGrF_tWyUCg7PBkAetvbbOPeOA@mail.gmail.com/ > Signed-off-by: YiFei Zhu [...] > diff --git a/arch/Kconfig b/arch/Kconfig [...] > +config SECCOMP_CACHE_DEBUG > + bool "Show seccomp filter cache status in /proc/pid/seccomp_cache" > + depends on SECCOMP > + depends on SECCOMP_FILTER > + depends on PROC_FS > + help > + This is enables /proc/pid/seccomp_cache interface to monitor nit: s/This is enables/This enables the/ > + seccomp cache data. The file format is subject to change. Reading > + the file requires CAP_SYS_ADMIN. > + > + This option is for debugging only. Enabling present the risk that nit: *presents > + an adversary may be able to infer the seccomp filter logic. [...] > +int proc_pid_seccomp_cache(struct seq_file *m, struct pid_namespace *ns, > + struct pid *pid, struct task_struct *task) > +{ > + struct seccomp_filter *f; > + unsigned long flags; > + > + /* > + * We don't want some sandboxed process know what their seccomp s/know/to know/ > + * filters consist of. > + */ > + if (!file_ns_capable(m->file, &init_user_ns, CAP_SYS_ADMIN)) > + return -EACCES; > + > + if (!lock_task_sighand(task, &flags)) > + return 0; maybe return -ESRCH here so that userspace can distinguish between an exiting process and a process with no filters? > + f = READ_ONCE(task->seccomp.filter); > + if (!f) { > + unlock_task_sighand(task, &flags); > + return 0; > + } [...]