From: Greg KH <gregkh@linuxfoundation.org>
To: kernel-hardening@lists.openwall.com
Cc: linux-kernel@vger.kernel.org
Subject: Re: [kernel-hardening] [PATCH 3/4] Make static usermode helper binaries constant
Date: Thu, 15 Dec 2016 13:18:07 -0800 [thread overview]
Message-ID: <20161215211807.GA13393@kroah.com> (raw)
In-Reply-To: <1481835061.3477.5.camel@gmail.com>
On Thu, Dec 15, 2016 at 03:51:01PM -0500, Daniel Micay wrote:
> > To follow up on this, and after staring at too many outputs of the
> > compiler, I think what this really should be is:
> > static char const critical_overtemp_path[] =
> > "/sbin/critical_overtemp";
> > right?
> >
> > That way both the variable, and the data, end up in read-only memory
> > from what I can tell.
> >
> > But, if I do:
> > static char const char critical_overtemp_path[] =
> > "/sbin/critical_overtemp";
> > then sparse complains to me about:
> > warning: duplicate const
> >
> > Is that just sparse being dense, or is the latter one really better
> > here? It seems that both of the above put the data and variable into
> > the same segment (.rodata).
> >
> > thanks,
> >
> > greg k-h
>
> Either 'char *const foo = "bar"' or 'const char *const foo = "bar" will
> also be a string constant in rodata with a pointer in rodata referring
> to them. Duplicate string constants get merged without any analysis as
> there's no guarantee of a unique address for the data itself since it's
> not a variable. 'const char foo[] = "bar"' goes into rodata too, but is
> the toolchain can't assume it can't safely merge strings + sizeof works
> but gcc/clang know how to optimize constant strlen anyway.
Thanks for the explanation. I don't think we need to worry about
merging these strings, but I'll keep it in mind.
However, the "folklore" of the kernel was to never do:
char *foo = "bar";
but instead do:
char foo[] = "bar";
to save on the extra variable that the former creates. Is that no
longer the case and we really should be using '*' to allow gcc to be
smarter about optimizations?
> The 'const' qualifier for pointers doesn't really do anything, it's when
> it's used on the variable (after the pointer) that it can do more than
> acting as a programming guide.
Many thanks for the explanations,
greg k-h
next prev parent reply other threads:[~2016-12-15 21:18 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-14 18:50 [kernel-hardening] [RFC 0/4] make call_usermodehelper a bit more "safe" Greg KH
2016-12-14 18:50 ` Greg KH
2016-12-14 18:50 ` [kernel-hardening] [PATCH 1/4] kmod: make usermodehelper path a const string Greg KH
2016-12-14 18:50 ` Greg KH
2016-12-14 18:50 ` [kernel-hardening] [PATCH 2/4] drbd: rename "usermode_helper" to "drbd_usermode_helper" Greg KH
2016-12-14 18:50 ` Greg KH
2016-12-14 18:50 ` [kernel-hardening] [PATCH 3/4] Make static usermode helper binaries constant Greg KH
2016-12-14 18:50 ` Greg KH
2016-12-14 19:11 ` [kernel-hardening] " Greg KH
2016-12-14 20:29 ` Rich Felker
2016-12-14 20:54 ` Greg KH
2016-12-15 17:54 ` Greg KH
2016-12-15 20:51 ` Daniel Micay
2016-12-15 21:18 ` Greg KH [this message]
2016-12-16 0:05 ` Daniel Micay
2016-12-16 0:14 ` Daniel Micay
2016-12-14 18:51 ` [kernel-hardening] [RFC 4/4] Introduce CONFIG_READONLY_USERMODEHELPER Greg KH
2016-12-14 18:51 ` Greg KH
2016-12-14 20:31 ` [kernel-hardening] " Kees Cook
2016-12-14 20:31 ` Kees Cook
2016-12-14 20:57 ` [kernel-hardening] " Greg KH
2016-12-14 20:57 ` Greg KH
2016-12-14 19:25 ` [kernel-hardening] [RFC 0/4] make call_usermodehelper a bit more "safe" Mark Rutland
2016-12-14 20:16 ` Kees Cook
2016-12-14 21:28 ` Jason A. Donenfeld
2016-12-14 23:16 ` Greg Kroah-Hartman
2016-12-16 1:02 ` [kernel-hardening] " NeilBrown
2016-12-16 1:02 ` NeilBrown
2016-12-16 12:49 ` [kernel-hardening] " Greg KH
2016-12-16 12:49 ` Greg KH
2016-12-19 13:34 ` [kernel-hardening] " Jiri Kosina
2016-12-19 13:34 ` Jiri Kosina
2016-12-20 9:27 ` [kernel-hardening] " Greg KH
2016-12-20 9:27 ` Greg KH
2016-12-20 10:27 ` [kernel-hardening] " Jiri Kosina
2016-12-20 10:27 ` Jiri Kosina
2016-12-20 10:31 ` [kernel-hardening] " Jiri Kosina
2016-12-20 10:31 ` Jiri Kosina
2016-12-20 10:48 ` [kernel-hardening] " Greg KH
2016-12-20 10:48 ` Greg KH
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=20161215211807.GA13393@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=kernel-hardening@lists.openwall.com \
--cc=linux-kernel@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.