Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2936799rwd; Fri, 16 Jun 2023 10:02:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6o8LUVQC0EluMoTunnzMMGNOkzsySFHp5KvHay2SFB/+GqTUSCMv7uZRJUw7Dw1266jIg9 X-Received: by 2002:a17:902:c40a:b0:1a9:b8c3:c2c2 with SMTP id k10-20020a170902c40a00b001a9b8c3c2c2mr3288264plk.37.1686934934567; Fri, 16 Jun 2023 10:02:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686934934; cv=none; d=google.com; s=arc-20160816; b=C7LB7KRqdJwdKnT66e4O5YGcxTsM2Go8OLBk2bN5jjGOcZVWWdNXlyEU8it9RvTldd +adkNsEJnKMCblVsek9qOe8WVj3nyR2TFQudpG0wm//4zSqQrM1hEQCVLQNGgdlXyKGv OflwMD+vnIdoBrlObS+fcFslzqaUdy20ChxfKU6TX4SblyrvEBN45RbB1+rONholTrHw xKmRuMPnOBuLBvggX05ToOQxaBkboqomE6ndtku/wtu4DLi0pv61dQWtzxzj2xp3L5+k lVA7PJMcBCatEau7Vjry7LpJuyp5defpt8mz3kFM7aLwMWeg08SVXAtWwDMPNRiZUbcg fa/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=DNWNKvtAd3be3OOMSbgYgPBEP6oRo5dkBW/l7tcDaJU=; b=IueXHyMRzA0uISTjja9aDwFD2TBs/CXEBfDSxJR1FN8MAGEF4+eCZWveR/0Tuuv57x R0DgUf8THlznDJu2JutCEFQwPQGkmCEOws10DLGNC8Qt3APaStXT6Coa/HCvy6KJEi/6 O2xhIHfSkLMf9KITIb6DQ9N8zZbdDwLZLB5DiMBOgkz5m9usQTICHWz7Sk/N5TVm8GsI IswJxvNIydTaPZmiaHu4sdQ/hlFj9e3WzEbMYN7hxEH2yJRmGQKZ1SwsCTIcWWo+gp6m 8Ur5+nTC8Z3vAa1OY115wTTb8Ox2UOqcmUFjNTMhLIwzoSZBN3/8DSDtI6UDWdCJYkwp 9L1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=Z4vN6IMY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kg14-20020a170903060e00b001b414fae35csi6048085plb.497.2023.06.16.10.01.41; Fri, 16 Jun 2023 10:02:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=Z4vN6IMY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345712AbjFPQyZ (ORCPT + 99 others); Fri, 16 Jun 2023 12:54:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345400AbjFPQyK (ORCPT ); Fri, 16 Jun 2023 12:54:10 -0400 Received: from sonic303-27.consmr.mail.ne1.yahoo.com (sonic303-27.consmr.mail.ne1.yahoo.com [66.163.188.153]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D83424C15 for ; Fri, 16 Jun 2023 09:52:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1686934358; bh=DNWNKvtAd3be3OOMSbgYgPBEP6oRo5dkBW/l7tcDaJU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=Z4vN6IMY8F8UeX+EhYfztwB4NqBYVIc5Xc6xPaCDdH1bYnoBhxA+WfR88KqJAGMlUotL9ioEcs2iy+eCyqbU72Szvxfl9s0cZRTnT0Xmkuyni48fdxREMd1PQUdvb6ZMtYRYZdDL0iaw+Y92c69hU9W0PYiNkvA0uxpaLUtdPbDdrOhN/sj5nFHuo919pQ6iMIpEp8eXmi1IC7KCOzOhBRqpqiVDeB9lg8TuVCT7d3quvbeanCN4z2AST/1VpiRDN9vl5QRjG5XGXYIwBB89r4mp8TSdM4CXjSpBj8WGPkWOOJMPeZZe/fhjlW9Sxb7+Cdwb+da16jx5hR8qiFuFFw== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1686934358; bh=t+4IUkWeiK0dDuOvCw0N9CnVzq99glyCiHMU9RRJM/v=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=o6VeiKp58yWQPY2ULVmYqa/+neV2gbBgJpyKRmD9+JJuL4qiF749gt/RtfycJWDAJ64wh2kF/g1+SdBVLkclMLIZ9JBl+QdRaUtDAOMMG3vEL94Tqa79bkpPgzOj9u+QznkUpIRDDKJA0IU+3ItMPlj1biF+pE2nr9yxoM+66l6qcLmvvrHT54Vq2l7NodfmRYhi3OyedNJ37l/s3AEbIE4/eu4svjoUigZoXqmKBQ2wcL4GJSWnQa2K7mf8/xnXtuBx+TiOkDwrcNDphlaQ+O6ZkvX4k6RIaqHGD17qhoH7niJw8+a5Ph8yKVWMaAO7RickJimJ5updqnTEOgJJ0Q== X-YMail-OSG: VxzDtF4VM1n8TFIQSOxNI4ADqjlPRBVFmfa3rjDQmYtxgQ5_15vKMPVGkZzViES YSclR0gLknANztxulLBdAykwx80VWagX3FdjnJ_MKCYwGsEeSFIcRJfik30BKCf_IeGZ7jcdHn85 HJtfueh1cwGRzpfYijTgK7RkXy3LpYh2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dx_J3r5.bd1xKrQ- X-Sonic-MF: X-Sonic-ID: f81caaeb-5d63-4e09-8ab8-35021b7add7c Received: from sonic.gate.mail.ne1.yahoo.com by sonic303.consmr.mail.ne1.yahoo.com with HTTP; Fri, 16 Jun 2023 16:52:38 +0000 Received: by hermes--production-ne1-574d4b7954-r69wt (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 46e5733d7b6da7b60f76f64d6170c2d9; Fri, 16 Jun 2023 16:52:34 +0000 (UTC) From: Casey Schaufler To: casey@schaufler-ca.com, paul@paul-moore.com, linux-security-module@vger.kernel.org Cc: jmorris@namei.org, serge@hallyn.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, stephen.smalley.work@gmail.com, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, mic@digikod.net, linux-fsdevel@vger.kernel.org Subject: [PATCH v11 03/11] proc: Use lsmids instead of lsm names for attrs Date: Fri, 16 Jun 2023 09:50:47 -0700 Message-Id: <20230616165055.4705-4-casey@schaufler-ca.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230616165055.4705-1-casey@schaufler-ca.com> References: <20230616165055.4705-1-casey@schaufler-ca.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use the LSM ID number instead of the LSM name to identify which security module's attibute data should be shown in /proc/self/attr. The security_[gs]etprocattr() functions have been changed to expect the LSM ID. The change from a string comparison to an integer comparison in these functions will provide a minor performance improvement. Signed-off-by: Casey Schaufler Reviewed-by: Kees Cook Reviewed-by: Serge Hallyn Cc: linux-fsdevel@vger.kernel.org --- fs/proc/base.c | 29 +++++++++++++++-------------- fs/proc/internal.h | 2 +- include/linux/security.h | 11 +++++------ security/security.c | 15 +++++++-------- 4 files changed, 28 insertions(+), 29 deletions(-) diff --git a/fs/proc/base.c b/fs/proc/base.c index 05452c3b9872..f999bb5c497b 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -97,6 +97,7 @@ #include #include #include +#include #include #include "internal.h" #include "fd.h" @@ -146,10 +147,10 @@ struct pid_entry { NOD(NAME, (S_IFREG|(MODE)), \ NULL, &proc_single_file_operations, \ { .proc_show = show } ) -#define ATTR(LSM, NAME, MODE) \ +#define ATTR(LSMID, NAME, MODE) \ NOD(NAME, (S_IFREG|(MODE)), \ NULL, &proc_pid_attr_operations, \ - { .lsm = LSM }) + { .lsmid = LSMID }) /* * Count the number of hardlinks for the pid_entry table, excluding the . @@ -2730,7 +2731,7 @@ static ssize_t proc_pid_attr_read(struct file * file, char __user * buf, if (!task) return -ESRCH; - length = security_getprocattr(task, PROC_I(inode)->op.lsm, + length = security_getprocattr(task, PROC_I(inode)->op.lsmid, file->f_path.dentry->d_name.name, &p); put_task_struct(task); @@ -2788,7 +2789,7 @@ static ssize_t proc_pid_attr_write(struct file * file, const char __user * buf, if (rv < 0) goto out_free; - rv = security_setprocattr(PROC_I(inode)->op.lsm, + rv = security_setprocattr(PROC_I(inode)->op.lsmid, file->f_path.dentry->d_name.name, page, count); mutex_unlock(¤t->signal->cred_guard_mutex); @@ -2837,27 +2838,27 @@ static const struct inode_operations proc_##LSM##_attr_dir_inode_ops = { \ #ifdef CONFIG_SECURITY_SMACK static const struct pid_entry smack_attr_dir_stuff[] = { - ATTR("smack", "current", 0666), + ATTR(LSM_ID_SMACK, "current", 0666), }; LSM_DIR_OPS(smack); #endif #ifdef CONFIG_SECURITY_APPARMOR static const struct pid_entry apparmor_attr_dir_stuff[] = { - ATTR("apparmor", "current", 0666), - ATTR("apparmor", "prev", 0444), - ATTR("apparmor", "exec", 0666), + ATTR(LSM_ID_APPARMOR, "current", 0666), + ATTR(LSM_ID_APPARMOR, "prev", 0444), + ATTR(LSM_ID_APPARMOR, "exec", 0666), }; LSM_DIR_OPS(apparmor); #endif static const struct pid_entry attr_dir_stuff[] = { - ATTR(NULL, "current", 0666), - ATTR(NULL, "prev", 0444), - ATTR(NULL, "exec", 0666), - ATTR(NULL, "fscreate", 0666), - ATTR(NULL, "keycreate", 0666), - ATTR(NULL, "sockcreate", 0666), + ATTR(LSM_ID_UNDEF, "current", 0666), + ATTR(LSM_ID_UNDEF, "prev", 0444), + ATTR(LSM_ID_UNDEF, "exec", 0666), + ATTR(LSM_ID_UNDEF, "fscreate", 0666), + ATTR(LSM_ID_UNDEF, "keycreate", 0666), + ATTR(LSM_ID_UNDEF, "sockcreate", 0666), #ifdef CONFIG_SECURITY_SMACK DIR("smack", 0555, proc_smack_attr_dir_inode_ops, proc_smack_attr_dir_ops), diff --git a/fs/proc/internal.h b/fs/proc/internal.h index 9dda7e54b2d0..a889d9ef9584 100644 --- a/fs/proc/internal.h +++ b/fs/proc/internal.h @@ -92,7 +92,7 @@ union proc_op { int (*proc_show)(struct seq_file *m, struct pid_namespace *ns, struct pid *pid, struct task_struct *task); - const char *lsm; + int lsmid; }; struct proc_inode { diff --git a/include/linux/security.h b/include/linux/security.h index 569b1d8ab002..945101b0d404 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -470,10 +470,9 @@ int security_sem_semctl(struct kern_ipc_perm *sma, int cmd); int security_sem_semop(struct kern_ipc_perm *sma, struct sembuf *sops, unsigned nsops, int alter); void security_d_instantiate(struct dentry *dentry, struct inode *inode); -int security_getprocattr(struct task_struct *p, const char *lsm, const char *name, +int security_getprocattr(struct task_struct *p, int lsmid, const char *name, char **value); -int security_setprocattr(const char *lsm, const char *name, void *value, - size_t size); +int security_setprocattr(int lsmid, const char *name, void *value, size_t size); int security_netlink_send(struct sock *sk, struct sk_buff *skb); int security_ismaclabel(const char *name); int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen); @@ -1332,14 +1331,14 @@ static inline void security_d_instantiate(struct dentry *dentry, struct inode *inode) { } -static inline int security_getprocattr(struct task_struct *p, const char *lsm, +static inline int security_getprocattr(struct task_struct *p, int lsmid, const char *name, char **value) { return -EINVAL; } -static inline int security_setprocattr(const char *lsm, char *name, - void *value, size_t size) +static inline int security_setprocattr(int lsmid, char *name, void *value, + size_t size) { return -EINVAL; } diff --git a/security/security.c b/security/security.c index 39c5225603cf..501c0884ec03 100644 --- a/security/security.c +++ b/security/security.c @@ -3800,7 +3800,7 @@ EXPORT_SYMBOL(security_d_instantiate); /** * security_getprocattr() - Read an attribute for a task * @p: the task - * @lsm: LSM name + * @lsmid: LSM identification * @name: attribute name * @value: attribute value * @@ -3808,13 +3808,13 @@ EXPORT_SYMBOL(security_d_instantiate); * * Return: Returns the length of @value on success, a negative value otherwise. */ -int security_getprocattr(struct task_struct *p, const char *lsm, - const char *name, char **value) +int security_getprocattr(struct task_struct *p, int lsmid, const char *name, + char **value) { struct security_hook_list *hp; hlist_for_each_entry(hp, &security_hook_heads.getprocattr, list) { - if (lsm != NULL && strcmp(lsm, hp->lsmid->name)) + if (lsmid != 0 && lsmid != hp->lsmid->id) continue; return hp->hook.getprocattr(p, name, value); } @@ -3823,7 +3823,7 @@ int security_getprocattr(struct task_struct *p, const char *lsm, /** * security_setprocattr() - Set an attribute for a task - * @lsm: LSM name + * @lsmid: LSM identification * @name: attribute name * @value: attribute value * @size: attribute value size @@ -3833,13 +3833,12 @@ int security_getprocattr(struct task_struct *p, const char *lsm, * * Return: Returns bytes written on success, a negative value otherwise. */ -int security_setprocattr(const char *lsm, const char *name, void *value, - size_t size) +int security_setprocattr(int lsmid, const char *name, void *value, size_t size) { struct security_hook_list *hp; hlist_for_each_entry(hp, &security_hook_heads.setprocattr, list) { - if (lsm != NULL && strcmp(lsm, hp->lsmid->name)) + if (lsmid != 0 && lsmid != hp->lsmid->id) continue; return hp->hook.setprocattr(name, value, size); } -- 2.40.1