Skip to contentSkip to conversation

security: declare member holding string literal const

PATCH In review Christian Göttsche 3 participants 7 messages Feb 17, 2022 – May 13, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 security: declare member holding string literal const

The struct security_hook_list member lsm is assigned in security_add_hooks() with string literals passed from the individual security modules. Declare the function parameter and the struct member const to signal their immutability.

Reported by Clang [-Wwrite-strings]:

    security/selinux/hooks.c:7388:63: error: passing 'const char [8]' to parameter of type 'char *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
            security_add_hooks(selinux_hooks, ARRAY_SIZE(selinux_hooks), selinux);
                                                                         ^~~~~~~~~
    ./include/linux/lsm_hooks.h:1629:11: note: passing argument to parameter 'lsm' here
                                    char *lsm);
                                          ^
---
 include/linux/lsm_hooks.h | 4 ++--
 security/security.c       | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
include/linux/lsm_hooks.h +2 -2
index 419b5febc3ca..47cdf3fbecef 100644
@@ -1595,7 +1595,7 @@ struct security_hook_list {
 	struct hlist_node		list;
 	struct hlist_head		*head;
 	union security_list_options	hook;
-	char				*lsm;
+	const char			*lsm;
 } __randomize_layout;
 
 /*
@@ -1630,7 +1630,7 @@ extern struct security_hook_heads security_hook_heads;
 extern char *lsm_names;
 
 extern void security_add_hooks(struct security_hook_list *hooks, int count,
-				char *lsm);
+				const char *lsm);
 
 #define LSM_FLAG_LEGACY_MAJOR	BIT(0)
 #define LSM_FLAG_EXCLUSIVE	BIT(1)
security/security.c +1 -1
index 9663ffcca4b0..a48eb3badfdd 100644
@@ -478,7 +478,7 @@ static int lsm_append(const char *new, char **result)
  * Each LSM has to register its hooks with the infrastructure.
  */
 void __init security_add_hooks(struct security_hook_list *hooks, int count,
-				char *lsm)
+				const char *lsm)
 {
 	int i;
 
Signature · 1 line
2.35.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 15 lines · Christian Göttsche

The struct security_hook_list member lsm is assigned in security_add_hooks() with string literals passed from the individual security modules. Declare the function parameter and the struct member const to signal their immutability.

Reported by Clang [-Wwrite-strings]:

    security/selinux/hooks.c:7388:63: error: passing 'const char [8]' to parameter of type 'char *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
            security_add_hooks(selinux_hooks, ARRAY_SIZE(selinux_hooks), selinux);
                                                                         ^~~~~~~~~
    ./include/linux/lsm_hooks.h:1629:11: note: passing argument to parameter 'lsm' here
                                    char *lsm);
                                          ^
Quoted 5 lines
---
 include/linux/lsm_hooks.h | 4 ++--
 security/security.c       | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

Thanks Christian.

Signature · 1 line
paul-moore.com
Reviewed-by on v1 1/1
#2 lore raw
In reply to Christian Göttsche
Quoted 7 lines · Christian Göttsche

The struct security_hook_list member lsm is assigned in security_add_hooks() with string literals passed from the individual security modules. Declare the function parameter and the struct member const to signal their immutability.

Reported by Clang [-Wwrite-strings]:

Quoted 8 lines
     security/selinux/hooks.c:7388:63: error: passing 'const char [8]' to parameter of type 'char *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
             security_add_hooks(selinux_hooks, ARRAY_SIZE(selinux_hooks), selinux);
                                                                          ^~~~~~~~~
     ./include/linux/lsm_hooks.h:1629:11: note: passing argument to parameter 'lsm' here
                                     char *lsm);
                                           ^
Quoted 40 lines
---
  include/linux/lsm_hooks.h | 4 ++--
  security/security.c       | 2 +-
  2 files changed, 3 insertions(+), 3 deletions(-)
include/linux/lsm_hooks.h +2 -2
index 419b5febc3ca..47cdf3fbecef 100644
@@ -1595,7 +1595,7 @@ struct security_hook_list {
  	struct hlist_node		list;
  	struct hlist_head		*head;
  	union security_list_options	hook;
-	char				*lsm;
+	const char			*lsm;
  } __randomize_layout;
 
  /*
@@ -1630,7 +1630,7 @@ extern struct security_hook_heads security_hook_heads;
  extern char *lsm_names;
 
  extern void security_add_hooks(struct security_hook_list *hooks, int count,
-				char *lsm);
+				const char *lsm);
 
  #define LSM_FLAG_LEGACY_MAJOR	BIT(0)
  #define LSM_FLAG_EXCLUSIVE	BIT(1)
security/security.c +1 -1
index 9663ffcca4b0..a48eb3badfdd 100644
@@ -478,7 +478,7 @@ static int lsm_append(const char *new, char **result)
   * Each LSM has to register its hooks with the infrastructure.
   */
  void __init security_add_hooks(struct security_hook_list *hooks, int count,
-				char *lsm)
+				const char *lsm)
  {
  	int i;
 
#3 lore raw
Quoted 16 lines · Casey Schaufler
Quoted 14 lines · Christian Göttsche

The struct security_hook_list member lsm is assigned in security_add_hooks() with string literals passed from the individual security modules. Declare the function parameter and the struct member const to signal their immutability.

Reported by Clang [-Wwrite-strings]:

     security/selinux/hooks.c:7388:63: error: passing 'const char [8]' to parameter of type 'char *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
             security_add_hooks(selinux_hooks, ARRAY_SIZE(selinux_hooks), selinux);
                                                                          ^~~~~~~~~
     ./include/linux/lsm_hooks.h:1629:11: note: passing argument to parameter 'lsm' here
                                     char *lsm);
                                           ^
