Skip to content

Commit 1af0e4a

Browse files
cgzonespcmoore
authored andcommitted
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); ^ Signed-off-by: Christian Göttsche <cgzones@googlemail.com> Reviewed-by: Paul Moore <paul@paul-moore.com> Reviewed-by: Casey Schaufler <casey@schaufler-ca.com> Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent c29722f commit 1af0e4a

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

include/linux/lsm_hooks.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,7 +1595,7 @@ struct security_hook_list {
15951595
struct hlist_node list;
15961596
struct hlist_head *head;
15971597
union security_list_options hook;
1598-
char *lsm;
1598+
const char *lsm;
15991599
} __randomize_layout;
16001600

16011601
/*
@@ -1630,7 +1630,7 @@ extern struct security_hook_heads security_hook_heads;
16301630
extern char *lsm_names;
16311631

16321632
extern void security_add_hooks(struct security_hook_list *hooks, int count,
1633-
char *lsm);
1633+
const char *lsm);
16341634

16351635
#define LSM_FLAG_LEGACY_MAJOR BIT(0)
16361636
#define LSM_FLAG_EXCLUSIVE BIT(1)

security/security.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ static int lsm_append(const char *new, char **result)
478478
* Each LSM has to register its hooks with the infrastructure.
479479
*/
480480
void __init security_add_hooks(struct security_hook_list *hooks, int count,
481-
char *lsm)
481+
const char *lsm)
482482
{
483483
int i;
484484

0 commit comments

Comments
 (0)