[PATCH] LSM: Avoid warnings about potentially unused hook variables

Subsystems: security subsystem, the rest

STALE1755d

4 messages, 3 authors, 2021-10-14 · open the first message on its own page

[PATCH] LSM: Avoid warnings about potentially unused hook variables

From: Kees Cook <hidden>
Date: 2021-10-13 17:31:19

Building with W=1 shows many unused const variable warnings. These can
be silenced, as we're well aware of their being potentially unused:

./include/linux/lsm_hook_defs.h:36:18: error: 'ptrace_access_check_default' defined but not used [-Werror=unused-const-variable=]
   36 | LSM_HOOK(int, 0, ptrace_access_check, struct task_struct *child,
      |                  ^~~~~~~~~~~~~~~~~~~
security/security.c:706:32: note: in definition of macro 'LSM_RET_DEFAULT'
  706 | #define LSM_RET_DEFAULT(NAME) (NAME##_default)
      |                                ^~~~
security/security.c:711:9: note: in expansion of macro 'DECLARE_LSM_RET_DEFAULT_int'
  711 |         DECLARE_LSM_RET_DEFAULT_##RET(DEFAULT, NAME)
      |         ^~~~~~~~~~~~~~~~~~~~~~~~
./include/linux/lsm_hook_defs.h:36:1: note: in expansion of macro 'LSM_HOOK'
   36 | LSM_HOOK(int, 0, ptrace_access_check, struct task_struct *child,
      | ^~~~~~~~

Cc: James Morris <jmorris@namei.org>
Cc: "Serge E. Hallyn" <serge@hallyn.com>
Cc: Paul Moore <paul@paul-moore.com>
Cc: Casey Schaufler <casey@schaufler-ca.com>
Cc: KP Singh <redacted>
Cc: linux-security-module@vger.kernel.org
Reported-by: kernel test robot <redacted>
Link: https://lore.kernel.org/linux-mm/202110131608.zms53FPR-lkp@intel.com/
Fixes: 98e828a0650f ("security: Refactor declaration of LSM hooks")
Signed-off-by: Kees Cook <redacted>
---
 security/security.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/security/security.c b/security/security.c
index 9ffa9e9c5c55..462f14354c2c 100644
--- a/security/security.c
+++ b/security/security.c
@@ -706,7 +706,7 @@ static int lsm_superblock_alloc(struct super_block *sb)
 #define LSM_RET_DEFAULT(NAME) (NAME##_default)
 #define DECLARE_LSM_RET_DEFAULT_void(DEFAULT, NAME)
 #define DECLARE_LSM_RET_DEFAULT_int(DEFAULT, NAME) \
-	static const int LSM_RET_DEFAULT(NAME) = (DEFAULT);
+	static const int __maybe_unused LSM_RET_DEFAULT(NAME) = (DEFAULT);
 #define LSM_HOOK(RET, DEFAULT, NAME, ...) \
 	DECLARE_LSM_RET_DEFAULT_##RET(DEFAULT, NAME)
 
-- 
2.30.2

Re: [PATCH] LSM: Avoid warnings about potentially unused hook variables

From: Paul Moore <paul@paul-moore.com>
Date: 2021-10-13 17:53:43

On Wed, Oct 13, 2021 at 1:31 PM Kees Cook [off-list ref] wrote:
Building with W=1 shows many unused const variable warnings. These can
be silenced, as we're well aware of their being potentially unused:

./include/linux/lsm_hook_defs.h:36:18: error: 'ptrace_access_check_default' defined but not used [-Werror=unused-const-variable=]
   36 | LSM_HOOK(int, 0, ptrace_access_check, struct task_struct *child,
      |                  ^~~~~~~~~~~~~~~~~~~
security/security.c:706:32: note: in definition of macro 'LSM_RET_DEFAULT'
  706 | #define LSM_RET_DEFAULT(NAME) (NAME##_default)
      |                                ^~~~
security/security.c:711:9: note: in expansion of macro 'DECLARE_LSM_RET_DEFAULT_int'
  711 |         DECLARE_LSM_RET_DEFAULT_##RET(DEFAULT, NAME)
      |         ^~~~~~~~~~~~~~~~~~~~~~~~
./include/linux/lsm_hook_defs.h:36:1: note: in expansion of macro 'LSM_HOOK'
   36 | LSM_HOOK(int, 0, ptrace_access_check, struct task_struct *child,
      | ^~~~~~~~

Cc: James Morris <jmorris@namei.org>
Cc: "Serge E. Hallyn" <serge@hallyn.com>
Cc: Paul Moore <paul@paul-moore.com>
Cc: Casey Schaufler <casey@schaufler-ca.com>
Cc: KP Singh <redacted>
Cc: linux-security-module@vger.kernel.org
Reported-by: kernel test robot <redacted>
Link: https://lore.kernel.org/linux-mm/202110131608.zms53FPR-lkp@intel.com/
Fixes: 98e828a0650f ("security: Refactor declaration of LSM hooks")
Signed-off-by: Kees Cook <redacted>
---
 security/security.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Looks reasonable to me, thanks Kees.  Unless James wants to pick this
up for the security tree, I can pull this into the SElinux tree with
the io_uring change which is causing the testing robot to complain.

Acked-by: Paul Moore <paul@paul-moore.com>
quoted hunk
diff --git a/security/security.c b/security/security.c
index 9ffa9e9c5c55..462f14354c2c 100644
--- a/security/security.c
+++ b/security/security.c
@@ -706,7 +706,7 @@ static int lsm_superblock_alloc(struct super_block *sb)
 #define LSM_RET_DEFAULT(NAME) (NAME##_default)
 #define DECLARE_LSM_RET_DEFAULT_void(DEFAULT, NAME)
 #define DECLARE_LSM_RET_DEFAULT_int(DEFAULT, NAME) \
-       static const int LSM_RET_DEFAULT(NAME) = (DEFAULT);
+       static const int __maybe_unused LSM_RET_DEFAULT(NAME) = (DEFAULT);
 #define LSM_HOOK(RET, DEFAULT, NAME, ...) \
        DECLARE_LSM_RET_DEFAULT_##RET(DEFAULT, NAME)

--
2.30.2
--
paul moore
www.paul-moore.com

Re: [PATCH] LSM: Avoid warnings about potentially unused hook variables

From: James Morris <jmorris@namei.org>
Date: 2021-10-13 22:01:43

On Wed, 13 Oct 2021, Paul Moore wrote:
Looks reasonable to me, thanks Kees.  Unless James wants to pick this
up for the security tree, I can pull this into the SElinux tree with
the io_uring change which is causing the testing robot to complain.

Acked-by: Paul Moore <paul@paul-moore.com>
Sounds good.


Acked-by: James Morris <redacted>


-- 
James Morris
[off-list ref]

Re: [PATCH] LSM: Avoid warnings about potentially unused hook variables

From: Paul Moore <paul@paul-moore.com>
Date: 2021-10-14 20:10:59

On Wed, Oct 13, 2021 at 6:01 PM James Morris [off-list ref] wrote:
On Wed, 13 Oct 2021, Paul Moore wrote:
quoted
Looks reasonable to me, thanks Kees.  Unless James wants to pick this
up for the security tree, I can pull this into the SElinux tree with
the io_uring change which is causing the testing robot to complain.

Acked-by: Paul Moore <paul@paul-moore.com>
Sounds good.

Acked-by: James Morris <redacted>
I just merged this into selinux/next, thanks everyone!

-- 
paul moore
www.paul-moore.com
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help