Re: crazy swapping

Linus Torvalds (torvalds@transmeta.com)
29 Nov 1998 19:14:22 GMT


In article <Pine.LNX.3.94.981129173357.8823A-100000@artax.karlin.mff.cuni.cz>,
Mikulas Patocka <mikulas@artax.karlin.mff.cuni.cz> wrote:
>When you create a file that have holes (using
>creat();lseek(10000000);write("xxx");close()), and make it swap file,
>system crashes and you get "rw_swap_page: bad swap file" message. Tested
>on 2.0.33 and 2.1.129.

Don't do that, then.

It's actually documented, and as only root can do a "swapon()" anyway,
the simple solution is to not do anything stupid as root.

And no, the kernel shouldn't even check for this. If you want to make
the "swapon" binary do some extra sanity checks, you could make it do
somehting like this:

if (stat(filename, &st) < 0) {
perror(filename);
exit(1);
}
if (S_ISREG(st.st_mode)) {
if (st.st_blocks * 512 < st.st_size) {
fprintf(stderr, "File %s appears to have holes in it. Aborting\n", filename);
exit(1);
}
}
swapon(filename);

so I don't want to add the check to the kernel - because it can
obviously easily be done in user space.

Linus

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