Skip to contentSkip to conversation

lsm: fix default return values for some hooks

PATCH In review Ondrej Mosnacek 2 participants 6 messages Oct 31, 2023 – Nov 8, 2023

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

cover lsm: fix default return values for some hooks

Some of the default return values listed in <linux/lsm_hook_defs.h> don't match the actual no-op value and can be trivially fixed.

Ondrej Mosnacek (2):
lsm: fix default return value for vm_enough_memory
lsm: fix default return value for inode_getsecctx

 include/linux/lsm_hook_defs.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Signature · 1 line
2.41.0
#1 lore raw

PATCH 1/2 lsm: fix default return value for vm_enough_memory

1 is the return value that implements a "no-op" hook, not 0.

Fixes 98e828a0650f ("security: Refactor declaration of LSM hooks")
---
 include/linux/lsm_hook_defs.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/lsm_hook_defs.h +1 -1
index 99b8176c3738d..4dd55fdfec267 100644
@@ -48,7 +48,7 @@ LSM_HOOK(int, 0, quota_on, struct dentry *dentry)
 LSM_HOOK(int, 0, syslog, int type)
 LSM_HOOK(int, 0, settime, const struct timespec64 *ts,
 	 const struct timezone *tz)
-LSM_HOOK(int, 0, vm_enough_memory, struct mm_struct *mm, long pages)
+LSM_HOOK(int, 1, vm_enough_memory, struct mm_struct *mm, long pages)
 LSM_HOOK(int, 0, bprm_creds_for_exec, struct linux_binprm *bprm)
 LSM_HOOK(int, 0, bprm_creds_from_file, struct linux_binprm *bprm, const struct file *file)
 LSM_HOOK(int, 0, bprm_check_security, struct linux_binprm *bprm)
Signature · 1 line
2.41.0
#2 lore raw

PATCH 2/2 lsm: fix default return value for inode_getsecctx

In reply to Ondrej Mosnacek

-EOPNOTSUPP is the return value that implements a "no-op" hook, not 0.

Without this fix having only the BPF LSM enabled (with no programs attached) can cause uninitialized variable reads in nfsd4_encode_fattr(), because the BPF hook returns 0 without touching the 'ctxlen' variable and the corresponding 'contextlen' variable in nfsd4_encode_fattr() remains uninitialized, yet being treated as valid based on the 0 return value.

Fixes 98e828a0650f ("security: Refactor declaration of LSM hooks")
---
 include/linux/lsm_hook_defs.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/lsm_hook_defs.h +1 -1
index 4dd55fdfec267..ff217a5ce5521 100644
@@ -273,7 +273,7 @@ LSM_HOOK(void, LSM_RET_VOID, release_secctx, char *secdata, u32 seclen)
 LSM_HOOK(void, LSM_RET_VOID, inode_invalidate_secctx, struct inode *inode)
 LSM_HOOK(int, 0, inode_notifysecctx, struct inode *inode, void *ctx, u32 ctxlen)
 LSM_HOOK(int, 0, inode_setsecctx, struct dentry *dentry, void *ctx, u32 ctxlen)
-LSM_HOOK(int, 0, inode_getsecctx, struct inode *inode, void **ctx,
+LSM_HOOK(int, -EOPNOTSUPP, inode_getsecctx, struct inode *inode, void **ctx,
 	 u32 *ctxlen)
 
 #if defined(CONFIG_SECURITY) && defined(CONFIG_WATCH_QUEUE)
Signature · 1 line
2.41.0
maintainer
#3 lore raw
In reply to Ondrej Mosnacek
Quoted 10 lines · Ondrej Mosnacek

Some of the default return values listed in <linux/lsm_hook_defs.h> don't match the actual no-op value and can be trivially fixed.

Ondrej Mosnacek (2):
lsm: fix default return value for vm_enough_memory
lsm: fix default return value for inode_getsecctx

 include/linux/lsm_hook_defs.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

These both look like reasonable -stable candidates to me, what do you think?

Signature · 1 line
paul-moore.com
#4 lore raw
Quoted 6 lines · Paul Moore
Quoted 4 lines · Ondrej Mosnacek

Some of the default return values listed in <linux/lsm_hook_defs.h> don't match the actual no-op value and can be trivially fixed.

Quoted 8 lines
Quoted 6 lines

Ondrej Mosnacek (2):
lsm: fix default return value for vm_enough_memory
lsm: fix default return value for inode_getsecctx

 include/linux/lsm_hook_defs.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

These both look like reasonable -stable candidates to me, what do you think?

Yes, that would be my assessment as well.

Signature · 3 lines
Ondrej Mosnacek
Senior Software Engineer, Linux Security - SELinux kernel
Red Hat, Inc.
maintainer
#5 lore raw
Quoted 10 lines · Ondrej Mosnacek
Quoted 9 lines · Paul Moore
Quoted 8 lines · Ondrej Mosnacek

Some of the default return values listed in <linux/lsm_hook_defs.h> don't match the actual no-op value and can be trivially fixed.

Ondrej Mosnacek (2):
lsm: fix default return value for vm_enough_memory
lsm: fix default return value for inode_getsecctx

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
 include/linux/lsm_hook_defs.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

These both look like reasonable -stable candidates to me, what do you think?

Yes, that would be my assessment as well.

Okay, good. I've just gone ahead and merged these into lsm/stable-6.7 and I'll plan to send them up to Linus on Thursday or Friday this week. Thanks.

Signature · 1 line
paul-moore.com