mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jeff Layton <jlayton@redhat.com>
To: akpm@linux-foundation.org, neilb@suse.de
Cc: linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 5/5] NLM: have nlm_shutdown_hosts kill off all NLM RPC tasks
Date: Thu, 10 Jan 2008 13:01:36 -0500	[thread overview]
Message-ID: <1199988096-19700-6-git-send-email-jlayton@redhat.com> (raw)
In-Reply-To: <1199988096-19700-5-git-send-email-jlayton@redhat.com>

The main problem is this:

When a lock that a client is blocking on comes free, lockd does this in
nlmsvc_grant_blocked():

    nlm_async_call(block->b_call, NLMPROC_GRANTED_MSG, &nlmsvc_grant_ops);

the callback from this call is nlmsvc_grant_callback(). That function
does this at the end to wake up lockd:

    svc_wake_up(block->b_daemon);

However there is no guarantee that lockd will be up when this happens.
If someone shuts down or restarts lockd before the async call completes,
then the b_daemon pointer will point to freed memory and the kernel may
oops.

If we're shutting down all the nlm_hosts anyway, then it doesn't make
sense to allow RPC calls to linger. Allowing them to do so can mean
that the RPC calls can outlive the currently running lockd and can lead
to the above use after free situation and possibly others.

Signed-off-by: Jeff Layton <jlayton@redhat.com>
---
 fs/lockd/host.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/fs/lockd/host.c b/fs/lockd/host.c
index 572601e..8771484 100644
--- a/fs/lockd/host.c
+++ b/fs/lockd/host.c
@@ -377,8 +377,10 @@ nlm_shutdown_hosts(void)
 	/* First, make all hosts eligible for gc */
 	dprintk("lockd: nuking all hosts...\n");
 	for (chain = nlm_hosts; chain < nlm_hosts + NLM_HOST_NRHASH; ++chain) {
-		hlist_for_each_entry(host, pos, chain, h_hash)
+		hlist_for_each_entry(host, pos, chain, h_hash) {
 			host->h_expires = jiffies - 1;
+			rpc_killall_tasks(host->h_rpcclnt);
+		}
 	}
 
 	/* Then, perform a garbage collection pass */
-- 
1.5.3.7


  reply	other threads:[~2008-01-10 18:02 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-10 18:01 [PATCH 0/5] Intro: convert lockd to kthread and fix use-after-free (try #7) Jeff Layton
2008-01-10 18:01 ` [PATCH 1/5] SUNRPC: spin svc_rqst initialization to its own function Jeff Layton
2008-01-10 18:01   ` [PATCH 2/5] SUNRPC: export svc_sock_update_bufs Jeff Layton
2008-01-10 18:01     ` [PATCH 3/5] NLM: Have lockd call try_to_freeze Jeff Layton
2008-01-10 18:01       ` [PATCH 4/5] NLM: Convert lockd to use kthreads Jeff Layton
2008-01-10 18:01         ` Jeff Layton [this message]
2008-01-13 11:54       ` [PATCH 3/5] NLM: Have lockd call try_to_freeze Jeff Layton
2008-01-13 22:24         ` Neil Brown
2008-01-13 23:59           ` Rafael J. Wysocki
2008-01-11  1:37 ` [PATCH 0/5] Intro: convert lockd to kthread and fix use-after-free (try #7) Neil Brown

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=1199988096-19700-6-git-send-email-jlayton@redhat.com \
    --to=jlayton@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=neilb@suse.de \
    /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

all inboxes | Powered by JetHome®