Quoted 4 lines
Quoted 1 line

Kindly ping;
any progress on this one?

Quoted 40 lines
Quoted 40 lines
---
  include/linux/lsm_hooks.h | 4 ++--
  security/security.c       | 2 +-
  2 files changed, 3 insertions(+), 3 deletions(-)
include/linux/lsm_hooks.h +2 -2
index 419b5febc3ca..47cdf3fbecef 100644
@@ -1595,7 +1595,7 @@ struct security_hook_list {
      struct hlist_node               list;
      struct hlist_head               *head;
      union security_list_options     hook;
-     char                            *lsm;
+     const char                      *lsm;
  } __randomize_layout;
 
  /*
@@ -1630,7 +1630,7 @@ extern struct security_hook_heads security_hook_heads;
  extern char *lsm_names;
 
  extern void security_add_hooks(struct security_hook_list *hooks, int count,
-                             char *lsm);
+                             const char *lsm);
 
  #define LSM_FLAG_LEGACY_MAJOR       BIT(0)
  #define LSM_FLAG_EXCLUSIVE  BIT(1)
security/security.c +1 -1
index 9663ffcca4b0..a48eb3badfdd 100644
@@ -478,7 +478,7 @@ static int lsm_append(const char *new, char **result)
   * Each LSM has to register its hooks with the infrastructure.
   */
  void __init security_add_hooks(struct security_hook_list *hooks, int count,
-                             char *lsm)
+                             const char *lsm)
  {
      int i;
 
maintainer
#4 lore raw
Quoted 16 lines · Christian Göttsche
Quoted 15 lines · Casey Schaufler
Quoted 14 lines · Christian Göttsche

The struct security_hook_list member lsm is assigned in security_add_hooks() with string literals passed from the individual security modules. Declare the function parameter and the struct member const to signal their immutability.

Reported by Clang [-Wwrite-strings]:

     security/selinux/hooks.c:7388:63: error: passing 'const char [8]' to parameter of type 'char *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
             security_add_hooks(selinux_hooks, ARRAY_SIZE(selinux_hooks), selinux);
                                                                          ^~~~~~~~~
     ./include/linux/lsm_hooks.h:1629:11: note: passing argument to parameter 'lsm' here
                                     char *lsm);
                                           ^
Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Kindly ping;
any progress on this one?

I've already added my Reviewed-by tag, as has Casey, so I think it's pretty "safe" at this point. The next step is for James to pull this into the LSM tree. If it is still collecting dust at the end of this week, ping us again and I can just go ahead and pull it into the SELinux tree, it's small enough that it shouldn't cause any problems.

Signature · 1 line
paul-moore.com
#5 lore raw
Quoted 24 lines · Paul Moore
Quoted 21 lines · Christian Göttsche
Quoted 19 lines · Casey Schaufler
Quoted 7 lines · Christian Göttsche

The struct security_hook_list member lsm is assigned in security_add_hooks() with string literals passed from the individual security modules. Declare the function parameter and the struct member const to signal their immutability.

Reported by Clang [-Wwrite-strings]:

Quoted 8 lines
     security/selinux/hooks.c:7388:63: error: passing 'const char [8]' to parameter of type 'char *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
             security_add_hooks(selinux_hooks, ARRAY_SIZE(selinux_hooks), selinux);
                                                                          ^~~~~~~~~
     ./include/linux/lsm_hooks.h:1629:11: note: passing argument to parameter 'lsm' here
                                     char *lsm);
                                           ^
Quoted 8 lines
Quoted 2 lines

Kindly ping;
any progress on this one?

I've already added my Reviewed-by tag, as has Casey, so I think it's pretty "safe" at this point. The next step is for James to pull this into the LSM tree. If it is still collecting dust at the end of this week, ping us again and I can just go ahead and pull it into the SELinux tree, it's small enough that it shouldn't cause any problems.

end-of-the-week-ping

Quoted 3 lines

--
paul-moore.com

maintainer
#6 lore raw
Quoted 27 lines · Christian Göttsche
Quoted 26 lines · Paul Moore
Quoted 23 lines · Christian Göttsche
Quoted 15 lines · Casey Schaufler
Quoted 14 lines · Christian Göttsche

The struct security_hook_list member lsm is assigned in security_add_hooks() with string literals passed from the individual security modules. Declare the function parameter and the struct member const to signal their immutability.

Reported by Clang [-Wwrite-strings]:

     security/selinux/hooks.c:7388:63: error: passing 'const char [8]' to parameter of type 'char *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
             security_add_hooks(selinux_hooks, ARRAY_SIZE(selinux_hooks), selinux);
                                                                          ^~~~~~~~~
     ./include/linux/lsm_hooks.h:1629:11: note: passing argument to parameter 'lsm' here
                                     char *lsm);
                                           ^
Quoted 4 lines
Quoted 1 line

Kindly ping;
any progress on this one?

Quoted 7 lines
Quoted 5 lines

I've already added my Reviewed-by tag, as has Casey, so I think it's pretty "safe" at this point. The next step is for James to pull this into the LSM tree. If it is still collecting dust at the end of this week, ping us again and I can just go ahead and pull it into the SELinux tree, it's small enough that it shouldn't cause any problems.

end-of-the-week-ping

Thanks for the reminder. I haven't seen any other action on this so I've gone ahead and merged this into selinux/next; thanks for your patience and persistence on this Christian!

Signature · 1 line
paul-moore.com