mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Miklos Szeredi <miklos@szeredi.hu>
To: linux-fsdevel@vger.kernel.org
Cc: hch@infradead.org, viro@ZenIV.linux.org.uk,
	linux-kernel@vger.kernel.org,
	Andreas Gruenbacher <agruen@suse.de>,
	John Johansen <jjohansen@suse.de>
Subject: [patch 6/8] Factor out sysctl pathname code
Date: Thu, 29 May 2008 13:32:51 +0200	[thread overview]
Message-ID: <20080529113315.284080903@szeredi.hu> (raw)
In-Reply-To: <20080529113245.450308367@szeredi.hu>

[-- Attachment #1: sysctl-pathname.diff --]
[-- Type: text/plain, Size: 3505 bytes --]

Convert the selinux sysctl pathname computation code into a standalone
function.

Signed-off-by: Andreas Gruenbacher <agruen@suse.de>
Signed-off-by: John Johansen <jjohansen@suse.de>
Reviewed-by: James Morris <jmorris@namei.org>
Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
---
 include/linux/sysctl.h   |    2 ++
 kernel/sysctl.c          |   27 +++++++++++++++++++++++++++
 security/selinux/hooks.c |   35 +++++------------------------------
 3 files changed, 34 insertions(+), 30 deletions(-)

Index: linux-2.6/include/linux/sysctl.h
===================================================================
--- linux-2.6.orig/include/linux/sysctl.h	2008-05-29 12:46:20.000000000 +0200
+++ linux-2.6/include/linux/sysctl.h	2008-05-29 12:46:25.000000000 +0200
@@ -980,6 +980,8 @@ extern int proc_doulongvec_minmax(struct
 extern int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int,
 				      struct file *, void __user *, size_t *, loff_t *);
 
+extern char *sysctl_pathname(ctl_table *, char *, int);
+
 extern int do_sysctl (int __user *name, int nlen,
 		      void __user *oldval, size_t __user *oldlenp,
 		      void __user *newval, size_t newlen);
Index: linux-2.6/kernel/sysctl.c
===================================================================
--- linux-2.6.orig/kernel/sysctl.c	2008-05-29 12:46:20.000000000 +0200
+++ linux-2.6/kernel/sysctl.c	2008-05-29 12:46:25.000000000 +0200
@@ -1432,6 +1432,33 @@ void register_sysctl_root(struct ctl_tab
 	spin_unlock(&sysctl_lock);
 }
 
+char *sysctl_pathname(ctl_table *table, char *buffer, int buflen)
+{
+	if (buflen < 1)
+		return NULL;
+	buffer += --buflen;
+	*buffer = '\0';
+
+	while (table) {
+		int namelen = strlen(table->procname);
+
+		if (buflen < namelen + 1)
+			return NULL;
+		buflen -= namelen + 1;
+		buffer -= namelen;
+		memcpy(buffer, table->procname, namelen);
+		*--buffer = '/';
+		table = table->parent;
+	}
+	if (buflen < 4)
+		return NULL;
+	buffer -= 4;
+	memcpy(buffer, "/sys", 4);
+
+	return buffer;
+}
+EXPORT_SYMBOL(sysctl_pathname);
+
 #ifdef CONFIG_SYSCTL_SYSCALL
 /* Perform the actual read/write of a sysctl table entry. */
 static int do_sysctl_strategy(struct ctl_table_root *root,
Index: linux-2.6/security/selinux/hooks.c
===================================================================
--- linux-2.6.orig/security/selinux/hooks.c	2008-05-29 12:46:20.000000000 +0200
+++ linux-2.6/security/selinux/hooks.c	2008-05-29 12:46:25.000000000 +0200
@@ -1736,40 +1736,15 @@ static int selinux_capable(struct task_s
 
 static int selinux_sysctl_get_sid(ctl_table *table, u16 tclass, u32 *sid)
 {
-	int buflen, rc;
-	char *buffer, *path, *end;
+	char *buffer, *path;
+	int rc = -ENOMEM;
 
-	rc = -ENOMEM;
 	buffer = (char *)__get_free_page(GFP_KERNEL);
 	if (!buffer)
 		goto out;
-
-	buflen = PAGE_SIZE;
-	end = buffer+buflen;
-	*--end = '\0';
-	buflen--;
-	path = end-1;
-	*path = '/';
-	while (table) {
-		const char *name = table->procname;
-		size_t namelen = strlen(name);
-		buflen -= namelen + 1;
-		if (buflen < 0)
-			goto out_free;
-		end -= namelen;
-		memcpy(end, name, namelen);
-		*--end = '/';
-		path = end;
-		table = table->parent;
-	}
-	buflen -= 4;
-	if (buflen < 0)
-		goto out_free;
-	end -= 4;
-	memcpy(end, "/sys", 4);
-	path = end;
-	rc = security_genfs_sid("proc", path, tclass, sid);
-out_free:
+	path = sysctl_pathname(table, buffer, PAGE_SIZE);
+	if (path)
+		rc = security_genfs_sid("proc", path, tclass, sid);
 	free_page((unsigned long)buffer);
 out:
 	return rc;

--

  parent reply	other threads:[~2008-05-29 11:35 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-29 11:32 [patch 0/8] vfs: more cleanups and fixes Miklos Szeredi
2008-05-29 11:32 ` [patch 1/8] vfs: dcache cleanups Miklos Szeredi
2008-05-29 12:23   ` Matthew Wilcox
2008-05-31  8:18   ` Christoph Hellwig
2008-05-29 11:32 ` [patch 2/8] vfs: fix sys_getcwd for detached mounts Miklos Szeredi
2008-05-31  8:20   ` Christoph Hellwig
2008-05-29 11:32 ` [patch 3/8] Make d_path() consistent across mount operations Miklos Szeredi
2008-05-31  8:22   ` Christoph Hellwig
2008-06-01 20:38     ` Miklos Szeredi
2008-06-02  5:55       ` Christoph Hellwig
2008-05-29 11:32 ` [patch 4/8] nfsd: rename MAY_ flags Miklos Szeredi
2008-05-29 12:47   ` Christoph Hellwig
2008-05-29 14:02     ` Miklos Szeredi
2008-05-29 20:40       ` J. Bruce Fields
2008-05-30  7:36         ` Christoph Hellwig
2008-05-30  9:07           ` Miklos Szeredi
2008-05-30  9:53             ` Miklos Szeredi
2008-05-30 20:12             ` J. Bruce Fields
2008-05-29 11:32 ` [patch 5/8] vfs: annotate permission operations Miklos Szeredi
2008-05-31  8:23   ` Christoph Hellwig
2008-05-29 11:32 ` Miklos Szeredi [this message]
2008-05-31  8:27   ` [patch 6/8] Factor out sysctl pathname code Christoph Hellwig
2008-06-03 13:34     ` Stephen Smalley
2008-05-29 11:32 ` [patch 7/8] vfs: clean up getattr API Miklos Szeredi
2008-05-29 11:32 ` [patch 8/8] vfs: create file_remove_suid() helper Miklos Szeredi
2008-05-31  8:29   ` Christoph Hellwig
2008-06-01 20:45     ` Miklos Szeredi
2008-06-02  6:05       ` Christoph Hellwig
2008-06-02  7:06         ` Miklos Szeredi

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=20080529113315.284080903@szeredi.hu \
    --to=miklos@szeredi.hu \
    --cc=agruen@suse.de \
    --cc=hch@infradead.org \
    --cc=jjohansen@suse.de \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@ZenIV.linux.org.uk \
    /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®