linux-hardening.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] landlock: Drop "const" argument qualifier to avoid GCC 4.9 warnings
@ 2021-09-10 22:36 Kees Cook
  2021-09-13 11:19 ` Mickaël Salaün
  0 siblings, 1 reply; 3+ messages in thread
From: Kees Cook @ 2021-09-10 22:36 UTC (permalink / raw)
  To: Mickaël Salaün
  Cc: Kees Cook, James Morris, Serge E. Hallyn, linux-security-module,
	linux-kernel, linux-hardening

When building under GCC 4.9, the compiler warns about const mismatches:

security/landlock/ruleset.c: In function 'insert_rule':
security/landlock/ruleset.c:196:34: error: passing argument 2 of 'create_rule' from incompatible pointer type [-Werror]
   new_rule = create_rule(object, &this->layers, this->num_layers,
                                  ^
security/landlock/ruleset.c:69:30: note: expected 'const struct landlock_layer ** const' but argument is of type 'struct landlock_layer (*)[]'
 static struct landlock_rule *create_rule(
                              ^
security/landlock/ruleset.c: In function 'landlock_insert_rule':
security/landlock/ruleset.c:240:38: error: passing argument 3 of 'insert_rule' from incompatible pointer type [-Werror]
  return insert_rule(ruleset, object, &layers, ARRAY_SIZE(layers));
                                      ^
security/landlock/ruleset.c:144:12: note: expected 'const struct landlock_layer ** const' but argument is of type 'struct landlock_layer (*)[1]'
 static int insert_rule(struct landlock_ruleset *const ruleset,
            ^

Drop "const" from the function definition.

Cc: "Mickaël Salaün" <mic@digikod.net>
Cc: James Morris <jmorris@namei.org>
Cc: "Serge E. Hallyn" <serge@hallyn.com>
Cc: linux-security-module@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 security/landlock/ruleset.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/security/landlock/ruleset.c b/security/landlock/ruleset.c
index ec72b9262bf3..64c37af88ee7 100644
--- a/security/landlock/ruleset.c
+++ b/security/landlock/ruleset.c
@@ -68,7 +68,7 @@ static void build_check_rule(void)
 
 static struct landlock_rule *create_rule(
 		struct landlock_object *const object,
-		const struct landlock_layer (*const layers)[],
+		struct landlock_layer (*layers)[],
 		const u32 num_layers,
 		const struct landlock_layer *const new_layer)
 {
@@ -143,7 +143,7 @@ static void build_check_ruleset(void)
  */
 static int insert_rule(struct landlock_ruleset *const ruleset,
 		struct landlock_object *const object,
-		const struct landlock_layer (*const layers)[],
+		struct landlock_layer (*layers)[],
 		size_t num_layers)
 {
 	struct rb_node **walker_node;
-- 
2.30.2


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] landlock: Drop "const" argument qualifier to avoid GCC 4.9 warnings
  2021-09-10 22:36 [PATCH] landlock: Drop "const" argument qualifier to avoid GCC 4.9 warnings Kees Cook
@ 2021-09-13 11:19 ` Mickaël Salaün
  2021-09-13 16:16   ` Kees Cook
  0 siblings, 1 reply; 3+ messages in thread
From: Mickaël Salaün @ 2021-09-13 11:19 UTC (permalink / raw)
  To: Kees Cook
  Cc: James Morris, Serge E. Hallyn, linux-security-module,
	linux-kernel, linux-hardening


On 11/09/2021 00:36, Kees Cook wrote:
> When building under GCC 4.9, the compiler warns about const mismatches:
> 
> security/landlock/ruleset.c: In function 'insert_rule':
> security/landlock/ruleset.c:196:34: error: passing argument 2 of 'create_rule' from incompatible pointer type [-Werror]
>    new_rule = create_rule(object, &this->layers, this->num_layers,
>                                   ^
> security/landlock/ruleset.c:69:30: note: expected 'const struct landlock_layer ** const' but argument is of type 'struct landlock_layer (*)[]'
>  static struct landlock_rule *create_rule(
>                               ^
> security/landlock/ruleset.c: In function 'landlock_insert_rule':
> security/landlock/ruleset.c:240:38: error: passing argument 3 of 'insert_rule' from incompatible pointer type [-Werror]
>   return insert_rule(ruleset, object, &layers, ARRAY_SIZE(layers));
>                                       ^
> security/landlock/ruleset.c:144:12: note: expected 'const struct landlock_layer ** const' but argument is of type 'struct landlock_layer (*)[1]'
>  static int insert_rule(struct landlock_ruleset *const ruleset,

I guess this is a bug in GCC 4.9 (i.e. missing automatic const upgrade).
Couldn't we backport a fix to GCC 4.9 instead?

>             ^
> 
> Drop "const" from the function definition.
> 
> Cc: "Mickaël Salaün" <mic@digikod.net>
> Cc: James Morris <jmorris@namei.org>
> Cc: "Serge E. Hallyn" <serge@hallyn.com>
> Cc: linux-security-module@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
>  security/landlock/ruleset.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/security/landlock/ruleset.c b/security/landlock/ruleset.c
> index ec72b9262bf3..64c37af88ee7 100644
> --- a/security/landlock/ruleset.c
> +++ b/security/landlock/ruleset.c
> @@ -68,7 +68,7 @@ static void build_check_rule(void)
>  
>  static struct landlock_rule *create_rule(
>  		struct landlock_object *const object,
> -		const struct landlock_layer (*const layers)[],
> +		struct landlock_layer (*layers)[],

The "const layers" is not an issue, it should not be removed.

>  		const u32 num_layers,
>  		const struct landlock_layer *const new_layer)
>  {
> @@ -143,7 +143,7 @@ static void build_check_ruleset(void)
>   */
>  static int insert_rule(struct landlock_ruleset *const ruleset,
>  		struct landlock_object *const object,
> -		const struct landlock_layer (*const layers)[],
> +		struct landlock_layer (*layers)[],

Same here for the second const.

>  		size_t num_layers)
>  {
>  	struct rb_node **walker_node;
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] landlock: Drop "const" argument qualifier to avoid GCC 4.9 warnings
  2021-09-13 11:19 ` Mickaël Salaün
