From patchwork Fri May 21 21:50:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Moore X-Patchwork-Id: 12273811 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 52635C47081 for ; Fri, 21 May 2021 21:50:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3852C613EE for ; Fri, 21 May 2021 21:50:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229808AbhEUVv6 (ORCPT ); Fri, 21 May 2021 17:51:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229926AbhEUVv5 (ORCPT ); Fri, 21 May 2021 17:51:57 -0400 Received: from mail-qk1-x72f.google.com (mail-qk1-x72f.google.com [IPv6:2607:f8b0:4864:20::72f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 679AFC06138B for ; Fri, 21 May 2021 14:50:33 -0700 (PDT) Received: by mail-qk1-x72f.google.com with SMTP id 124so8993339qkh.10 for ; Fri, 21 May 2021 14:50:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paul-moore-com.20150623.gappssmtp.com; s=20150623; h=subject:from:to:date:message-id:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=nqTYSxcbdFhLeehGXcGD2BgJgX1rjG2Wtkqyf5lYwxs=; b=bCFSuOY106xTmbrlMmlMrtItsMWp3Hrouloy7nRctAo9P0YrEyWroH4Ep1Wjx4QIiv UMEuUWBpuTHsO7andG1cDqSvIm5IK+x1RgyHplBq8wnv1ZpWWO016Qp2B5dCKcita4Ih 5jLyY8pFF1+7i33CjNYLETuFBSlX0txwhjTvm8kQh9dFZnrad8MBgrlvJ2Y882UKwLJz vBtWK/ECSTO3lm1kzFQDCa+YS2zoravl75Ym/ZrQ6yW0gxDhyJeBeGom1foDF7bQW6Vt vs3Bp/Iwjp4Fj1raR1G0++c8ebRn1pMYE5JpNeJG+IUXEjzW+qVY9VoV5qkQN70LTEMj Z2NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=nqTYSxcbdFhLeehGXcGD2BgJgX1rjG2Wtkqyf5lYwxs=; b=LLqriBPDtMTG0T8bfGaDwyuSRqOD+Pr3+qyjjC/gXLQAMZtwNidVyyE9058Z8idvmD 4gFsqcfIVOJ7LjZ6mz3Nm3kryoeTP4O3DgujkIbo7jc7lpX60FcjkIAQxAPG/rrt/nu0 BxXwlS047x/l+GXg8qwxKYMgvVu/GR7jVXSFHr9RcYr4wfakAS1HJwZEU4Ds6dFjLnHt 5ZQ545e/kxYZ46C+5iDnYq+eKsYxb5ph1C5JYNM7Gq++r68qpSVkzdhFMjEe5HL5biG8 kz1rKzGjuNPQ+hazgXgdV3NaGEpJx1ZFPl6nb/G5EK5esdMJI+frCue+F1ycMilKRa7w Aqfg== X-Gm-Message-State: AOAM531PkZ1EfxHAq/agtNf6zGcrHlFWACQ4PmtGJA0iFkzjLcexOO/G ZFZK6EpU4A7gPc9QcCoSyCQw X-Google-Smtp-Source: ABdhPJzzqQ3A/ENC4p3Z2YDJQeOswRLu6mmSuT0tmeMEw4hgI4BgJLg6GP2bt6rxQX4t1+reaZa3rA== X-Received: by 2002:a05:620a:4090:: with SMTP id f16mr15272263qko.225.1621633832501; Fri, 21 May 2021 14:50:32 -0700 (PDT) Received: from localhost (pool-96-237-52-188.bstnma.fios.verizon.net. [96.237.52.188]) by smtp.gmail.com with ESMTPSA id e5sm5317173qtg.96.2021.05.21.14.50.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 May 2021 14:50:32 -0700 (PDT) Subject: [RFC PATCH 8/9] selinux: add support for the io_uring access controls From: Paul Moore To: linux-security-module@vger.kernel.org, selinux@vger.kernel.org, linux-audit@redhat.com, io-uring@vger.kernel.org, linux-fsdevel@vger.kernel.org, Kumar Kartikeya Dwivedi , Jens Axboe , Alexander Viro Date: Fri, 21 May 2021 17:50:31 -0400 Message-ID: <162163383147.8379.1567341725602837940.stgit@sifl> In-Reply-To: <162163367115.8379.8459012634106035341.stgit@sifl> References: <162163367115.8379.8459012634106035341.stgit@sifl> User-Agent: StGit/1.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org WARNING - This is a work in progress, this patch, including the description, may be incomplete or even incorrect. You have been warned. This patch implements two new io_uring access controls, specifically support for controlling the io_uring "personalities" and IORING_SETUP_SQPOLL. Controlling the sharing of io_urings themselves is handled via the normal file/inode labeling and sharing mechanisms. The io_uring { override_creds } permission restricts which domains the subject domain can use to override it's own credentials. Granting a domain the io_uring { override_creds } permission allows it to impersonate another domain in io_uring operations. The io_uring { sqpoll } permission restricts which domains can create asynchronous io_uring polling threads. This is important from a security perspective as operations queued by this asynchronous thread inherit the credentials of the thread creator by default; if an io_uring is shared across process/domain boundaries this could result in one domain impersonating another. Controlling the creation of sqpoll threads, and the sharing of io_urings across processes, allow policy authors to restrict the ability of one domain to impersonate another via io_uring. As a quick summary, this patch adds a new object class with two permissions: io_uring { override_creds sqpoll } These permissions can be seen in the two simple policy statements below: allow domA_t domB_t : io_uring { override_creds }; allow domA_t self : io_uring { sqpoll }; Signed-off-by: Paul Moore --- security/selinux/hooks.c | 67 +++++++++++++++++++++++++++++++++++ security/selinux/include/classmap.h | 2 + 2 files changed, 69 insertions(+) diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index eaea837d89d1..696130972e4d 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -7115,6 +7115,68 @@ static int selinux_perf_event_write(struct perf_event *event) } #endif +#ifdef CONFIG_IO_URING + +#if 1 +/* XXX - dump_creds() is for debugging only, remove before committing */ +static void dump_creds(const struct cred *cred) +{ + u32 secid; + char *ctx = NULL; + unsigned int ctx_len = 0; + + security_cred_getsecid(cred, &secid); + if (secid) + security_secid_to_secctx(secid, &ctx, &ctx_len); + + printk(KERN_ERR "CRED: ->security is %s\n", (ctx ? : "(error)")); + + if (ctx) + security_release_secctx(ctx, ctx_len); +} +#endif + +/** + * selinux_uring_override_creds - check the requested cred override + * @new: the target creds + * + * Check to see if the current task is allowed to override it's credentials + * to service an io_uring operation. + */ +int selinux_uring_override_creds(const struct cred *new) +{ +#if 1 + /* XXX - debug only code, remove before committing */ + pr_err("PMD: selinux_uring_override_creds()\n"); + pr_err("PMD: >>> CURRENT\n"); + dump_creds(current_cred()); + pr_err("PMD: >>> NEW\n"); + dump_creds(new); +#endif + return avc_has_perm(&selinux_state, current_sid(), cred_sid(new), + SECCLASS_IO_URING, IO_URING__OVERRIDE_CREDS, NULL); +} + +/** + * selinux_uring_sqpoll - check if a io_uring polling thread can be created + * + * Check to see if the current task is allowed to create a new io_uring + * kernel polling thread. + */ +int selinux_uring_sqpoll(void) +{ + int sid = current_sid(); +#if 1 + /* XXX - debug only code, remove before committing */ + pr_err("PMD: selinux_uring_sqpoll()\n"); + pr_err("PMD: >>> CURRENT\n"); + dump_creds(current_cred()); +#endif + return avc_has_perm(&selinux_state, sid, sid, + SECCLASS_IO_URING, IO_URING__SQPOLL, NULL); +} +#endif /* CONFIG_IO_URING */ + /* * IMPORTANT NOTE: When adding new hooks, please be careful to keep this order: * 1. any hooks that don't belong to (2.) or (3.) below, @@ -7353,6 +7415,11 @@ static struct security_hook_list selinux_hooks[] __lsm_ro_after_init = { LSM_HOOK_INIT(perf_event_write, selinux_perf_event_write), #endif +#ifdef CONFIG_IO_URING + LSM_HOOK_INIT(uring_override_creds, selinux_uring_override_creds), + LSM_HOOK_INIT(uring_sqpoll, selinux_uring_sqpoll), +#endif + LSM_HOOK_INIT(locked_down, selinux_lockdown), /* diff --git a/security/selinux/include/classmap.h b/security/selinux/include/classmap.h index 62d19bccf3de..3314ad72279d 100644 --- a/security/selinux/include/classmap.h +++ b/security/selinux/include/classmap.h @@ -252,6 +252,8 @@ struct security_class_mapping secclass_map[] = { { "integrity", "confidentiality", NULL } }, { "anon_inode", { COMMON_FILE_PERMS, NULL } }, + { "io_uring", + { "override_creds", "sqpoll", NULL } }, { NULL } };