aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorJohn Fastabend <john.r.fastabend@intel.com>2012-08-14 08:34:24 -0400
committerDavid S. Miller <davem@davemloft.net>2012-08-16 17:56:11 -0400
commitf796c20cf67aa54c9130d0dc41307c0025719b85 (patch)
treeeea2e9d62d56083968683d5df80565c611edfbab /net
parent16c0b164bd24d44db137693a36b428ba28970c62 (diff)
net: netprio: fix files lock and remove useless d_path bits
Add lock to prevent a race with a file closing and also remove useless and ugly sscanf code. The extra code was never needed and the case it supposedly protected against is in fact handled correctly by sock_from_file as pointed out by Al Viro. CC: Neil Horman <nhorman@tuxdriver.com> Reported-by: Al Viro <viro@ZenIV.linux.org.uk> Signed-off-by: John Fastabend <john.r.fastabend@intel.com> Acked-by: Neil Horman <nhorman@tuxdriver.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r--net/core/netprio_cgroup.c22
1 files changed, 4 insertions, 18 deletions
diff --git a/net/core/netprio_cgroup.c b/net/core/netprio_cgroup.c
index ed0c0431fcd8..f65dba3afd99 100644
--- a/net/core/netprio_cgroup.c
+++ b/net/core/netprio_cgroup.c
@@ -277,12 +277,6 @@ out_free_devname:
277void net_prio_attach(struct cgroup *cgrp, struct cgroup_taskset *tset) 277void net_prio_attach(struct cgroup *cgrp, struct cgroup_taskset *tset)
278{ 278{
279 struct task_struct *p; 279 struct task_struct *p;
280 char *tmp = kzalloc(sizeof(char) * PATH_MAX, GFP_KERNEL);
281
282 if (!tmp) {
283 pr_warn("Unable to attach cgrp due to alloc failure!\n");
284 return;
285 }
286 280
287 cgroup_taskset_for_each(p, cgrp, tset) { 281 cgroup_taskset_for_each(p, cgrp, tset) {
288 unsigned int fd; 282 unsigned int fd;
@@ -296,32 +290,24 @@ void net_prio_attach(struct cgroup *cgrp, struct cgroup_taskset *tset)
296 continue; 290 continue;
297 } 291 }
298 292
299 rcu_read_lock(); 293 spin_lock(&files->file_lock);
300 fdt = files_fdtable(files); 294 fdt = files_fdtable(files);
301 for (fd = 0; fd < fdt->max_fds; fd++) { 295 for (fd = 0; fd < fdt->max_fds; fd++) {
302 char *path;
303 struct file *file; 296 struct file *file;
304 struct socket *sock; 297 struct socket *sock;
305 unsigned long s; 298 int err;
306 int rv, err = 0;
307 299
308 file = fcheck_files(files, fd); 300 file = fcheck_files(files, fd);
309 if (!file) 301 if (!file)
310 continue; 302 continue;
311 303
312 path = d_path(&file->f_path, tmp, PAGE_SIZE);
313 rv = sscanf(path, "socket:[%lu]", &s);
314 if (rv <= 0)
315 continue;
316
317 sock = sock_from_file(file, &err); 304 sock = sock_from_file(file, &err);
318 if (!err) 305 if (sock)
319 sock_update_netprioidx(sock->sk, p); 306 sock_update_netprioidx(sock->sk, p);
320 } 307 }
321 rcu_read_unlock(); 308 spin_unlock(&files->file_lock);
322 task_unlock(p); 309 task_unlock(p);
323 } 310 }
324 kfree(tmp);
325} 311}
326 312
327static struct cftype ss_files[] = { 313static struct cftype ss_files[] = {