perfbook.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Elad Lahav <e2lahav@gmail.com>
To: perfbook@vger.kernel.org
Subject: Hazard pointers: suspicious dereference
Date: Sun, 13 Nov 2022 10:20:18 -0500	[thread overview]
Message-ID: <CAJbg=FWTVdoZr2uzDeSMcUE-0EGQbFgtVR6NvoRQ9Y+P1LSoRQ@mail.gmail.com> (raw)

hp_try_record() takes a pointer to a pointer, casts it to void **, and
then passes it to _h_t_r_impl(). So far so good.

hp_record() takes a pointer to a pointer, but dereferences it when
calling hp_try_record(). That seems odd to me. Let's say we have a
structure foo_t, and a pointer to it, foo_p. Then

hp_record((void **)&foo_p, hp)  =>
hp_try_record(*p, hp) // p is pointer to pointer to foo_s =>
_h_t_r_impl((void **)p, hp) // p is a pointer to foo_s, cast as (void **) =>
tmp = READ_ONCE(*p) // reading from the first bytes of foo_s as an address

I also tried building the example route_hazard.c such that it uses
hp_record() instead of hp_try_record(), and it crashes as I expected.

Am I missing something?

--Elad

             reply	other threads:[~2022-11-13 15:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-13 15:20 Elad Lahav [this message]
2022-11-20 18:23 ` Hazard pointers: suspicious dereference Elad Lahav
2022-11-20 23:40   ` Paul McKenney

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='CAJbg=FWTVdoZr2uzDeSMcUE-0EGQbFgtVR6NvoRQ9Y+P1LSoRQ@mail.gmail.com' \
    --to=e2lahav@gmail.com \
    --cc=perfbook@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 read-only IMAP folder(s) and NNTP newsgroup(s).