1
From: Andreas Gruenbacher <agruen@suse.de>
2
Subject: Factor out sysctl pathname code
4
Convert the selinux sysctl pathname computation code into a standalone
7
Signed-off-by: Andreas Gruenbacher <agruen@suse.de>
8
Signed-off-by: John Johansen <jjohansen@suse.de>
9
Reviewed-by: James Morris <jmorris@namei.org>
12
include/linux/sysctl.h | 2 ++
13
kernel/sysctl.c | 27 +++++++++++++++++++++++++++
14
security/selinux/hooks.c | 35 +++++------------------------------
15
3 files changed, 34 insertions(+), 30 deletions(-)
17
--- a/include/linux/sysctl.h
18
+++ b/include/linux/sysctl.h
19
@@ -983,6 +983,8 @@ extern int proc_doulongvec_minmax(struct
20
extern int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int,
21
struct file *, void __user *, size_t *, loff_t *);
23
+extern char *sysctl_pathname(ctl_table *, char *, int);
25
extern int do_sysctl (int __user *name, int nlen,
26
void __user *oldval, size_t __user *oldlenp,
27
void __user *newval, size_t newlen);
30
@@ -1327,6 +1327,33 @@ struct ctl_table_header *sysctl_head_nex
34
+char *sysctl_pathname(ctl_table *table, char *buffer, int buflen)
42
+ int namelen = strlen(table->procname);
44
+ if (buflen < namelen + 1)
46
+ buflen -= namelen + 1;
48
+ memcpy(buffer, table->procname, namelen);
50
+ table = table->parent;
55
+ memcpy(buffer, "/sys", 4);
59
+EXPORT_SYMBOL(sysctl_pathname);
61
#ifdef CONFIG_SYSCTL_SYSCALL
62
int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
63
void __user *newval, size_t newlen)
64
--- a/security/selinux/hooks.c
65
+++ b/security/selinux/hooks.c
66
@@ -1431,40 +1431,15 @@ static int selinux_capable(struct task_s
68
static int selinux_sysctl_get_sid(ctl_table *table, u16 tclass, u32 *sid)
71
- char *buffer, *path, *end;
72
+ char *buffer, *path;
76
buffer = (char*)__get_free_page(GFP_KERNEL);
81
- end = buffer+buflen;
87
- const char *name = table->procname;
88
- size_t namelen = strlen(name);
89
- buflen -= namelen + 1;
93
- memcpy(end, name, namelen);
96
- table = table->parent;
102
- memcpy(end, "/sys", 4);
104
- rc = security_genfs_sid("proc", path, tclass, sid);
106
+ path = sysctl_pathname(table, buffer, PAGE_SIZE);
108
+ rc = security_genfs_sid("proc", path, tclass, sid);
109
free_page((unsigned long)buffer);