diff options
author | Jeff Dike <jdike@addtoit.com> | 2006-03-27 04:14:39 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-03-27 11:44:38 -0500 |
commit | 1fbbd6844e6a84e5d166ab475dc298d3b89fa4bf (patch) | |
tree | ea00fbae751120e139491f5c30f3275d2f2cf19b /arch/um | |
parent | 98c18238f146a9038098244d60a7d2b1f67ee790 (diff) |
[PATCH] uml: prevent umid theft
Behavior when booting two UMLs with the same umid was broken. The second one
would steal the umid. This fixes that, making the second UML take a random
umid instead.
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Cc: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'arch/um')
-rw-r--r-- | arch/um/os-Linux/umid.c | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/arch/um/os-Linux/umid.c b/arch/um/os-Linux/umid.c index ecf107ae5ac8..198e59163288 100644 --- a/arch/um/os-Linux/umid.c +++ b/arch/um/os-Linux/umid.c | |||
@@ -143,8 +143,10 @@ static int not_dead_yet(char *dir) | |||
143 | goto out_close; | 143 | goto out_close; |
144 | } | 144 | } |
145 | 145 | ||
146 | if((kill(p, 0) == 0) || (errno != ESRCH)) | 146 | if((kill(p, 0) == 0) || (errno != ESRCH)){ |
147 | printk("umid \"%s\" is already in use by pid %d\n", umid, p); | ||
147 | return 1; | 148 | return 1; |
149 | } | ||
148 | 150 | ||
149 | err = actually_do_remove(dir); | 151 | err = actually_do_remove(dir); |
150 | if(err) | 152 | if(err) |
@@ -234,33 +236,44 @@ int __init make_umid(void) | |||
234 | err = mkdir(tmp, 0777); | 236 | err = mkdir(tmp, 0777); |
235 | if(err < 0){ | 237 | if(err < 0){ |
236 | err = -errno; | 238 | err = -errno; |
237 | if(errno != EEXIST) | 239 | if(err != -EEXIST) |
238 | goto err; | 240 | goto err; |
239 | 241 | ||
240 | if(not_dead_yet(tmp) < 0) | 242 | /* 1 -> this umid is already in use |
243 | * < 0 -> we couldn't remove the umid directory | ||
244 | * In either case, we can't use this umid, so return -EEXIST. | ||
245 | */ | ||
246 | if(not_dead_yet(tmp) != 0) | ||
241 | goto err; | 247 | goto err; |
242 | 248 | ||
243 | err = mkdir(tmp, 0777); | 249 | err = mkdir(tmp, 0777); |
244 | } | 250 | } |
245 | if(err < 0){ | 251 | if(err){ |
246 | printk("Failed to create '%s' - err = %d\n", umid, err); | 252 | err = -errno; |
247 | goto err_rmdir; | 253 | printk("Failed to create '%s' - err = %d\n", umid, -errno); |
254 | goto err; | ||
248 | } | 255 | } |
249 | 256 | ||
250 | umid_setup = 1; | 257 | umid_setup = 1; |
251 | 258 | ||
252 | create_pid_file(); | 259 | create_pid_file(); |
253 | 260 | ||
254 | return 0; | 261 | err = 0; |
255 | |||
256 | err_rmdir: | ||
257 | rmdir(tmp); | ||
258 | err: | 262 | err: |
259 | return err; | 263 | return err; |
260 | } | 264 | } |
261 | 265 | ||
262 | static int __init make_umid_init(void) | 266 | static int __init make_umid_init(void) |
263 | { | 267 | { |
268 | if(!make_umid()) | ||
269 | return 0; | ||
270 | |||
271 | /* If initializing with the given umid failed, then try again with | ||
272 | * a random one. | ||
273 | */ | ||
274 | printk("Failed to initialize umid \"%s\", trying with a random umid\n", | ||
275 | umid); | ||
276 | *umid = '\0'; | ||
264 | make_umid(); | 277 | make_umid(); |
265 | 278 | ||
266 | return 0; | 279 | return 0; |