From patchwork Thu Dec 14 12:50:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13493007 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E664BC4332F for ; Thu, 14 Dec 2023 12:51:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2BE118D00A2; Thu, 14 Dec 2023 07:51:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1AE456B0129; Thu, 14 Dec 2023 07:51:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DE15D8D00A2; Thu, 14 Dec 2023 07:51:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id BF1356B010F for ; Thu, 14 Dec 2023 07:51:50 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 926A140C2D for ; Thu, 14 Dec 2023 12:51:50 +0000 (UTC) X-FDA: 81565410780.06.493FC3D Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) by imf26.hostedemail.com (Postfix) with ESMTP id A9EFC14001B for ; Thu, 14 Dec 2023 12:51:48 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=UqarjMYY; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf26.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.215.173 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702558308; a=rsa-sha256; cv=none; b=0AkKaCVJ1bb0cebVyXKS+kfBI0COzr1mmDsHBavHnb5/6aQGTV2CscSfzxAKiqZnECz88M Fp//Dl0S1euk4YFe/nT3UeFI28nxsn721cI4PDHH518UR9fOibmJlxDjWE1Jj0ec1Mn94M eCER7gFcGZ+IuOXgnqXajMqfPzGyppg= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=UqarjMYY; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf26.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.215.173 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702558308; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=6NLQupAZumzbZoKpNAG12sWAtAVUuthZdQhUM0QKlyo=; b=hlMPssETx+b6TKU9VflLIjLzxIefFvXcW8ato6Flr+lLhZxSLFNO/LtEbyeodRFBWQHbtV +tk6jfX4H4cej1V4WxaXKfvA2tsKJhpcbovEFJo4rlH5cZ62aIBl8GDUwXwUDaIcrjrLyt hhAAfXHr0E3Der3vuY6+oDxy4F/ZBUk= Received: by mail-pg1-f173.google.com with SMTP id 41be03b00d2f7-5be30d543c4so4584503a12.2 for ; Thu, 14 Dec 2023 04:51:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702558307; x=1703163107; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6NLQupAZumzbZoKpNAG12sWAtAVUuthZdQhUM0QKlyo=; b=UqarjMYY4+ADVEDJYJWiW+RbPPxx2Q8b6kgSZuY6pfZxEq1pJw1Truz1MS+A0lDYhq hSTd0JUDznTebnlKGVnllVzi9r8ZHFIuYlceBJI94zAFvYWQwi5DVTjxg8OP7prSca7s I7bQocnacNKRTifY/AVyQ+H6lhRKd03QRNZBjUx+DF2mU8JP/suO1zbJQ9JOjSZst71w qWIPORdMtRYExhsPt2t9/tcYthmZB+53SS243iSmeNT4JGNZwPGGl9Bc9Ascv2v5slUi 2xF3ylI45Q7ufwv7GHlVrj3XMBo4SUaaBHyQyTlVB9p+MyEwVBQ4JpKSTrrNrOwJ0c0q RfjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702558307; x=1703163107; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6NLQupAZumzbZoKpNAG12sWAtAVUuthZdQhUM0QKlyo=; b=BvnZfHS4MplzJygCGmi2N+3kyCypz6sJQzUq9vXdfQWK2bUmql6o39TkfX9oEu6P0y wXzc+8Ov/22lUslcep24cYYXx5MkPqyGVST7z3hMqtktA78w/bDKnZWqnQvkbhaowwDg +JublgGUGy3uohuSyytR/d58rrqiWzXFMccdYkrne5Ko3SC+/r+JC5EK5EZbQy0OVz9+ 8tBQGFW3d3E8ZYblu8z/LSERuQhPFP65hrVZlcaIJas20/M6zDLG+AQx33QpP3v2a1FW Y3DJeihVL+zgaqkScuPatCCJNKKqMH9LWJpN4DUDTbpzSAc7nozlbazce1OmkgQeRk9Q j+3w== X-Gm-Message-State: AOJu0Ywh1MMKK79T5XKr0mb5V2hRIhaUH1xTkZrfIevNcs8ktwnnbUA6 WGjP7CPWgTrQ3I/j2899T+0= X-Google-Smtp-Source: AGHT+IFyrMV98A56t+dmpjQI6o3tD3UVYHPGWsTpR7EYC7ExrRnRkFX6PbWwWnOn+9SdsmHBpk2UrQ== X-Received: by 2002:a05:6a20:13cc:b0:190:2c2f:7df9 with SMTP id ho12-20020a056a2013cc00b001902c2f7df9mr4835222pzc.64.1702558307403; Thu, 14 Dec 2023 04:51:47 -0800 (PST) Received: from vultr.guest ([149.28.194.201]) by smtp.gmail.com with ESMTPSA id jj17-20020a170903049100b001d36b2e3dddsm1184528plb.192.2023.12.14.04.51.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 04:51:46 -0800 (PST) From: Yafang Shao To: akpm@linux-foundation.org, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com, omosnace@redhat.com, casey@schaufler-ca.com, kpsingh@kernel.org, mhocko@suse.com, ying.huang@intel.com Cc: linux-mm@kvack.org, linux-security-module@vger.kernel.org, bpf@vger.kernel.org, ligang.bdlg@bytedance.com, Yafang Shao Subject: [PATCH v5 bpf-next 4/5] security: selinux: Implement set_mempolicy hook Date: Thu, 14 Dec 2023 12:50:32 +0000 Message-Id: <20231214125033.4158-5-laoar.shao@gmail.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20231214125033.4158-1-laoar.shao@gmail.com> References: <20231214125033.4158-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: A9EFC14001B X-Stat-Signature: p1oa5rugtdkgf5nnoah9uqcahuanuap3 X-HE-Tag: 1702558308-753111 X-HE-Meta: U2FsdGVkX18bJM2mMbY6MVF8n9aox0SpddlccDYepxSDqXF7IIaEQ4ueqZjpuVcR8KnlRADHe19K6BKgx/EDibWagbvKLfRheQIQnJ9SJ2FQGlLYAutAnocna0h+aJoS2gYHRauYQsU/ImqqQHbYg/cFazDKDayebr1R2LAJ6unzmWE1UfPrH0Y2pOYld0ac0mzP96UNTTxbuW28h83hQbROFmJUr7zASvnpVn2t3feiSjpWhjcVK9rqLSqb3Jtp6UuQRE/2lfHm6SBQ1d14SMj0vS0GiagKETS5NjWXIbyM3ecfiFhTpoLSowQ/ofZnAz2Iw8JuoAbcHGYFN8s1f+Z1jHrDNoT7kcnI1U6x9dik6vca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A/hpryoMiN94qb96uNYxEXm9v2Z5Uj8j4RVk+eABoNxdkF/qUec1DdvYYNzy5VmtrOrc6+f1ovx3KXX/PzuPpciIQy11egobree4jvj9kMd+AiZEzid3Z0uAj/TK5iAUVEgCAmncaU0tCegKCW9ooNQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Add a SELinux access control for the newly introduced set_mempolicy lsm hook. A new permission "setmempolicy" is defined under the "process" class for it. Signed-off-by: Yafang Shao --- security/selinux/hooks.c | 8 ++++++++ security/selinux/include/classmap.h | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index feda711..1528d4d 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -4238,6 +4238,13 @@ static int selinux_userns_create(const struct cred *cred) USER_NAMESPACE__CREATE, NULL); } +static int selinux_set_mempolicy(unsigned long mode, unsigned short mode_flags, + nodemask_t *nmask, unsigned int flags) +{ + return avc_has_perm(current_sid(), task_sid_obj(current), SECCLASS_PROCESS, + PROCESS__SETMEMPOLICY, NULL); +} + /* Returns error only if unable to parse addresses */ static int selinux_parse_skb_ipv4(struct sk_buff *skb, struct common_audit_data *ad, u8 *proto) @@ -7072,6 +7079,7 @@ static int selinux_uring_cmd(struct io_uring_cmd *ioucmd) LSM_HOOK_INIT(task_kill, selinux_task_kill), LSM_HOOK_INIT(task_to_inode, selinux_task_to_inode), LSM_HOOK_INIT(userns_create, selinux_userns_create), + LSM_HOOK_INIT(set_mempolicy, selinux_set_mempolicy), LSM_HOOK_INIT(ipc_permission, selinux_ipc_permission), LSM_HOOK_INIT(ipc_getsecid, selinux_ipc_getsecid), diff --git a/security/selinux/include/classmap.h b/security/selinux/include/classmap.h index a3c3807..c280d92 100644 --- a/security/selinux/include/classmap.h +++ b/security/selinux/include/classmap.h @@ -51,7 +51,7 @@ "getattr", "setexec", "setfscreate", "noatsecure", "siginh", "setrlimit", "rlimitinh", "dyntransition", "setcurrent", "execmem", "execstack", "execheap", "setkeycreate", - "setsockcreate", "getrlimit", NULL } }, + "setsockcreate", "getrlimit", "setmempolicy", NULL } }, { "process2", { "nnp_transition", "nosuid_transition", NULL } }, { "system",