From: "Paul E. McKenney" <paulmck@linux.ibm.com>
To: Joel Fernandes <joel@joelfernandes.org>
Cc: Steven Rostedt <rostedt@goodmis.org>,
linux-kernel@vger.kernel.org, keescook@chromium.org,
mathieu.desnoyers@efficios.com, Jessica Yu <jeyu@kernel.org>,
kernel-hardening@lists.openwall.com, kernel-team@android.com,
rcu@vger.kernel.org
Subject: Re: [PATCH v3 3/3] module: Make __tracepoints_ptrs as read-only
Date: Thu, 11 Apr 2019 06:44:28 -0700 [thread overview]
Message-ID: <20190411134428.GY14111@linux.ibm.com> (raw)
In-Reply-To: <20190411082106.GB167446@google.com>
On Thu, Apr 11, 2019 at 04:21:06AM -0400, Joel Fernandes wrote:
> On Wed, Apr 10, 2019 at 08:44:01PM -0400, Steven Rostedt wrote:
> > On Wed, 10 Apr 2019 16:29:02 -0400
> > Joel Fernandes <joel@joelfernandes.org> wrote:
> >
> > > The srcu structure pointer array is modified at module load time because the
> > > array is fixed up by the module loader at load-time with the final locations
> > > of the tracepoints right? Basically relocation fixups. At compile time, I
> > > believe it is not know what the values in the ptr array are. I believe same
> > > is true for the tracepoint ptrs array.
> > >
> > > Also it needs to be in a separate __tracepoint_ptrs so that this code works:
> > >
> > >
> > > #ifdef CONFIG_TRACEPOINTS
> > > mod->tracepoints_ptrs = section_objs(info, "__tracepoints_ptrs",
> > > sizeof(*mod->tracepoints_ptrs),
> > > &mod->num_tracepoints);
> > > #endif
> > >
> > > Did I miss some point? Thanks,
> >
> > But there's a lot of others too. Hmm, does this mean that the RO data
> > sections that are in modules are not set to RO?
> >
> > There's a bunch of separate sections that are RO. Just look in
> > include/asm-generic/vmlinux.lds.h under the RO_DATA_SECTION() macro.
> >
> > A lot of the sections saved in module.c:find_module_sections() are in
> > that RO_DATA when compiled as a builtin. Are they not RO when loaded via
> > a module?
> >
> > If this is the case, there probably is going to be a lot more sections
> > added to your list.
>
> Hi Steven,
>
> You are right. It turns out that this patch for tracepoint is not needed
> since each tracepoint pointer is marked as a const which automatically makes
> the section non-writable after relocations..
>
> #ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
> typedef const int tracepoint_ptr_t;
> #else
> typedef struct tracepoint * const tracepoint_ptr_t;
> #endif
>
> So the fix for SRCU could just be the following. I verified with the change
> that the ELF section section is marked only with the ALLOCATE flag, not the
> WRITE flag which should automatically put the srcu pointer array in rodata.
> I'll test this out tomorrow.
>
> Patch 2/3 and 3/3 would not be nececessary if this works out. 1/3 may be a
> nice clean up but is not something urgent and we could do that in the future
> if needed.
>
> Any thoughts? Thanks a lot for the review!
>
> (I believe it is still worth auditing other sections in built-in RODATA and
> making sure they are non-writable for modules as well).
Nice and simple change! ;-)
If it works and Steve is OK with it, I will be happy to take the
corresponding formal patch.
Thanx, Paul
> ---8<-----------------------
>
> diff --git a/include/linux/srcutree.h b/include/linux/srcutree.h
> index 8af1824c46a8..9cfcc8a756ae 100644
> --- a/include/linux/srcutree.h
> +++ b/include/linux/srcutree.h
> @@ -123,7 +123,7 @@ struct srcu_struct {
> #ifdef MODULE
> # define __DEFINE_SRCU(name, is_static) \
> is_static struct srcu_struct name; \
> - struct srcu_struct *__srcu_struct_##name \
> + struct srcu_struct * const __srcu_struct_##name \
> __section("___srcu_struct_ptrs") = &name
> #else
> # define __DEFINE_SRCU(name, is_static) \
>
next prev parent reply other threads:[~2019-04-11 13:44 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-10 19:57 [PATCH v3 1/3] module: Prepare for addition of new ro_after_init sections Joel Fernandes (Google)
2019-04-10 19:57 ` [PATCH v3 2/3] module: Make srcu_struct ptr array as read-only post init Joel Fernandes (Google)
2019-04-10 19:57 ` [PATCH v3 3/3] module: Make __tracepoints_ptrs as read-only Joel Fernandes (Google)
2019-04-10 20:11 ` Steven Rostedt
2019-04-10 20:29 ` Joel Fernandes
2019-04-11 0:44 ` Steven Rostedt
2019-04-11 8:21 ` Joel Fernandes
2019-04-11 13:19 ` Steven Rostedt
2019-04-11 20:06 ` Joel Fernandes
2019-04-11 13:44 ` Paul E. McKenney [this message]
2019-04-17 15:16 ` Jessica Yu
2019-04-17 15:36 ` Paul E. McKenney
2019-04-20 11:38 ` Joel Fernandes
2019-04-11 8:32 ` [PATCH v3 1/3] module: Prepare for addition of new ro_after_init sections Miroslav Benes
2019-04-17 13:29 ` Jessica Yu
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=20190411134428.GY14111@linux.ibm.com \
--to=paulmck@linux.ibm.com \
--cc=jeyu@kernel.org \
--cc=joel@joelfernandes.org \
--cc=keescook@chromium.org \
--cc=kernel-hardening@lists.openwall.com \
--cc=kernel-team@android.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=rcu@vger.kernel.org \
--cc=rostedt@goodmis.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).