From: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
To: linux-kernel@vger.kernel.org
Subject: [PATCH][4/5] Add inode_operations for proc sysctl
Date: Sun, 20 Mar 2005 11:14:43 +0100 [thread overview]
Message-ID: <1111313683.C4EFe5.17773@neapel230.server4you.de> (raw)
In-Reply-To: <1111278162.22BA.5209@neapel230.server4you.de>
Add getattr and permission inode_operations for base /proc/<pid> entries
that make sure the value of inode->i_mode is up-to-date with its
respective sysctl setting. This is achieved by calling the new function
proc_update_mode. It currently spares the init process.
diff -pur l1/fs/proc/base.c l2/fs/proc/base.c
--- l1/fs/proc/base.c 2005-03-19 20:08:30.000000000 +0100
+++ l2/fs/proc/base.c 2005-03-19 20:08:39.000000000 +0100
@@ -243,6 +243,40 @@ static struct pid_entry tid_attr_stuff[]
mode_t proc_base_permissions[] = {
S_IRUGO, /* PROC_CMDLINE */
};
+
+static void proc_update_mode(struct inode *inode)
+{
+ struct task_struct *task = proc_task(inode);
+ int ctl_name = proc_ctl_name(inode);
+
+ if (ctl_name == 0)
+ return;
+ if (task->pid == 1) /* Don't touch init. TODO: kernel threads? */
+ return;
+ inode->i_mode = (inode->i_mode & ~S_IALLUGO) |
+ proc_base_permissions[ctl_name-1];
+}
+
+static int proc_base_permission(struct inode *inode, int mask,
+ struct nameidata *nd)
+{
+ proc_update_mode(inode);
+ return generic_permission(inode, mask, NULL);
+}
+
+static int proc_base_getattr(struct vfsmount *mnt, struct dentry *dentry,
+ struct kstat *stat)
+{
+ struct inode *inode = dentry->d_inode;
+ proc_update_mode(inode);
+ generic_fillattr(inode, stat);
+ return 0;
+}
+
+static struct inode_operations proc_base_inode_operations = {
+ .getattr = proc_base_getattr,
+ .permission = proc_base_permission,
+};
#endif /* CONFIG_SYSCTL */
static int proc_fd_link(struct inode *inode, struct dentry **dentry, struct vfsmount **mnt)
@@ -1474,6 +1508,8 @@ static struct dentry *proc_pident_lookup
ei = PROC_I(inode);
#ifdef CONFIG_SYSCTL
ei->ctl_name = p->ctl_name;
+ proc_update_mode(inode);
+ inode->i_op = &proc_base_inode_operations;
#endif
inode->i_mode = p->mode;
/*
next prev parent reply other threads:[~2005-03-20 10:17 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-03-20 0:22 [PATCH][0/6] Change proc file permissions with sysctls Rene Scharfe
2005-03-20 4:22 ` Bodo Eggert
2005-03-20 6:08 ` Albert Cahalan
2005-03-20 9:48 ` Jan Engelhardt
2005-03-20 10:14 ` [PATCH][3/5] New member for proc_inode: ctl_name Rene Scharfe
2005-03-20 10:14 ` [PATCH][6/5] Bonus: unrelated minor cleanup of enum pid_directory_inos Rene Scharfe
2005-03-20 10:14 ` Rene Scharfe [this message]
2005-03-20 10:14 ` [PATCH][1/5] Introduce proc_domode Rene Scharfe
2005-03-20 10:32 ` Jan Engelhardt
2005-03-20 10:40 ` Rene Scharfe
2005-03-20 10:14 ` [PATCH][2/5] Sysctl for proc Rene Scharfe
2005-03-20 10:14 ` [PATCH][5/5] Four more sysctls Rene Scharfe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1111313683.C4EFe5.17773@neapel230.server4you.de \
--to=rene.scharfe@lsrfire.ath.cx \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®