@ 2021-09-13 16:16   ` Kees Cook
  0 siblings, 0 replies; 3+ messages in thread
From: Kees Cook @ 2021-09-13 16:16 UTC (permalink / raw)
  To: Mickaël Salaün
  Cc: James Morris, Serge E. Hallyn, linux-security-module,
	linux-kernel, linux-hardening

On Mon, Sep 13, 2021 at 01:19:19PM +0200, Mickaël Salaün wrote:
> 
> On 11/09/2021 00:36, Kees Cook wrote:
> > When building under GCC 4.9, the compiler warns about const mismatches:
> > 
> > security/landlock/ruleset.c: In function 'insert_rule':
> > security/landlock/ruleset.c:196:34: error: passing argument 2 of 'create_rule' from incompatible pointer type [-Werror]
> >    new_rule = create_rule(object, &this->layers, this->num_layers,
> >                                   ^
> > security/landlock/ruleset.c:69:30: note: expected 'const struct landlock_layer ** const' but argument is of type 'struct landlock_layer (*)[]'
> >  static struct landlock_rule *create_rule(
> >                               ^
> > security/landlock/ruleset.c: In function 'landlock_insert_rule':
> > security/landlock/ruleset.c:240:38: error: passing argument 3 of 'insert_rule' from incompatible pointer type [-Werror]
> >   return insert_rule(ruleset, object, &layers, ARRAY_SIZE(layers));
> >                                       ^
> > security/landlock/ruleset.c:144:12: note: expected 'const struct landlock_layer ** const' but argument is of type 'struct landlock_layer (*)[1]'
> >  static int insert_rule(struct landlock_ruleset *const ruleset,
> 
> I guess this is a bug in GCC 4.9 (i.e. missing automatic const upgrade).
> Couldn't we backport a fix to GCC 4.9 instead?

I don't disagree, but I'm just trying to deal with the fall-out of
-Werror. Perhaps speak up on this thread in support of deprecating
GCC 4.9?

https://lore.kernel.org/lkml/20210910234047.1019925-1-ndesaulniers@google.com/

-Kees

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-09-13 16:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-10 22:36 [PATCH] landlock: Drop "const" argument qualifier to avoid GCC 4.9 warnings Kees Cook
2021-09-13 11:19 ` Mickaël Salaün
2021-09-13 16:16   ` Kees Cook

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).