[PATCH] net: net_prio: Block attach if a socket is shared

From: Daniel Wagner
Date: Tue Jan 22 2013 - 05:08:22 EST


---
net/core/netprio_cgroup.c | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)

diff --git a/net/core/netprio_cgroup.c b/net/core/netprio_cgroup.c
index 847c02b..de4e6c5 100644
--- a/net/core/netprio_cgroup.c
+++ b/net/core/netprio_cgroup.c
@@ -274,9 +274,39 @@ static struct cftype ss_files[] = {
{ } /* terminate */
};

+static int check_cnt(const void *v, struct file *file, unsigned n)
+{
+ unsigned *flag = (unsigned *)v;
+ int err;
+
+ struct socket *sock = sock_from_file(file, &err);
+ if (sock && file_count(file) > 1)
+ *flag = 1;
+
+ return 0;
+}
+
+static int cgrp_can_attach(struct cgroup *cgrp, struct cgroup_taskset *tset)
+{
+ struct task_struct *p;
+ unsigned flag = 0;
+
+ cgroup_taskset_for_each(p, cgrp, tset) {
+ task_lock(p);
+ iterate_fd(p->files, 0, check_cnt, &flag);
+ task_unlock(p);
+ }
+
+ if (flag != 0)
+ return -EINVAL;
+
+ return 0;
+}
+
struct cgroup_subsys net_prio_subsys = {
.name = "net_prio",
.create = cgrp_create,
+ .can_attach = cgrp_can_attach,
.destroy = cgrp_destroy,
.attach = net_prio_attach,
.subsys_id = net_prio_subsys_id,
--
1.8.0.rc0



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/