All of lore.kernel.org
 help / color / mirror / Atom feed
From: Steven Whitehouse <steve@chygwyn.com>
To: Satyam Sharma <ssatyam@cse.iitk.ac.in>
Cc: linux-kernel@vger.kernel.org, teigland@redhat.com,
	linux-cluster@redhat.com, joel.becker@oracle.com
Subject: Re: [PATCH] DLM: fix a couple of races
Date: Tue, 08 May 2007 09:00:58 +0100	[thread overview]
Message-ID: <1178611258.7476.5.camel@quoit> (raw)
In-Reply-To: <Pine.LNX.4.64.0705042119510.16239@cselinux1.cse.iitk.ac.in>

Hi,

Added to the GFS2 -nmw git tree, thanks. Please remember to add a
Signed-off-by line for future patches - I've added it for you this time,

Steve.

On Fri, 2007-05-04 at 21:49 +0530, Satyam Sharma wrote:
> Hi,
> 
> There are the following two trivially-fixed races in fs/dlm/config.c:
> 
> 1. The configfs subsystem semaphore must be held by the caller when 
> calling config_group_find_obj(). It's needed to walk the subsystem 
> hierarchy without racing with a simultaneous mkdir(2) or rmdir(2). I 
> looked around to see if there was some other way we were avoiding this 
> race, but couldn't find any.
> 
> 2. get_comm() does hold the subsystem semaphore but lets go too soon -- 
> before grabbing a reference on the found config_item. A concurrent 
> rmdir(2) could come and release the comm after the up() but before the 
> config_item_get().
> 
> Patch that fixes both these bugs below.
> 
> Cheers,
> S
> 
> PS: For some reason, configfs still uses a struct semaphore (as a binary 
> semaphore) for configfs_subsystem.su_sem. Someone with free time should 
> convert that to a struct mutex, say configfs_subsystem.su_mtx -- which is 
> the preferred way to use (binary) mutexes presently. CC'ing Joel Becker on 
> this.
> 
> ---
> 
> Fix two races in fs/dlm/config.c:
> 
> (1) Grab the configfs subsystem semaphore before calling 
> config_group_find_obj() in get_space(). This solves a potential race 
> between get_space() and concurrent mkdir(2) or rmdir(2).
> 
> (2) Grab a reference on the found config_item _while_ holding the configfs 
> subsystem semaphore in get_comm(), and not after it. This solves a 
> potential race between get_comm() and concurrent rmdir(2).
> 
>   fs/dlm/config.c |   15 +++++++++++----
>   1 file changed, 11 insertions(+), 4 deletions(-)
> 
>  	Signed-off-by: Satyam Sharma <ssatyam@cse.iitk.ac.in>
> 
> ---
> 
> diff -ruNp linux-2.6.21.1/fs/dlm/config.c linux-2.6.21.1~patch/fs/dlm/config.c
> --- linux-2.6.21.1/fs/dlm/config.c	2007-04-26 08:38:32.000000000 +0530
> +++ linux-2.6.21.1~patch/fs/dlm/config.c	2007-05-04 21:08:54.000000000 +0530
> @@ -744,9 +744,16 @@ static ssize_t node_weight_write(struct
> 
>   static struct space *get_space(char *name)
>   {
> +	struct config_item *i;
> +
>   	if (!space_list)
>   		return NULL;
> -	return to_space(config_group_find_obj(space_list, name));
> +
> +	down(&space_list->cg_subsys->su_sem);
> +	i = config_group_find_obj(space_list, name);
> +	up(&space_list->cg_subsys->su_sem);
> +
> +	return to_space(i);
>   }
> 
>   static void put_space(struct space *sp)
> @@ -772,20 +779,20 @@ static struct comm *get_comm(int nodeid,
>   			if (cm->nodeid != nodeid)
>   				continue;
>   			found = 1;
> +			config_item_get(i);
>   			break;
>   		} else {
>   			if (!cm->addr_count ||
>   			    memcmp(cm->addr[0], addr, sizeof(*addr)))
>   				continue;
>   			found = 1;
> +			config_item_get(i);
>   			break;
>   		}
>   	}
>   	up(&clusters_root.subsys.su_sem);
> 
> -	if (found)
> -		config_item_get(i);
> -	else
> +	if (!found)
>   		cm = NULL;
>   	return cm;
>   }
> 
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/


  parent reply	other threads:[~2007-05-08  8:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-04 16:19 [PATCH] DLM: fix a couple of races Satyam Sharma
2007-05-04 18:17 ` David Teigland
2007-05-08  8:00 ` Steven Whitehouse [this message]
2007-05-08  8:10   ` Steven Whitehouse
  -- strict thread matches above, loose matches on Subject: below --
2007-07-09 16:02 [Cluster-devel] [GFS2/DLM] Pre-pull Patch Posting swhiteho
2007-07-09 16:02 ` [Cluster-devel] [PATCH] [GFS2] flush the glock completely in inode_go_sync swhiteho
2007-07-09 16:02   ` [PATCH] [DLM] fix a couple of races swhiteho

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=1178611258.7476.5.camel@quoit \
    --to=steve@chygwyn.com \
    --cc=joel.becker@oracle.com \
    --cc=linux-cluster@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ssatyam@cse.iitk.ac.in \
    --cc=teigland@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.