linux-lvm.redhat.com archive mirror
 help / color / mirror / Atom feed
From: Bastian Blank <waldi@debian.org>
To: linux-lvm@redhat.com
Cc: Alasdair G Kergon <agk@redhat.com>
Subject: [linux-lvm] [iwj@ubuntu.com: Bug#402132: lvm2 racey symlink creation]
Date: Fri, 8 Dec 2006 15:07:34 +0100	[thread overview]
Message-ID: <20061208140734.GA20472@wavehammer.waldi.eu.org> (raw)

----- Forwarded message from Ian Jackson <iwj@ubuntu.com> -----

Date: Fri, 8 Dec 2006 12:20:05 +0000
From: Ian Jackson <iwj@ubuntu.com>
To: submit@bugs.debian.org
Subject: Bug#402132: lvm2 racey symlink creation

Package: lvm2
Version: 2.02.06-2
Tags: patch

When the lvm2 utilities vgchange, vgmknodes, et al, create the
/dev/<vg>/<lv> symlinks, they do it like this
    lstat
    unlink
    symlink

This means that even if the vg is and remains active throughout, there
is a moment when the symlink is missing.  Any other program on the
system which is referring to that lv may see this glitch and
misbehave.

The patch below fixes this.  It now does this instead:
    stat
    symlink to /dev/<vg>/<lv>..tmp
    rename the ..tmp symlink to /dev/<vg>/<lv>

FYI, we will be deploying this change in the forthcoming Ubuntu
release.

Thanks for your attention,
Ian.

diff -ruN --exclude='*~' orig/lvm2-2.02.06/lib/activate/fs.c lvm2-2.02.06/lib/activate/fs.c
--- orig/lvm2-2.02.06/lib/activate/fs.c	2005-11-15 17:45:32.000000000 +0000
+++ lvm2-2.02.06/lib/activate/fs.c	2006-12-08 12:16:32.000000000 +0000
@@ -106,7 +106,7 @@
 		    const char *lv_name, const char *dev)
 {
 	char lv_path[PATH_MAX], link_path[PATH_MAX], lvm1_group_path[PATH_MAX];
-	char vg_path[PATH_MAX];
+	char vg_path[PATH_MAX], lv_path_tmp[PATH_MAX];
 	struct stat buf;
 
 	if (lvm_snprintf(vg_path, sizeof(vg_path), "%s%s",
@@ -123,6 +123,13 @@
 		return 0;
 	}
 
+	if (lvm_snprintf(lv_path_tmp, sizeof(lv_path_tmp), "%s..tmp",
+			 lv_path) == -1) {
+		log_error("Couldn't create temporary pathname for "
+			  "logical volume link %s", lv_path);
+		return 0;
+	}
+
 	if (lvm_snprintf(link_path, sizeof(link_path), "%s/%s",
 			 dm_dir(), dev) == -1) {
 		log_error("Couldn't create destination pathname for "
@@ -160,17 +167,11 @@
 				  link_path);
 			return 0;
 		}
-
-		log_very_verbose("Removing %s", lv_path);
-		if (unlink(lv_path) < 0) {
-			log_sys_error("unlink", lv_path);
-			return 0;
-		}
 	}
 
-	log_very_verbose("Linking %s -> %s", lv_path, link_path);
-	if (symlink(link_path, lv_path) < 0) {
-		log_sys_error("symlink", lv_path);
+	log_very_verbose("Linking %s -> %s", lv_path_tmp, link_path);
+	if (symlink(link_path, lv_path_tmp) < 0) {
+		log_sys_error("symlink", lv_path_tmp);
 		return 0;
 	}
 
@@ -181,6 +182,12 @@
         }
 #endif
 
+	log_very_verbose("Installing symlink %s as %s", lv_path_tmp, lv_path);
+	if (rename(lv_path_tmp, lv_path) < 0) {
+		log_sys_error("rename", lv_path_tmp);
+		return 0;
+	}
+
 	return 1;
 }

----- End forwarded message -----

-- 
Violence in reality is quite different from theory.
		-- Spock, "The Cloud Minders", stardate 5818.4

                 reply	other threads:[~2006-12-08 14:07 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20061208140734.GA20472@wavehammer.waldi.eu.org \
    --to=waldi@debian.org \
    --cc=agk@redhat.com \
    --cc=linux-lvm@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).