lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:	Thu, 19 Jul 2012 14:02:30 -0500
From:	Eric Sandeen <sandeen@...hat.com>
To:	ext4 development <linux-ext4@...r.kernel.org>
CC:	Kazuya Mio <k-mio@...jp.nec.com>
Subject: [PATCH] e4defrag: Handle device symlinks

Device nodes are commonly accessed via symlinks, i.e.

# ls -l /dev/mapper/testvg-testlv 
lrwxrwxrwx. 1 root root 7 Jul 19 13:01 /dev/mapper/testvg-testlv -> ../dm-0

Today, e4defrag on such a device will fail:

# e4defrag -c /dev/mapper/testvg-testlv 
File is not regular file
 "/dev/mapper/testvg-testlv"

due to it being a link, and e4defrag on the link target does as well:

# e4defrag -c /dev/dm-0 
Filesystem is not mounted

due to the target not being found in /etc/mtab.

Fix this by checking whether the symlink target is a block device
and if so, using that device in main(), and also changing get_mount_point()
to search for a matching device number, not device name.

Signed-off-by: Eric Sandeen <sandeen@...hat.com>
---


diff --git a/misc/e4defrag.c b/misc/e4defrag.c
index 6491edd..260265c 100644
--- a/misc/e4defrag.c
+++ b/misc/e4defrag.c
@@ -266,8 +266,15 @@ static int get_mount_point(const char *devname, char *mount_point,
 {
 	/* Refer to /etc/mtab */
 	const char	*mtab = MOUNTED;
-	FILE	*fp = NULL;
+	FILE		*fp = NULL;
 	struct mntent	*mnt = NULL;
+	struct stat64	sb;
+
+	if (stat64(devname, &sb) < 0) {
+		perror(NGMSG_FILE_INFO);
+		PRINT_FILE_NAME(devname);
+		return -1;
+	}
 
 	fp = setmntent(mtab, "r");
 	if (fp == NULL) {
@@ -276,7 +283,15 @@ static int get_mount_point(const char *devname, char *mount_point,
 	}
 
 	while ((mnt = getmntent(fp)) != NULL) {
-		if (strcmp(devname, mnt->mnt_fsname) != 0)
+		struct stat64 ms;
+
+		/*
+		 * To handle device symlinks, we see if the
+ 		 * device number matches, not the name
+ 		 */
+		if (stat64(mnt->mnt_fsname, &ms) < 0)
+			continue;
+		if (sb.st_rdev != ms.st_rdev)
 			continue;
 
 		endmntent(fp);
@@ -1770,6 +1785,15 @@ int main(int argc, char *argv[])
 			continue;
 		}
 
+		/* Handle i.e. lvm device symlinks */
+		if (S_ISLNK(buf.st_mode)) {
+			struct stat64	buf2;
+
+			if (stat64(argv[i], &buf2) == 0 &&
+			    S_ISBLK(buf2.st_mode))
+				buf = buf2;
+		}
+
 		if (S_ISBLK(buf.st_mode)) {
 			/* Block device */
 			strncpy(dev_name, argv[i], strnlen(argv[i], PATH_MAX));


--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