Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp6588305rwl; Mon, 9 Jan 2023 10:12:24 -0800 (PST) X-Google-Smtp-Source: AMrXdXvA4zCZ7i/nmLAK63ZKq0XiagjyLHXfSqvl/iGPY7JMYY0mVgXCBxNbtgBvSmS+DJXJ07cO X-Received: by 2002:a17:902:d5c8:b0:193:38b4:b9a7 with SMTP id g8-20020a170902d5c800b0019338b4b9a7mr2781137plh.31.1673287943855; Mon, 09 Jan 2023 10:12:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673287943; cv=none; d=google.com; s=arc-20160816; b=BomEJWe+JIXDFUyJHfgz5o8ywlRQfzXITr1bO59ZgEod00LIQOp108orIERRjWc8Qp bi09pQHbPJzVjiAV0e4b5Mfm/xCXKcPrAkzu4HzcRA2jqhCQrvczRQE4Q3mi5yymD3um 1rzPbRWtGPG+bCH9bHaB4z0t55JmbqdJLwbYGC/j5k6GmB0mdRhbQU6Uo6tpm1v41zvb XkyvNXilyFm+PW6ghExfM4xn+lnGL3B8VQcJWZhpX5koyGxptodwRDKYOBU+Cf1iEMdY AYiKUcypO83JsmgC2504mpEk8ImaKpCfDRWfdrdJcSE5kcXxZ5n2QnZmQsX91kzfbOkE qnFw== 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=UkfRcDMPf/v1DcWo04q62pwUSUPbnp//erzjsjt01Vs=; b=nFMbiQy57zlsNhSGm30OtZeiJfIOb7rmhLC5TdXl7q/erJ45A2ql+rktfO6qO9TbHX 0WISWrdHch9jYrvZZ7pprw+sNhAD1m9VP2UHSpYOMluRVhfdD5sPUyhTtYTG1FjxNbkR Oaw6udShgoO4972H92gssKlOBAU9oTmxqlXwT2TnTttHLM4lwKO2WSo7MPoImJrVUJ0I MA3VjH6/akU7vKaNv6866q+gQxsmbRtJsUPRsfHG5/OdGPaVOYr28I3At21Xaud9E0Ly qWRPY1mgTC/3CFIKhYCjGNZd2Yb9xVi+r5hvEAi9p+U2evKOCp36OBCzW3Y9Y+u2HSbU 5TIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=DTwP1PWz; 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 b18-20020a170902d51200b00178b5e035fcsi9973576plg.496.2023.01.09.10.12.17; Mon, 09 Jan 2023 10:12:23 -0800 (PST) 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=DTwP1PWz; 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 S233860AbjAISKh (ORCPT + 53 others); Mon, 9 Jan 2023 13:10:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234972AbjAISJk (ORCPT ); Mon, 9 Jan 2023 13:09:40 -0500 Received: from sonic302-28.consmr.mail.ne1.yahoo.com (sonic302-28.consmr.mail.ne1.yahoo.com [66.163.186.154]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24A8BB1FF for ; Mon, 9 Jan 2023 10:09:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1673287747; bh=UkfRcDMPf/v1DcWo04q62pwUSUPbnp//erzjsjt01Vs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=DTwP1PWzMxGoqT041JAZTuN7kRjnfPepw9YnmknPtmeQXTpRfHl5oLUwD/SENda2P7hhneYngAeV8NYVjvEXUwlV9pQCJr/D1xPuB1BUa94MWt9UgqdJ/M11J4bpz7Wp6ELSRoM/OF4XFOa6F0v3ekn9VrIbI76e+qbDAl92D/1POciUw4d/PrcR4hLmTrIfWZDyZWji8gZni10eMWEIsSLNEhmIgid0o5tS/Crc2afsZJQKSoILpT2g6dENb9hXMq+U0K1h9v/Wi5TkUAlotABfuFBK9aBnUQkTZIq7h39bEfx56LcAtTIe+4fq9Vh2M+oxqvLKHBMqAspBW3TxDw== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1673287747; bh=0V71/1e8f/JUulk1j0yXLI4ibca3kGMAkCTPoIx8CKv=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=gZ4aNpsOnzWyS8h1EbpX1G5nCp5qmiHEEQ0l+MCMxPu9pJyXpLun9Ldkh3ewFyfF0A1SUrlLzrtGWJ/NBfMuMZ95EcHavzeU8j7yQPhdM28RK/8MW6NpYdvXXAI87wi8C2/yvU5ygIxsg7TtrfLjoi53EtRfAgO+YmwU7sjK8SOazG8Eun+eOPU+L2O6YS69oqhn7ZzQA5CnKTcTYTSQUPPrfUJKmHPygCpuZksUr1+QWGslH6b++PyhClGUpiSpoyUoqkUe9ZUFzIvk+T24d0e/MQ+Trf6ce5Wnqx/Y/ofaaL3UunNHW7fMhe0R+TXli3u1MRgYlZLuxnNdv4CTrA== X-YMail-OSG: CpzcW9UVM1mblJ2JGRpNGRRBVfYPbAxCcDUwbRlMQp.mvxCpKxnYVvRBTgH104R L0tNZ.ttFY8j6yb0OmBQhvjSMvWW0CQIcDlEDS3T4Vqyc6GD4kR9otl8q4EZb91jbgxbFQN5PQTj ZgA46h18pnKtGfePgANHcpsaZVAcpKJ5BI6oFi4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onic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic302.consmr.mail.ne1.yahoo.com with HTTP; Mon, 9 Jan 2023 18:09:07 +0000 Received: by hermes--production-ne1-7b69748c4d-474lb (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 3be57d1d3a3d9a781b586d3784815f58; Mon, 09 Jan 2023 18:09:02 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, paul@paul-moore.com, linux-security-module@vger.kernel.org Cc: casey@schaufler-ca.com, jmorris@namei.org, 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 v5 3/8] proc: Use lsmids instead of lsm names for attrs Date: Mon, 9 Jan 2023 10:07:12 -0800 Message-Id: <20230109180717.58855-4-casey@schaufler-ca.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230109180717.58855-1-casey@schaufler-ca.com> References: <20230109180717.58855-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_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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 Cc: linux-fsdevel@vger.kernel.org --- fs/proc/base.c | 29 +++++++++++++++-------------- fs/proc/internal.h | 2 +- include/linux/security.h | 11 +++++------ security/security.c | 11 +++++------ 4 files changed, 26 insertions(+), 27 deletions(-) diff --git a/fs/proc/base.c b/fs/proc/base.c index 9e479d7d202b..9328b6b07dfc 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -96,6 +96,7 @@ #include #include #include +#include #include #include "internal.h" #include "fd.h" @@ -145,10 +146,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(0, "current", 0666), + ATTR(0, "prev", 0444), + ATTR(0, "exec", 0666), + ATTR(0, "fscreate", 0666), + ATTR(0, "keycreate", 0666), + ATTR(0, "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 b701d0207edf..18db9722c81b 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 33ed1860b96f..2d09e818a7d1 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -475,10 +475,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); @@ -1346,14 +1345,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 a590fa98ddd6..a0f4af2da5f3 100644 --- a/security/security.c +++ b/security/security.c @@ -2169,26 +2169,25 @@ void security_d_instantiate(struct dentry *dentry, struct inode *inode) } EXPORT_SYMBOL(security_d_instantiate); -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->lsm)) + if (lsmid != 0 && lsmid != hp->lsmid->id) continue; return hp->hook.getprocattr(p, name, value); } return LSM_RET_DEFAULT(getprocattr); } -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->lsm)) + if (lsmid != 0 && lsmid != hp->lsmid->id) continue; return hp->hook.setprocattr(name, value, size); } -- 2.39.0