linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* sys_swapoff() symlink bug
@ 2004-03-15 18:52 Michael Buesch
  0 siblings, 0 replies; only message in thread
From: Michael Buesch @ 2004-03-15 18:52 UTC (permalink / raw)
  To: linux kernel mailing list; +Cc: andrea

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

The following script demonstrates a bug in the swapon/swapoff
syscalls in the latest 2.6 kernel (I did not check 2.4).

#/bin/sh
# 3:12 is hda12, which is a swap partition on my system.
SWAP_MAJOR=3
SWAP_MINOR=12
echo "running swaps:"
cat /proc/swaps
echo "--"
mkdir /testdev
mknod /testdev/testnode b $SWAP_MAJOR $SWAP_MINOR
ln -s /testdev/testnode /testdev/testlink
swapon /testdev/testlink
echo "swapon returned $?"
echo "running swaps:"
cat /proc/swaps
echo "--"
swapoff /testdev/testdev
echo "swapoff returned $?"
echo "running swaps:"
cat /proc/swaps
echo "--"
rm -Rf /testdev


The output of this script on my system is:

running swaps:
- --
swapon returned 0
running swaps:
Filename                                Type            Size    Used    Priority
/testdev/testnode                        partition      976712  0       -32
- --
swapoff returned 255
running swaps:
Filename                                Type            Size    Used    Priority
/testdev/testnode                        partition      976712  0       -32
- --


As you can see the swapoff fails, because it is called on
the node instead of the symlink that was used for swapon.
I think this should not fail.

The code that fails to detect, that the symlink _is_ actually
the same swapspace as the node itself, is mm/swapfile.c:1038

	for (type = swap_list.head; type >= 0; type = swap_info[type].next) {
		p = swap_info + type;
		if ((p->flags & SWP_ACTIVE) == SWP_ACTIVE) {

/* I'm not really sure about what we should check here, instead
 * of f_mapping to detect it.
 */
			if (p->swap_file->f_mapping == mapping)
				break;
		}
		prev = type;
	}

- -- 
Regards Michael Buesch  [ http://www.tuxsoft.de.vu ]

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFAVftgFGK1OIvVOP4RAqMeAKCa8YNIziH6/HCYLjTxg98MBzUE+wCgv6pw
qUptbBGt+jCXeDdJpQk71l4=
=+JkD
-----END PGP SIGNATURE-----

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2004-03-15 18:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-15 18:52 sys_swapoff() symlink bug Michael Buesch

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).