sysctl: allow override of /proc/sys/net with CAP_NET_ADMIN

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Linux Kernel Mailing List
Date: Friday, July 25, 2008 - 12:10 pm

Gitweb:     http://git.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=4ecb90...
Commit:     4ecb90090c84210a8bd2a9d7a5906e616735873c
Parent:     99541c23cd32bacf1a591ca537a7c0cb9053ad7e
Author:     Stephen Hemminger <shemminger@vyatta.com>
AuthorDate: Fri Jul 25 01:48:32 2008 -0700
Committer:  Linus Torvalds <torvalds@linux-foundation.org>
CommitDate: Fri Jul 25 10:53:45 2008 -0700

    sysctl: allow override of /proc/sys/net with CAP_NET_ADMIN
    
    Extend the permission check for networking sysctl's to allow modification
    when current process has CAP_NET_ADMIN capability and is not root.  This
    version uses the until now unused permissions hook to override the mode
    value for /proc/sys/net if accessed by a user with capabilities.
    
    Found while working with Quagga.  It is impossible to turn forwarding
    on/off through the command interface because Quagga uses secure coding
    practice of dropping privledges during initialization and only raising via
    capabilities when necessary.  Since the dameon has reset real/effective
    uid after initialization, all attempts to access /proc/sys/net variables
    will fail.
    
    Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>
    Acked-by: "Eric W. Biederman" <ebiederm@xmission.com>
    Cc: Chris Wright <chrisw@sous-sol.org>
    Cc: Alexey Dobriyan <adobriyan@gmail.com>
    Cc: Andrew Morgan <morgan@kernel.org>
    Cc: Pavel Emelyanov <xemul@openvz.org>
    Cc: "David S. Miller" <davem@davemloft.net>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
---
 net/sysctl_net.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/net/sysctl_net.c b/net/sysctl_net.c
index 007c1a6..63ada43 100644
--- a/net/sysctl_net.c
+++ b/net/sysctl_net.c
@@ -35,8 +35,22 @@ net_ctl_header_lookup(struct ctl_table_root *root, struct nsproxy *namespaces)
 	return &namespaces->net_ns->sysctl_table_headers;
 }
 
+/* Return standard mode bits for table entry. */
+static int net_ctl_permissions(struct ctl_table_root *root,
+			       struct nsproxy *nsproxy,
+			       struct ctl_table *table)
+{
+	/* Allow network administrator to have same access as root. */
+	if (capable(CAP_NET_ADMIN)) {
+		int mode = (table->mode >> 6) & 7;
+		return (mode << 6) | (mode << 3) | mode;
+	}
+	return table->mode;
+}
+
 static struct ctl_table_root net_sysctl_root = {
 	.lookup = net_ctl_header_lookup,
+	.permissions = net_ctl_permissions,
 };
 
 static LIST_HEAD(net_sysctl_ro_tables);
--
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
sysctl: allow override of /proc/sys/net with CAP_NET_ADMIN, Linux Kernel Mailing ..., (Fri Jul 25, 12:10 pm)