From patchwork Wed Sep 15 16:50:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Moore X-Patchwork-Id: 12496891 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 30FE4C433FE for ; Wed, 15 Sep 2021 16:50:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 143C9610E9 for ; Wed, 15 Sep 2021 16:50:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230368AbhIOQv1 (ORCPT ); Wed, 15 Sep 2021 12:51:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230428AbhIOQv0 (ORCPT ); Wed, 15 Sep 2021 12:51:26 -0400 Received: from mail-qt1-x833.google.com (mail-qt1-x833.google.com [IPv6:2607:f8b0:4864:20::833]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45329C0613C1 for ; Wed, 15 Sep 2021 09:50:04 -0700 (PDT) Received: by mail-qt1-x833.google.com with SMTP id b14so2960164qtb.0 for ; Wed, 15 Sep 2021 09:50:04 -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=pFXyiSy5mSijsi+vyJp9AB0dIFK/hLMP5evPgimL4oI=; b=nT//ASu3kjB1yTgZVaPmiOOsJv/sdzgDl247t8dcGM0kHoePlSQ8SAPszJGV9J9iwg 3G5vFa5H7CmK9wz87ZXOgKP+vMKwGBanH517h8eyTtpkrGSeOo5krQYZt4n3FZ87OB9N SwXyQ4pRQMNIppPyKfsGqsKPsS9fDxyg1UWFf0XoToUTYMlGYWkGqCIemk8tXTGTtH5m fv/3BzJuf7jYr1Oxb47jEgZxCn7WZ6pqIovl2Tdk67i5w0Z6UwyFQPU3XPGPrhr/zcS4 Uv1N2WZTW1fvnBEphMbAQbCGTRiy0kBOYNgq4R6eWs8X+8nejdluBa73mgV7JbwZbN30 I2lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:from:to:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=pFXyiSy5mSijsi+vyJp9AB0dIFK/hLMP5evPgimL4oI=; b=zqtIt4ickaNug3hJTxpmL/033L0+bVv3M7eFH7vnZ6w72TuH0b4K4ZNyCsk0SsFiUz Vhd/lI4hm520tjYJ3f6q8utyhPeJjwWns705q16ykCfHp9+a6dPg0lcRS8c2/T0klVIm mDDEU6t2lpaZgb0jj2PNpR9ujd0wFB+gfDZA5shycGM22EWiy4ocV8nkOtE+o1h+CxSk QQs44JPPgFPdB6Aa2ByJZwUPgedQ18vDSaKT9dOh3lJNtYVpQo2Ako7lMAJ9O+PLNmZW pegJnfyaWXUORnmd+k4FQHdjjCJxc8n6x3/tQuaulbyDgrs79D7vQO50YC7hhZrdxBe9 Cb0Q== X-Gm-Message-State: AOAM532QPKUIVW7jjHg4edm7RhK63Wi3aR6MEtFDgbG/XkGkQjV5EEws 3iikKT1jQVxZWinZIOY+scXq X-Google-Smtp-Source: ABdhPJwxHpFS9FikZ0JUIYc0mk4r4o/AVbyPloTv5KlWztD4/Z4Jcgb2HFB09rgl94uVExhd3nfILQ== X-Received: by 2002:ac8:7285:: with SMTP id v5mr801915qto.300.1631724603382; Wed, 15 Sep 2021 09:50:03 -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 t3sm377604qkg.2.2021.09.15.09.50.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Sep 2021 09:50:02 -0700 (PDT) Subject: [PATCH v4 7/8] 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, Jens Axboe , Pavel Begunkov , Kumar Kartikeya Dwivedi Date: Wed, 15 Sep 2021 12:50:02 -0400 Message-ID: <163172460230.88001.3182498346819815467.stgit@olly> In-Reply-To: <163172413301.88001.16054830862146685573.stgit@olly> References: <163172413301.88001.16054830862146685573.stgit@olly> User-Agent: StGit/1.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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 --- v4: - no change v3: - removed work-in-progress warning from the description v2: - made the selinux_uring_* funcs static - removed the debugging code v1: - initial draft --- security/selinux/hooks.c | 34 ++++++++++++++++++++++++++++++++++ security/selinux/include/classmap.h | 2 ++ 2 files changed, 36 insertions(+) diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index 6517f221d52c..012e8504ed9e 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -7111,6 +7111,35 @@ static int selinux_perf_event_write(struct perf_event *event) } #endif +#ifdef CONFIG_IO_URING +/** + * 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. + */ +static int selinux_uring_override_creds(const struct cred *new) +{ + 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. + */ +static int selinux_uring_sqpoll(void) +{ + int sid = current_sid(); + + 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, @@ -7349,6 +7378,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 084757ff4390..698ccfdaf82d 100644 --- a/security/selinux/include/classmap.h +++ b/security/selinux/include/classmap.h @@ -254,6 +254,8 @@ struct security_class_mapping secclass_map[] = { { "integrity", "confidentiality", NULL } }, { "anon_inode", { COMMON_FILE_PERMS, NULL } }, + { "io_uring", + { "override_creds", "sqpoll", NULL } }, { NULL } };