Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2256915ybt; Tue, 16 Jun 2020 00:54:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxnFIOjPiYynxN5+U+H9yaSLrIFUJaNUWSq4jJAYdww05ogrZbtzD9pdnJ8OgybW9QpIMwJ X-Received: by 2002:a17:906:5203:: with SMTP id g3mr1570638ejm.58.1592294096746; Tue, 16 Jun 2020 00:54:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592294096; cv=none; d=google.com; s=arc-20160816; b=w96uV6kBs2kzttvQwoRfGlL0G8y20ChtemFeAOr8bLvH1mggVKd130dP5jalic2+u6 vSgHZIf1ocSFETqSN5IeJFuy4V2xbTQHZz4YbX1TCPz7szihGsr83A0YQ0AkGi99MMK/ e0SJqoL2BaL6U4nhVLBIHwgOFsCQDu++yPipGlSfxC9uX2MvaZA28CRJyTVusQhNT+bm aGuC2m8sWVpEh1mCyHecYEzUCQlSUZRvcQ4UBgFxsTBb/2+um1KAqDrTjwR9k4gKpuGb VwE9Pa065NKsH3mhlhJo3RnAoSLWRePDmQAq89IueS21+xfmAfWInnnCC3s03XdQj965 TrVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=CiCnefOEfqSi7wYDZ0Ly9qFUXTY1JQW6i7HQc69RyoQ=; b=TjCjU6+cg+EW6mv0Y+++XaSa7F5qi0ELVCLBj2a5w/Llqwq4NVec4SXCtPPhVQHdLR 5mUaDvgB6HhDSEcY6onSlhgsbZmAUgob4dk0+yUWniSI5rAOtyhKLMQ5tNmbnWixRleX 3WKmui+eSm6vuj+LyVnHmy0eSnCbRsgZumL5sBaoEo8T+o7f/A4/tYL1j96ZOSQ36d/n 0IMGKMCsxxtt8UgK+S+NbtUxJsss2LUyA9huEReHmEu6bDNp3U8fwkdpoBRiTlmbLX0Y uZwrZ7tVNbuU7YysNzQ7UOPCAQ2q+tvcY2hyAlDh/eGV0eWk/YTEmKsiu67TX8tw3cbx 2ekw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=IcgNnBPc; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y21si10025785edt.501.2020.06.16.00.54.34; Tue, 16 Jun 2020 00:54:56 -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=@chromium.org header.s=google header.b=IcgNnBPc; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727083AbgFPHu1 (ORCPT + 99 others); Tue, 16 Jun 2020 03:50:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726641AbgFPHts (ORCPT ); Tue, 16 Jun 2020 03:49:48 -0400 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E722C08C5C4 for ; Tue, 16 Jun 2020 00:49:45 -0700 (PDT) Received: by mail-pl1-x62c.google.com with SMTP id x11so2617833plo.7 for ; Tue, 16 Jun 2020 00:49:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CiCnefOEfqSi7wYDZ0Ly9qFUXTY1JQW6i7HQc69RyoQ=; b=IcgNnBPcUI4XxaHRZv+68h1umX7cyvIMCP36Q7y+O5a5sA6ytY5XtslKRv21o3+cf9 X+FMmnNEztj2FpFUzVzclsbAf//w6fXPH21coPI4d9FweeYzdb0yM25T7mcIhl6EITHx x7tTwGEQtIjtktlXFsLdB31FXf9xbkZG5U6Uk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CiCnefOEfqSi7wYDZ0Ly9qFUXTY1JQW6i7HQc69RyoQ=; b=rBwVHVdRqQdnQoByhRTE/I36+XIg6n5fuLqiW5bE0PkAlU0yD5bIL+tIc//uDEyjCl dR3n1wZ3DIOibYdM5Jd3JDNb/hGxGzv82VInH9v9DW3PeMlbNlOwLLxkZW8t1Hz3T/6/ MPG16S+HCBPan6LnYKzt1Y8rcs4IjLn1557s3CRjHcbqMLZY2NzlUrbPKaGm5ljO4zVn NnbBSBIrFF9u2KWDNjzarn7J+iwvMqRBwitS7vb99rvwGUxIOExzgXOX9+JkQIOlm3sY C5jwrU66l7iSMUFCBu2R7mgnFIGAKOhc983PWbACrvvFgvyQfeSQw/w5foG0obdbORO9 H38Q== X-Gm-Message-State: AOAM530322daf6cNUDBvIc6PUGsagWf/K+6EktXafKnWpC7AuFmYSKhG ywtAfjAYubmfE9meO2pa2UdmOw== X-Received: by 2002:a17:90a:4d4e:: with SMTP id l14mr1619537pjh.10.1592293784832; Tue, 16 Jun 2020 00:49:44 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id z1sm1612258pjz.10.2020.06.16.00.49.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jun 2020 00:49:42 -0700 (PDT) From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Kees Cook , Andy Lutomirski , Will Drewry , Christian Brauner , Sargun Dhillon , Tycho Andersen , Jann Horn , "zhujianwei (C)" , Dave Hansen , Matthew Wilcox , Andy Lutomirski , Shuah Khan , Matt Denton , Chris Palmer , Jeffrey Vander Stoep , Aleksa Sarai , Hehuazhen , x86@kernel.org, Linux Containers , linux-security-module@vger.kernel.org, linux-api@vger.kernel.org Subject: [PATCH 3/8] seccomp: Introduce SECCOMP_PIN_ARCHITECTURE Date: Tue, 16 Jun 2020 00:49:29 -0700 Message-Id: <20200616074934.1600036-4-keescook@chromium.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200616074934.1600036-1-keescook@chromium.org> References: <20200616074934.1600036-1-keescook@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For systems that provide multiple syscall maps based on architectures (e.g. AUDIT_ARCH_X86_64 and AUDIT_ARCH_I386 via CONFIG_COMPAT), allow a fast way to pin the process to a specific syscall mapping, instead of needing to generate all filters with an architecture check as the first filter action. Cc: Andy Lutomirski Cc: Will Drewry Signed-off-by: Kees Cook --- include/linux/seccomp.h | 3 +++ include/uapi/linux/seccomp.h | 1 + kernel/seccomp.c | 37 ++++++++++++++++++++++++++++++++++-- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/include/linux/seccomp.h b/include/linux/seccomp.h index babcd6c02d09..6525ddec177a 100644 --- a/include/linux/seccomp.h +++ b/include/linux/seccomp.h @@ -30,6 +30,9 @@ struct seccomp_filter; */ struct seccomp { int mode; +#ifdef CONFIG_COMPAT + u32 arch; +#endif atomic_t filter_count; struct seccomp_filter *filter; }; diff --git a/include/uapi/linux/seccomp.h b/include/uapi/linux/seccomp.h index c1735455bc53..84e89bb201ae 100644 --- a/include/uapi/linux/seccomp.h +++ b/include/uapi/linux/seccomp.h @@ -16,6 +16,7 @@ #define SECCOMP_SET_MODE_FILTER 1 #define SECCOMP_GET_ACTION_AVAIL 2 #define SECCOMP_GET_NOTIF_SIZES 3 +#define SECCOMP_PIN_ARCHITECTURE 4 /* Valid flags for SECCOMP_SET_MODE_FILTER */ #define SECCOMP_FILTER_FLAG_TSYNC (1UL << 0) diff --git a/kernel/seccomp.c b/kernel/seccomp.c index a319700c04c4..43edf53c2d84 100644 --- a/kernel/seccomp.c +++ b/kernel/seccomp.c @@ -268,9 +268,16 @@ static u32 seccomp_run_filters(const struct seccomp_data *sd, struct seccomp_filter **match) { u32 ret = SECCOMP_RET_ALLOW; + struct seccomp_filter *f; + +#ifdef CONFIG_COMPAT + /* Block mismatched architectures. */ + if (current->seccomp.arch && current->seccomp.arch != sd->arch) + return SECCOMP_RET_KILL_PROCESS; +#endif + /* Make sure cross-thread synced filter points somewhere sane. */ - struct seccomp_filter *f = - READ_ONCE(current->seccomp.filter); + f = READ_ONCE(current->seccomp.filter); /* Ensure unexpected behavior doesn't result in failing open. */ if (WARN_ON(f == NULL)) @@ -478,6 +485,11 @@ static inline void seccomp_sync_threads(unsigned long flags) if (task_no_new_privs(caller)) task_set_no_new_privs(thread); +#ifdef CONFIG_COMPAT + /* Copy any pinned architecture. */ + thread->seccomp.arch = caller->seccomp.arch; +#endif + /* * Opt the other thread into seccomp if needed. * As threads are considered to be trust-realm @@ -1456,6 +1468,20 @@ static long seccomp_get_notif_sizes(void __user *usizes) return 0; } +static long seccomp_pin_architecture(void) +{ +#ifdef CONFIG_COMPAT + u32 arch = syscall_get_arch(current); + + /* How did you even get here? */ + if (current->seccomp.arch && current->seccomp.arch != arch) + return -EBUSY; + + current->seccomp.arch = arch; +#endif + return 0; +} + /* Common entry point for both prctl and syscall. */ static long do_seccomp(unsigned int op, unsigned int flags, void __user *uargs) @@ -1477,6 +1503,13 @@ static long do_seccomp(unsigned int op, unsigned int flags, return -EINVAL; return seccomp_get_notif_sizes(uargs); + case SECCOMP_PIN_ARCHITECTURE: + if (flags != 0) + return -EINVAL; + if (uargs != NULL) + return -EINVAL; + + return seccomp_pin_architecture(); default: return -EINVAL; } -- 2.25.1