From patchwork Fri Dec 1 09:46:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13475554 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 61AC6C4167B for ; Fri, 1 Dec 2023 09:47:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 070DD6B0442; Fri, 1 Dec 2023 04:47:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E4FCD6B0444; Fri, 1 Dec 2023 04:47:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CCA196B0445; Fri, 1 Dec 2023 04:47:15 -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 B35DB6B0442 for ; Fri, 1 Dec 2023 04:47:15 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 894C9C0179 for ; Fri, 1 Dec 2023 09:47:15 +0000 (UTC) X-FDA: 81517771230.27.4B0BD47 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by imf12.hostedemail.com (Postfix) with ESMTP id A59CD4000F for ; Fri, 1 Dec 2023 09:47:13 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ihqHSsku; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf12.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.210.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=1701424033; 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=Hrd8Q/aZ94cCzu/B8oHzIUPKN1cXCmsoH2G1FVF6YII=; b=YKb4/wWzLzYMOdiZl4W4DlmGgrIZkXsPZGk1sT3EIKT73+TOtZGibZow1pBm7qCapbPDkD XPlo46fwuFMruK9C5h3cZUIBdr9Kkkz7VOUbR8Rzj+1VmUMqISOOzAshKeP3uNGBLzCwm/ SLtRWM4R/Wv6hC/l1AFzF9PdCcbNrIE= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ihqHSsku; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf12.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.210.173 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701424033; a=rsa-sha256; cv=none; b=N/szP3yrtUQkRmMGMhBPt6ob9+kDZCMfhb0XFexaE+0aVqtp0CyXeA/5WQqlIqRljjNWXs Eojl8yekJGPgCiXx4Rl03GcvuvB+fPxNLnbR18GFu8kKEbzKcrivjeedTM+9jT8pNxBfk6 k968KnyPKblvad8wsQRG390wOQfweLM= Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-6cdea2f5918so1345882b3a.2 for ; Fri, 01 Dec 2023 01:47:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701424032; x=1702028832; 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=Hrd8Q/aZ94cCzu/B8oHzIUPKN1cXCmsoH2G1FVF6YII=; b=ihqHSskuejTW5nTPImEUiW7iqDW01v1pYd1/uL6psrkf1bju9BePpdh9cSSp6ik1g/ s+6Wf9F78v8m9Bd+dPuM8FmeifPq6n7JL7a+KUQYQboJfbKTpEE1BXsNuzkaUmbLw69w mB8m2O7TDOw+l3v4ND/UuOyWSHI7KeHxd0L2oyHRsoNTDMPDF6pmzgAJJBEN27tL3xF7 /Pp1SW14+JxwN7B0tpE+e1EhZLgyjuv/aSfyirgNmAyVzjOHo70T45RujarArqmprsDs 7HxYo3mV/qelaXIvn+67RfB5N4Muc57KL5fle5p/5YqB8zYt5DWf+p9DerswFhvRIb1i JWFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701424032; x=1702028832; 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=Hrd8Q/aZ94cCzu/B8oHzIUPKN1cXCmsoH2G1FVF6YII=; b=YmZ5Hks53l8b7e206mp0O3AOYgWopRCv8NfNu64XPQ3jTRC8pc9GGKHKYRM+OWgQ04 i2yS+Weoi6EgCNTXeIgRzd3dVcG78UuSH2MB/ApsbQQ79iSxS8N68EFAS96EE756cFAK MtXC9h0vD++G15x2M5Xr2GVTqs0KitzRsqnuy9xsQIRENnpL2dqtY4uizTUUDP8MJ0d7 v2b3iATuDS049jVooXgP9YH5j3xYXwPrY89wISYbOWfXZYEbcLLIAUzyQ7HiXdGk1j6M I4/rndZsLG7oK/c5gg/yY/H5KPKptG50S2ljwL9/f0IXYBSW0r4aqWQXU4ezqF5ICEnA KVZQ== X-Gm-Message-State: AOJu0Yz15SZuYu6BXlzoUrQv02onOGuKFOg+66UkKLj2BznrdNjaHHB0 3KxxEVI8xr9QpijHSm9SXrY= X-Google-Smtp-Source: AGHT+IGTfBMOdaKabUHzgD6/ex7gttFCAVl5dyu04ZCxUj3YMK/ifw1iGQwqNjXNRb2rj7NPqQSuqQ== X-Received: by 2002:a05:6a21:6215:b0:16c:b5ce:50f with SMTP id wm21-20020a056a21621500b0016cb5ce050fmr19689003pzb.32.1701424032510; Fri, 01 Dec 2023 01:47:12 -0800 (PST) Received: from vultr.guest ([149.28.194.201]) by smtp.gmail.com with ESMTPSA id e6-20020a170902b78600b001bdd7579b5dsm2875534pls.240.2023.12.01.01.47.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 01:47:12 -0800 (PST) From: Yafang Shao To: akpm@linux-foundation.org, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com, omosnace@redhat.com, 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 v3 5/7] security: selinux: Implement set_mempolicy hook Date: Fri, 1 Dec 2023 09:46:34 +0000 Message-Id: <20231201094636.19770-6-laoar.shao@gmail.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20231201094636.19770-1-laoar.shao@gmail.com> References: <20231201094636.19770-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: A59CD4000F X-Stat-Signature: po7ose49krncdurb8hznfs8a7k4mm3u1 X-HE-Tag: 1701424033-582321 X-HE-Meta: U2FsdGVkX18fWFHNUyIkrAb/swLbz0eHaC/Yo7nf7RNZyM8Hv/hRUQIS7aaJtfCc8sT37IIoueaE8ccrkYyv6ZA1Q9Skr2WssQtOmPb3d/TooRPolY0XKmnG3zOPqwMlUCZRl5wqZmx85+2zUOjmp+ISDlJ3CJ8dNnwBUYJJWxguKLZ68Ev8bwazGK8J5Me/dv8DP5qR3DIMmYTXIsasSBGpheiWPvkSIVVVh7duqYaAzCBhGkE9uX5wKdtYzvk02Hk/uaprEs0vlKGelJaVy9jY9w4YaD7xUzidtdfZwDx4Zcb2KY8dV+LvD0TZABCpPnSmic6Hoq5HHIfmF/zAEB8AvQ5aFkf2LGZpxogkvsNpuo87fc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C+gyeZf9gpdJNypTSZZASg/yIlUubsxydo3Tt9uVtMgwYzqqZZ1KOevBqFUmLferNCL9Gs3T1YKbE/ganQop17FXLI9Bh7ZxC7Evo0GliEgta+KyoGMxY0AikQFm6fr956+8EDBwPUvAxnLC2IQ== 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 feda711c6b7b..1528d4dcfa03 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 struct security_hook_list selinux_hooks[] __ro_after_init = { 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 a3c380775d41..c280d92a409f 100644 --- a/security/selinux/include/classmap.h +++ b/security/selinux/include/classmap.h @@ -51,7 +51,7 @@ const struct security_class_mapping secclass_map[] = { "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",