swapon() bug and patch

Patrick (patrick@cs.virginia.edu)
Tue, 6 Oct 1998 04:25:05 -0400 (EDT)


Calling swapon() repeatedly with the same special file returns success
where it shouldn't. The same file gets added repeatedly to swap space,
which presumably would cause real nastiness when the kernel wants to use
the same file twice at once.

The fix is to check the dentry->d_count, as 2.0.* checked the
inode->i_count. A patch (against 2.1.121 or newer) to do this is below.

(Caveat: newbie submission. If I'm dead wrong, just say so... I'm right
about the bug, anyway. :)

--Patrick

--- linux/mm/swapfile.c.orig Tue Oct 6 03:34:26 1998
+++ linux/mm/swapfile.c Tue Oct 6 04:09:35 1998
@@ -535,6 +535,10 @@
goto bad_swap_2;

p->swap_file = swap_dentry;
+ if (swap_dentry->d_count != 1) {
+ error = -EBUSY;
+ goto bad_swap_2;
+ }
error = -EINVAL;

if (S_ISBLK(swap_dentry->d_inode->i_mode)) {

-
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/