Re: Automated fsck on boot

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Jari,

On Sat, Apr 08, 2006 at 09:00:14PM +0300, Jari Ruusu wrote:
> Cool. But mount code needs one more check: it must make sure that
> loop backing device is exactly the one it is supposed to be. Not
> checking that could be security hole. It also prevents "pilot
> errors" that occasionally happen, even to me. Mount refusing to
> mount because a loop device was already in other use has saved my
> ass multiple times.  :)

I'm happy that you like the idea. :-)

Does the attached version do the right thing in this regard? It
works for me and takes the normal code path if lo_file_name doesn't
match the loopfile that was given in *spec.

cheers,
Max
--- 2.12r/mount/lomount.c~	2006-04-09 00:17:29.000000000 +0200
+++ 2.12r/mount/lomount.c	2006-04-09 00:17:47.000000000 +0200
@@ -202,6 +202,30 @@
 	return 0;
 }
 
+int is_loop_active(const char *dev, const char *backdev)
+{
+	int fd;
+	int ret = 0;
+	struct stat statbuf;
+	struct loop_info64 loopinfo;
+	if (stat (dev, &statbuf) == 0 && S_ISBLK(statbuf.st_mode)) {
+		fd = open (dev, O_RDONLY);
+		if (fd < 0)
+			return 0;
+		if (is_unused_loop_device(fd) == 0) {
+			if (loop_get_status64_ioctl(fd, &loopinfo) < 0) {
+				close (fd);
+				return 0;
+			}
+			loopinfo.lo_file_name[LO_NAME_SIZE-1] = 0;
+			if (!strcmp((char *)loopinfo.lo_file_name, backdev))
+				ret = 1; /* backing device matches */
+		}
+		close(fd);
+	}
+	return ret;
+}
+
 static int rd_wr_retry(int fd, char *buf, int cnt, int w)
 {
 	int x, y, z;
--- 2.12r/mount/lomount.h~	2006-04-09 00:17:29.000000000 +0200
+++ 2.12r/mount/lomount.h	2006-04-09 00:17:47.000000000 +0200
@@ -2,6 +2,7 @@
 extern int set_loop(const char *, const char *, int *, const char **, unsigned int *);
 extern int del_loop(const char *);
 extern int is_loop_device(const char *);
+extern int is_loop_active(const char *, const char *);
 extern char * find_unused_loop_device(void);
 
 extern char *passFDnumber;
--- 2.12r/mount/mount.c~	2006-04-09 00:17:29.000000000 +0200
+++ 2.12r/mount/mount.c	2006-04-09 00:17:47.000000000 +0200
@@ -682,6 +682,10 @@
     if (fake) {
       if (verbose)
 	printf(_("mount: skipping the setup of a loop device\n"));
+    } else if (*loopdev && is_loop_active(*loopdev, *loopfile)) {
+      if (verbose)
+	printf(_("mount: skipping the setup of a loop device\n"));
+      *spec = *loopdev;
     } else {
       int loopro = (*flags & MS_RDONLY);
 

[Index of Archives]     [Kernel]     [Linux Crypto]     [Gnu Crypto]     [Gnu Classpath]     [Netfilter]     [Bugtraq]
  Powered by Linux