2.4.36-stable kernel tree
Revision | 57812a4772fa73f264b59ae31c5cc277630b1ff5 (tree) |
---|---|
Zeit | 2008-11-10 00:22:14 |
Autor | David Miller <davem@dave...> |
Commiter | Willy Tarreau |
net: Fix recursive descent in scm_destroy().
[backport of 2.6 commit f8d570a4745835f2238a33b537218a1bb03fc671]
scm_destroy() walks the list of file descriptors in the scm_fp_list
pointed to by the scm_cookie argument.
Those, in turn, can close sockets and invoke scm_destroy() again.
There is nothing which limits how deeply this can occur.
The idea for how to fix this is from Linus. Basically, we do all of
the fput()s at the top level by collecting all of the scm_fp_list
objects hit by an fput(). Inside of the initial scm_destroy() we
keep running the list until it is empty.
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Willy Tarreau <w@1wt.eu>
@@ -415,6 +415,8 @@ struct task_struct { | ||
415 | 415 | |
416 | 416 | /* journalling filesystem info */ |
417 | 417 | void *journal_info; |
418 | + | |
419 | + struct list_head *scm_work_list; | |
418 | 420 | }; |
419 | 421 | |
420 | 422 | /* |
@@ -8,8 +8,9 @@ | ||
8 | 8 | |
9 | 9 | struct scm_fp_list |
10 | 10 | { |
11 | - int count; | |
12 | - struct file *fp[SCM_MAX_FD]; | |
11 | + struct list_head list; | |
12 | + int count; | |
13 | + struct file *fp[SCM_MAX_FD]; | |
13 | 14 | }; |
14 | 15 | |
15 | 16 | struct scm_cookie |
@@ -70,6 +70,7 @@ static int scm_fp_copy(struct cmsghdr *cmsg, struct scm_fp_list **fplp) | ||
70 | 70 | if (!fpl) |
71 | 71 | return -ENOMEM; |
72 | 72 | *fplp = fpl; |
73 | + INIT_LIST_HEAD(&fpl->list); | |
73 | 74 | fpl->count = 0; |
74 | 75 | } |
75 | 76 | fpp = &fpl->fp[fpl->count]; |
@@ -101,9 +102,25 @@ void __scm_destroy(struct scm_cookie *scm) | ||
101 | 102 | |
102 | 103 | if (fpl) { |
103 | 104 | scm->fp = NULL; |
104 | - for (i=fpl->count-1; i>=0; i--) | |
105 | - fput(fpl->fp[i]); | |
106 | - kfree(fpl); | |
105 | + if (current->scm_work_list) { | |
106 | + list_add_tail(&fpl->list, current->scm_work_list); | |
107 | + } else { | |
108 | + LIST_HEAD(work_list); | |
109 | + | |
110 | + current->scm_work_list = &work_list; | |
111 | + | |
112 | + list_add(&fpl->list, &work_list); | |
113 | + while (!list_empty(&work_list)) { | |
114 | + fpl = list_entry(work_list.next, struct scm_fp_list, list); | |
115 | + | |
116 | + list_del(&fpl->list); | |
117 | + for (i=fpl->count-1; i>=0; i--) | |
118 | + fput(fpl->fp[i]); | |
119 | + kfree(fpl); | |
120 | + } | |
121 | + | |
122 | + current->scm_work_list = NULL; | |
123 | + } | |
107 | 124 | } |
108 | 125 | } |
109 | 126 |
@@ -263,6 +280,7 @@ struct scm_fp_list *scm_fp_dup(struct scm_fp_list *fpl) | ||
263 | 280 | |
264 | 281 | new_fpl = kmalloc(sizeof(*fpl), GFP_KERNEL); |
265 | 282 | if (new_fpl) { |
283 | + INIT_LIST_HEAD(&new_fpl->list); | |
266 | 284 | for (i=fpl->count-1; i>=0; i--) |
267 | 285 | get_file(fpl->fp[i]); |
268 | 286 | memcpy(new_fpl, fpl, sizeof(*fpl)); |