Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp816819pxk; Wed, 23 Sep 2020 17:44:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzAmr88jh1PaaymYSckAcbKb2Rxr8Kj3pgp99FQvxSIbQkleMph8dFVg0zorSViEJHGJbWp X-Received: by 2002:a17:907:4276:: with SMTP id nq6mr2118006ejb.246.1600908261901; Wed, 23 Sep 2020 17:44:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600908261; cv=none; d=google.com; s=arc-20160816; b=hw1mWzMgGCSBzkP9+0AvKjfTUgdvnzRcN3L/SDQA08GuycUfrMlbjaLakCSM6EW/i4 0kRJ2AVgz96AKUaTRWcmHjsWuDdA716ksLLaE4gnNZIhl8+MELSnQvEqevSJA5HdJNbJ na9gjIOPqkw2PfFNr9nuhxl1CjFF2EutivE0yEHC1J9d+nqVeFSEqmxE08TIQK8GlOId pdvz/bP5Mh7J3neDr5RrZWOUg0iOz38Oe58dPioLQ91JC8GIpWhYPiBrPlNS2wMO/RWH LbK/viZXsN5MuV6oaA/Ln/J6y/6IxfqrqHZUTaOfu3XGTq47VEVd3YIxHEtMbZ/9r/uD 2CPQ== 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=ALS2hDm4ftsEUNq9TXFt06kpNHf/ZcV3y5aWx3s1Do8=; b=PiStXT9rP4TjUORKb3N6KSYFB1SyYQ5IBsggpP7otifl3AKw/6sS9MGApMr3fz+n2a wpQJPW5I5Y8owz7KWJ0lUTJaS0V1seIjSM3rny/iVnWQjdUheh8AM6+PXRt927Bk9JB8 /k/0VDXKdzeEf82ZMkzeK//s8p7f406eXgc9f6EfJuYzIGlvjOaAhkPoZen8KrjbeFlM KMpmzXfbjqkk8VkF1GGoy5PLjcFj0sB3tYxWEnz28Tph7gfSiVjyylF00YsmREEMCD+U yuL42Is00wkqoJyjb9kyKVwYus0FhRkr3IYudku/vQYOWVaIck7wo2TOoqno+R7mto9a NVlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=i+nBcw6Q; 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 j20si1078223eds.200.2020.09.23.17.43.58; Wed, 23 Sep 2020 17:44:21 -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=i+nBcw6Q; 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 S1726735AbgIXAmF (ORCPT + 99 others); Wed, 23 Sep 2020 20:42:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726466AbgIXAmF (ORCPT ); Wed, 23 Sep 2020 20:42:05 -0400 Received: from mail-ed1-x541.google.com (mail-ed1-x541.google.com [IPv6:2a00:1450:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BF5EC0613CE for ; Wed, 23 Sep 2020 17:42:04 -0700 (PDT) Received: by mail-ed1-x541.google.com with SMTP id j2so1597925eds.9 for ; Wed, 23 Sep 2020 17:42:04 -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=ALS2hDm4ftsEUNq9TXFt06kpNHf/ZcV3y5aWx3s1Do8=; b=i+nBcw6Qc5YdCSP79kchMxNZ9vscFmuRHIjL+4oM9aaVNrPeQ2J1fRTklh0kqsjyI1 N8NLB4IWr+D48TgWyYvZVuR18wkLSPfX8ovenzBJ4SrpdBaZGCKeG/X9PqlHe/AREy+G qo3TDDWtf6fkUtjt6XhYF7btCK2MTxIo9/4DEX+39YzOETzUS7wn6qaEXW02Fy7Nv7Sy iAhA3DJm5GB6uJspOdBYPqpCrSqmLiQJtt9QHxklrgcQ+yeDdyLYxkIwNF+ZXqK0GpPm VMI2uHMtk9t1HcUse8hr8ZqCv8PfIWNolN5O2CBcz/jLPmHK2IpxgDyi/+YWAMhYYGp8 Br8w== 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=ALS2hDm4ftsEUNq9TXFt06kpNHf/ZcV3y5aWx3s1Do8=; b=KsRk229vH/1R0LIiKx5NdXR70lDmqxgg+XuKXZ6vwXj8D1G3zEz7JuuZeqrftW6UMe Dj2WyCshCEird6HHGhWm+/WVCc9Mz/xIvLjNcFIqHp5Y0uq74DCISSgbUN9h/RaRhBSJ 2aqB8Skxovbgajc1WPzF/c+dg+3HnKQqLgg940dI2YsXh1q7ttRhajW1J4/lccjEJdHH FH/MjfWiUd8pGEAQGwe8Ja/n9TC9azWeh37P/PZ2zI41e51Bw1WKXeTx6qCok8kiefMD 7RZQ1bVuMDNOjv/FNzMGj/wKqrJxS/AfP5xUP7tlxvTNby1WTaQIwnYltmVeLk7oxzPy EKXw== X-Gm-Message-State: AOAM530LuPNkjEYkKn2S1ee6zOzg+NKsYR9Ib/t1Q2ewX4ueIdCb0ZE8 AQxCxjBRc4bptkMDmKwGNliA4WYdtKLUlm51b6mxtg== X-Received: by 2002:a50:e807:: with SMTP id e7mr2071571edn.84.1600908123101; Wed, 23 Sep 2020 17:42:03 -0700 (PDT) MIME-Version: 1.0 References: <20200923232923.3142503-1-keescook@chromium.org> <20200923232923.3142503-2-keescook@chromium.org> In-Reply-To: <20200923232923.3142503-2-keescook@chromium.org> From: Jann Horn Date: Thu, 24 Sep 2020 02:41:36 +0200 Message-ID: Subject: Re: [PATCH 1/6] seccomp: Introduce SECCOMP_PIN_ARCHITECTURE To: Kees Cook Cc: YiFei Zhu , Christian Brauner , Tycho Andersen , Andy Lutomirski , Will Drewry , Andrea Arcangeli , Giuseppe Scrivano , Tobin Feldman-Fitzthum , Dimitrios Skarlatos , Valentin Rothberg , Hubertus Franke , Jack Chen , Josep Torrellas , Tianyin Xu , bpf , Linux Containers , Linux API , kernel list Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 24, 2020 at 1:29 AM Kees Cook wrote: > For systems that provide multiple syscall maps based on audit > architectures (e.g. AUDIT_ARCH_X86_64 and AUDIT_ARCH_I386 via > CONFIG_COMPAT) or via syscall masks (e.g. x86_x32), allow a fast way > to pin the process to a specific syscall table, instead of needing > to generate all filters with an architecture check as the first filter > action. > > This creates the internal representation that seccomp itself can use > (which is separate from the filters, which need to stay runtime > agnostic). Additionally paves the way for constant-action bitmaps. I don't really see the point in providing this UAPI - the syscall number checking will probably have much more performance cost than the architecture number check, and it's not like this lets us avoid the check, we're just moving it over into C code. > Signed-off-by: Kees Cook > --- > include/linux/seccomp.h | 9 +++ > include/uapi/linux/seccomp.h | 1 + > kernel/seccomp.c | 79 ++++++++++++++++++- > tools/testing/selftests/seccomp/seccomp_bpf.c | 33 ++++++++ > 4 files changed, 120 insertions(+), 2 deletions(-) > > diff --git a/include/linux/seccomp.h b/include/linux/seccomp.h > index 02aef2844c38..0be20bc81ea9 100644 > --- a/include/linux/seccomp.h > +++ b/include/linux/seccomp.h > @@ -20,12 +20,18 @@ > #include > #include > > +#define SECCOMP_ARCH_IS_NATIVE 1 > +#define SECCOMP_ARCH_IS_COMPAT 2 FYI, mips has three different possible "arch" values (per kernel build config; the __AUDIT_ARCH_LE flag can also be set, but that's fixed based on the config): - AUDIT_ARCH_MIPS - AUDIT_ARCH_MIPS | __AUDIT_ARCH_64BIT - AUDIT_ARCH_MIPS | __AUDIT_ARCH_64BIT | __AUDIT_ARCH_CONVENTION_MIPS64_N32 But I guess we can deal with that once someone wants to actually add support for this on mips. > +#define SECCOMP_ARCH_IS_MULTIPLEX 3 Why should X32 be handled specially? If the seccomp filter allows specific syscalls (as it should), we don't have to care about X32. Only in weird cases where the seccomp filter wants to deny specific syscalls (a horrible idea), X32 is a concern, and in such cases, the userspace code can generate a single conditional jump to deal with it. And when seccomp is used properly to allow specific syscalls, the kernel will just waste time uselessly checking this X32 stuff. [...] > diff --git a/kernel/seccomp.c b/kernel/seccomp.c [...] > +static long seccomp_pin_architecture(void) > +{ > +#ifdef SECCOMP_ARCH > + struct task_struct *task = current; > + > + u8 arch = seccomp_get_arch(syscall_get_arch(task), > + syscall_get_nr(task, task_pt_regs(task))); > + > + /* How did you even get here? */ Via a racing TSYNC, that's how. > + if (task->seccomp.arch && task->seccomp.arch != arch) > + return -EBUSY; > + > + task->seccomp.arch = arch; > +#endif > + return 0; > +} Why does this return 0 if SECCOMP_ARCH is not defined? That suggests to userspace that we have successfully pinned the ABI, even though we're actually unable to do so.