linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: NeilBrown <neilb@suse.de>
To: Adam Kwolek <adam.kwolek@intel.com>
Cc: linux-raid@vger.kernel.org, ed.ciechanowski@intel.com,
	marcin.labun@intel.com, dan.j.williams@intel.com
Subject: Re: [PATCH] FIX: Verify if array name doesn't exist already
Date: Fri, 23 Dec 2011 07:15:22 +1100	[thread overview]
Message-ID: <20111223071522.4224782e@notabene.brown> (raw)
In-Reply-To: <20111222142109.5678.19199.stgit@gklab-128-013.igk.intel.com>

[-- Attachment #1: Type: text/plain, Size: 2750 bytes --]

On Thu, 22 Dec 2011 15:21:10 +0100 Adam Kwolek <adam.kwolek@intel.com> wrote:

> When e.g. array name (an) is correct and it is the same as container name (cn),
> file element creation /dev/md/an will replace /dev/md/cn.
> This can cause that user cannot access container using /dev/md/cn.
> 
> Verify during array creation if chosen name is not already existing one.
> 
> Signed-off-by: Adam Kwolek <adam.kwolek@intel.com>
> ---
> 
>  Create.c |   11 +++++++++++
>  1 files changed, 11 insertions(+), 0 deletions(-)
> 
> diff --git a/Create.c b/Create.c
> index 5d1548b..e522d8e 100644
> --- a/Create.c
> +++ b/Create.c
> @@ -558,6 +558,17 @@ int Create(struct supertype *st, char *mddev,
>  		map_unlock(&map);
>  		return 1;
>  	}
> +	/* verify if chosen_name is not in use,
> +	 * it could be in conflict with already existing device
> +	 * e.g. container, array
> +	 */
> +	if (stat(chosen_name, &stb) != -1) {
> +		fprintf(stderr, Name ": Array name %s is in use already.\n",
> +			chosen_name);
> +		close(mdfd);
> +		map_unlock(&map);
> +		return 1;
> +	}
>  	mddev = chosen_name;
>  
>  	vers = md_get_version(mdfd);


Thanks.  However I would rather use map_by_name to check for prior existence,
as create_mddev can actually create the device in /dev if udev is not in use.

So this is what I have committed.

NeilBrown

commit 3e9df86add05b3a759148a8a1760a44887654322
Author: Adam Kwolek <adam.kwolek@intel.com>
Date:   Fri Dec 23 07:13:55 2011 +1100

    FIX: Verify if array name doesn't exist already
    
    When e.g. array name (an) is correct and it is the same as container name (cn),
    file element creation /dev/md/an will replace /dev/md/cn.
    This can cause that user cannot access container using /dev/md/cn.
    
    Verify during array creation if chosen name is not already existing
    one.
    
    [Changed to use map_by_name() rather than stat() to determine prior
     existence - NeilBrown]
    
    
    Signed-off-by: Adam Kwolek <adam.kwolek@intel.com>
    Signed-off-by: NeilBrown <neilb@suse.de>

diff --git a/Create.c b/Create.c
index 5d1548b..90ff3ed 100644
--- a/Create.c
+++ b/Create.c
@@ -558,6 +558,18 @@ int Create(struct supertype *st, char *mddev,
 		map_unlock(&map);
 		return 1;
 	}
+	/* verify if chosen_name is not in use,
+	 * it could be in conflict with already existing device
+	 * e.g. container, array
+	 */
+	if (strncmp(chosen_name, "/dev/md/", 8) == 0
+	    && map_by_name(&map, chosen_name+8) != NULL) {
+		fprintf(stderr, Name ": Array name %s is in use already.\n",
+			chosen_name);
+		close(mdfd);
+		map_unlock(&map);
+		return 1;
+	}
 	mddev = chosen_name;
 
 	vers = md_get_version(mdfd);

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 828 bytes --]

      reply	other threads:[~2011-12-22 20:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-22 14:21 [PATCH] FIX: Verify if array name doesn't exist already Adam Kwolek
2011-12-22 20:15 ` NeilBrown [this message]

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=20111223071522.4224782e@notabene.brown \
    --to=neilb@suse.de \
    --cc=adam.kwolek@intel.com \
    --cc=dan.j.williams@intel.com \
    --cc=ed.ciechanowski@intel.com \
    --cc=linux-raid@vger.kernel.org \
    --cc=marcin.labun@intel.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).