Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 508dc6e1 authored by Benny Halevy's avatar Benny Halevy Committed by J. Bruce Fields
Browse files

nfsd41: free_session/free_client must be called under the client_lock



The session client is manipulated under the client_lock hence
both free_session and nfsd4_del_conns must be called under this lock.

This patch adds a BUG_ON that checks this condition in the
respective functions and implements the missing locks.

nfsd4_{get,put}_session helpers were moved to the C file that uses them
so to prevent use from external files and an unlocked version of
nfsd4_put_session is provided for external use from nfs4xdr.c

Signed-off-by: default avatarBenny Halevy <bhalevy@tonian.com>
Signed-off-by: default avatarJ. Bruce Fields <bfields@redhat.com>
parent e27f49c3
Loading
Loading
Loading
Loading
+31 −4
Original line number Original line Diff line number Diff line
@@ -95,6 +95,19 @@ nfs4_lock_state(void)
	mutex_lock(&client_mutex);
	mutex_lock(&client_mutex);
}
}


static void free_session(struct kref *);

/* Must be called under the client_lock */
static void nfsd4_put_session_locked(struct nfsd4_session *ses)
{
	kref_put(&ses->se_ref, free_session);
}

static void nfsd4_get_session(struct nfsd4_session *ses)
{
	kref_get(&ses->se_ref);
}

void
void
nfs4_unlock_state(void)
nfs4_unlock_state(void)
{
{
@@ -836,11 +849,12 @@ static void nfsd4_del_conns(struct nfsd4_session *s)
	spin_unlock(&clp->cl_lock);
	spin_unlock(&clp->cl_lock);
}
}


void free_session(struct kref *kref)
static void free_session(struct kref *kref)
{
{
	struct nfsd4_session *ses;
	struct nfsd4_session *ses;
	int mem;
	int mem;


	BUG_ON(!spin_is_locked(&client_lock));
	ses = container_of(kref, struct nfsd4_session, se_ref);
	ses = container_of(kref, struct nfsd4_session, se_ref);
	nfsd4_del_conns(ses);
	nfsd4_del_conns(ses);
	spin_lock(&nfsd_drc_lock);
	spin_lock(&nfsd_drc_lock);
@@ -851,6 +865,13 @@ void free_session(struct kref *kref)
	kfree(ses);
	kfree(ses);
}
}


void nfsd4_put_session(struct nfsd4_session *ses)
{
	spin_lock(&client_lock);
	nfsd4_put_session_locked(ses);
	spin_unlock(&client_lock);
}

static struct nfsd4_session *alloc_init_session(struct svc_rqst *rqstp, struct nfs4_client *clp, struct nfsd4_create_session *cses)
static struct nfsd4_session *alloc_init_session(struct svc_rqst *rqstp, struct nfs4_client *clp, struct nfsd4_create_session *cses)
{
{
	struct nfsd4_session *new;
	struct nfsd4_session *new;
@@ -898,7 +919,9 @@ static struct nfsd4_session *alloc_init_session(struct svc_rqst *rqstp, struct n
	status = nfsd4_new_conn_from_crses(rqstp, new);
	status = nfsd4_new_conn_from_crses(rqstp, new);
	/* whoops: benny points out, status is ignored! (err, or bogus) */
	/* whoops: benny points out, status is ignored! (err, or bogus) */
	if (status) {
	if (status) {
		spin_lock(&client_lock);
		free_session(&new->se_ref);
		free_session(&new->se_ref);
		spin_unlock(&client_lock);
		return NULL;
		return NULL;
	}
	}
	if (cses->flags & SESSION4_BACK_CHAN) {
	if (cses->flags & SESSION4_BACK_CHAN) {
@@ -1010,12 +1033,13 @@ static struct nfs4_client *alloc_client(struct xdr_netobj name)
static inline void
static inline void
free_client(struct nfs4_client *clp)
free_client(struct nfs4_client *clp)
{
{
	BUG_ON(!spin_is_locked(&client_lock));
	while (!list_empty(&clp->cl_sessions)) {
	while (!list_empty(&clp->cl_sessions)) {
		struct nfsd4_session *ses;
		struct nfsd4_session *ses;
		ses = list_entry(clp->cl_sessions.next, struct nfsd4_session,
		ses = list_entry(clp->cl_sessions.next, struct nfsd4_session,
				se_perclnt);
				se_perclnt);
		list_del(&ses->se_perclnt);
		list_del(&ses->se_perclnt);
		nfsd4_put_session(ses);
		nfsd4_put_session_locked(ses);
	}
	}
	if (clp->cl_cred.cr_group_info)
	if (clp->cl_cred.cr_group_info)
		put_group_info(clp->cl_cred.cr_group_info);
		put_group_info(clp->cl_cred.cr_group_info);
@@ -1184,7 +1208,9 @@ static struct nfs4_client *create_client(struct xdr_netobj name, char *recdir,
	if (princ) {
	if (princ) {
		clp->cl_principal = kstrdup(princ, GFP_KERNEL);
		clp->cl_principal = kstrdup(princ, GFP_KERNEL);
		if (clp->cl_principal == NULL) {
		if (clp->cl_principal == NULL) {
			spin_lock(&client_lock);
			free_client(clp);
			free_client(clp);
			spin_unlock(&client_lock);
			return NULL;
			return NULL;
		}
		}
	}
	}
@@ -1812,9 +1838,10 @@ nfsd4_destroy_session(struct svc_rqst *r,
	nfsd4_probe_callback_sync(ses->se_client);
	nfsd4_probe_callback_sync(ses->se_client);
	nfs4_unlock_state();
	nfs4_unlock_state();


	spin_lock(&client_lock);
	nfsd4_del_conns(ses);
	nfsd4_del_conns(ses);

	nfsd4_put_session_locked(ses);
	nfsd4_put_session(ses);
	spin_unlock(&client_lock);
	status = nfs_ok;
	status = nfs_ok;
out:
out:
	dprintk("%s returns %d\n", __func__, ntohl(status));
	dprintk("%s returns %d\n", __func__, ntohl(status));
+1 −12
Original line number Original line Diff line number Diff line
@@ -198,18 +198,7 @@ struct nfsd4_session {
	struct nfsd4_slot	*se_slots[];	/* forward channel slots */
	struct nfsd4_slot	*se_slots[];	/* forward channel slots */
};
};


static inline void
extern void nfsd4_put_session(struct nfsd4_session *ses);
nfsd4_put_session(struct nfsd4_session *ses)
{
	extern void free_session(struct kref *kref);
	kref_put(&ses->se_ref, free_session);
}

static inline void
nfsd4_get_session(struct nfsd4_session *ses)
{
	kref_get(&ses->se_ref);
}


/* formatted contents of nfs4_sessionid */
/* formatted contents of nfs4_sessionid */
struct nfsd4_sessionid {
struct nfsd4_sessionid {