From: Bruce Fields <bfields@fieldses.org>
To: David Windsor <dwindsor@gmail.com>
Cc: Hans Liljestrand <ishkamiel@gmail.com>,
linux-nfs@vger.kernel.org, netdev@vger.kernel.org,
kernel-hardening@lists.openwall.com,
Jeff Layton <jlayton@poochiereds.net>,
Kees Cook <keescook@chromium.org>,
"Reshetova, Elena" <elena.reshetova@intel.com>
Subject: Re: [kernel-hardening] Re: [RFC][PATCH] nfsd: add +1 to reference counting scheme for struct nfsd4_session
Date: Wed, 15 Feb 2017 11:45:05 -0500 [thread overview]
Message-ID: <20170215164505.GA14912@fieldses.org> (raw)
In-Reply-To: <CAEXv5_hP39k7HSLP-G_khx7MMQHnk=8Z5caa+U5n3bYvUTE1gQ@mail.gmail.com>
On Mon, Feb 13, 2017 at 06:46:19AM -0500, David Windsor wrote:
> On Mon, Feb 13, 2017 at 5:54 AM, Hans Liljestrand <ishkamiel@gmail.com> wrote:
> > On Sat, Feb 11, 2017 at 01:42:53AM -0500, David Windsor wrote:
> >>
> >> <snip>
> >>
> >>> Signed-off-by: David Windsor <dwindsor@gmail.com>
> >>> ---
> >>> fs/nfsd/nfs4state.c | 6 +++---
> >>> 1 file changed, 3 insertions(+), 3 deletions(-)
> >>>
> >>> diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
> >>> index a0dee8a..b0f3010 100644
> >>> --- a/fs/nfsd/nfs4state.c
> >>> +++ b/fs/nfsd/nfs4state.c
> >>> @@ -196,7 +196,7 @@ static void nfsd4_put_session_locked(struct
> >>> nfsd4_session *ses)
> >>>
> >>> lockdep_assert_held(&nn->client_lock);
> >>>
> >>> - if (atomic_dec_and_test(&ses->se_ref) && is_session_dead(ses))
> >>> + if (!atomic_add_unless(&ses->se_ref, -1, 1) &&
> >>> is_session_des(ses))
> >>
> >>
> >> This should read:
> >> if (!atomic_add_unless(&ses->se_ref, -1, 1) && is_session_dead(ses))
> >>
> >>> free_session(ses);
> >
> >
> > Hi,
> > I'm not sure if I have this correctly; But both before and after the patch
> > free_session gets called when se_ref count was 1, shouldn't this have
> > changed with the +1 scheme?
> >
> > Also, since the !atomic_add_unless doesn't actually decrement when at 1,
> > doesn't this leave the se_ref as 1 when it's destroyed? The function seems
> > to always be locked, so perhaps this doesn't matter, but still seems a bit
> > risky.
> >
>
> Yes; I forgot the additional call to atomic_dec_and_test() before
> free_session(). Thanks!
>
> I'll resubmit this after seeing how the rest of this discussion goes.
> We may end up abandoning this refcounting case.
I could live with it.
My knee jerk reaction is like Jeff's--it just seems more natural to me
for reference count 0 to mean "not in use, OK to free" in cases like
this--but maybe I just need to get used to the idea.
It'd be interesting to see what the final result looks like after
conversion to refcount_t.
--b.
prev parent reply other threads:[~2017-02-15 16:45 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-09 7:38 [RFC][PATCH] nfsd: add +1 to reference counting scheme for struct nfsd4_session David Windsor
2017-02-11 6:42 ` David Windsor
2017-02-11 12:31 ` Jeff Layton
2017-02-11 14:01 ` David Windsor
2017-02-11 14:09 ` Jeff Layton
2017-02-13 10:38 ` Christoph Hellwig
2017-02-13 11:42 ` David Windsor
2017-02-13 12:12 ` Christoph Hellwig
2017-02-14 13:48 ` David Windsor
2017-02-12 1:15 ` Bruce Fields
2017-02-12 1:42 ` David Windsor
2017-02-13 10:54 ` [kernel-hardening] " Hans Liljestrand
2017-02-13 11:46 ` David Windsor
2017-02-15 16:45 ` Bruce Fields [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=20170215164505.GA14912@fieldses.org \
--to=bfields@fieldses.org \
--cc=dwindsor@gmail.com \
--cc=elena.reshetova@intel.com \
--cc=ishkamiel@gmail.com \
--cc=jlayton@poochiereds.net \
--cc=keescook@chromium.org \
--cc=kernel-hardening@lists.openwall.com \
--cc=linux-nfs@vger.kernel.org \
--cc=netdev@vger.kernel.org \
/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).