netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: add sysctl allow_so_priority for SO_PRIORITY setsockopt
@ 2011-10-21 22:22 Maciej Żenczykowski
  2011-10-22  4:04 ` David Miller
  0 siblings, 1 reply; 7+ messages in thread
From: Maciej Żenczykowski @ 2011-10-21 22:22 UTC (permalink / raw)
  To: Maciej Żenczykowski; +Cc: netdev, Maciej Żenczykowski

From: Maciej Żenczykowski <maze@google.com>

This change adds a sysctl (/proc/sys/net/core/allow_so_priority)
with a default of true (1), as such it does not change the default
behaviour of the Linux kernel.

This sysctl can be set to false (0), this will result in non
CAP_NET_ADMIN processes being unable to set SO_PRIORITY socket
option.

This is desireable if we want to rely on socket/skb priorities
being inferred from TOS/TCLASS bits.

Signed-off-by: Maciej Żenczykowski <maze@google.com>
---
 include/net/sock.h         |    2 ++
 net/core/sock.c            |    5 ++++-
 net/core/sysctl_net_core.c |    7 +++++++
 3 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/include/net/sock.h b/include/net/sock.h
index 5ac682f..bf18a6a 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -1853,6 +1853,8 @@ extern __u32 sysctl_rmem_max;
 
 extern void sk_init(void);
 
+extern int sysctl_allow_so_priority;
+
 extern int sysctl_optmem_max;
 
 extern __u32 sysctl_wmem_default;
diff --git a/net/core/sock.c b/net/core/sock.c
index 5a08762..383fd89 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -217,6 +217,8 @@ __u32 sysctl_rmem_max __read_mostly = SK_RMEM_MAX;
 __u32 sysctl_wmem_default __read_mostly = SK_WMEM_MAX;
 __u32 sysctl_rmem_default __read_mostly = SK_RMEM_MAX;
 
+int sysctl_allow_so_priority __read_mostly = 1;
+
 /* Maximal space eaten by iovec or ancillary data plus some space */
 int sysctl_optmem_max __read_mostly = sizeof(unsigned long)*(2*UIO_MAXIOV+512);
 EXPORT_SYMBOL(sysctl_optmem_max);
@@ -612,7 +614,8 @@ set_rcvbuf:
 		break;
 
 	case SO_PRIORITY:
-		if ((val >= 0 && val <= 6) || capable(CAP_NET_ADMIN))
+		if ((val >= 0 && val <= 6 && sysctl_allow_so_priority)
+		    || capable(CAP_NET_ADMIN))
 			sk->sk_priority = val;
 		else
 			ret = -EPERM;
diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
index 77a65f0..91fdaac 100644
--- a/net/core/sysctl_net_core.c
+++ b/net/core/sysctl_net_core.c
@@ -183,6 +183,13 @@ static struct ctl_table net_core_table[] = {
 		.mode		= 0644,
 		.proc_handler	= proc_dointvec
 	},
+	{
+		.procname	= "allow_so_priority",
+		.data		= &sysctl_allow_so_priority,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec
+	},
 	{ }
 };
 
-- 
1.7.3.1

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-10-22  9:01 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-21 22:22 [PATCH] net: add sysctl allow_so_priority for SO_PRIORITY setsockopt Maciej Żenczykowski
2011-10-22  4:04 ` David Miller
2011-10-22  6:49   ` Maciej Żenczykowski
2011-10-22  6:58     ` David Miller
2011-10-22  8:27       ` Maciej Żenczykowski
2011-10-22  8:40         ` David Miller
2011-10-22  9:01         ` David Täht

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).