Skip to content

Commit 83e804f

Browse files
l0kodJames Morris
authored andcommitted
fs,security: Add sb_delete hook
The sb_delete security hook is called when shutting down a superblock, which may be useful to release kernel objects tied to the superblock's lifetime (e.g. inodes). This new hook is needed by Landlock to release (ephemerally) tagged struct inodes. This comes from the unprivileged nature of Landlock described in the next commit. Cc: Al Viro <[email protected]> Cc: James Morris <[email protected]> Signed-off-by: Mickaël Salaün <[email protected]> Reviewed-by: Jann Horn <[email protected]> Acked-by: Serge Hallyn <[email protected]> Reviewed-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: James Morris <[email protected]>
1 parent cb2c7d1 commit 83e804f

File tree

5 files changed

+14
-0
lines changed

5 files changed

+14
-0
lines changed

fs/super.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ void generic_shutdown_super(struct super_block *sb)
454454
evict_inodes(sb);
455455
/* only nonzero refcount inodes can have marks */
456456
fsnotify_sb_delete(sb);
457+
security_sb_delete(sb);
457458

458459
if (sb->s_dio_done_wq) {
459460
destroy_workqueue(sb->s_dio_done_wq);

include/linux/lsm_hook_defs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ LSM_HOOK(int, 0, fs_context_dup, struct fs_context *fc,
5959
LSM_HOOK(int, -ENOPARAM, fs_context_parse_param, struct fs_context *fc,
6060
struct fs_parameter *param)
6161
LSM_HOOK(int, 0, sb_alloc_security, struct super_block *sb)
62+
LSM_HOOK(void, LSM_RET_VOID, sb_delete, struct super_block *sb)
6263
LSM_HOOK(void, LSM_RET_VOID, sb_free_security, struct super_block *sb)
6364
LSM_HOOK(void, LSM_RET_VOID, sb_free_mnt_opts, void *mnt_opts)
6465
LSM_HOOK(int, 0, sb_eat_lsm_opts, char *orig, void **mnt_opts)

include/linux/lsm_hooks.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@
108108
* allocated.
109109
* @sb contains the super_block structure to be modified.
110110
* Return 0 if operation was successful.
111+
* @sb_delete:
112+
* Release objects tied to a superblock (e.g. inodes).
113+
* @sb contains the super_block structure being released.
111114
* @sb_free_security:
112115
* Deallocate and clear the sb->s_security field.
113116
* @sb contains the super_block structure to be modified.

include/linux/security.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ void security_bprm_committed_creds(struct linux_binprm *bprm);
291291
int security_fs_context_dup(struct fs_context *fc, struct fs_context *src_fc);
292292
int security_fs_context_parse_param(struct fs_context *fc, struct fs_parameter *param);
293293
int security_sb_alloc(struct super_block *sb);
294+
void security_sb_delete(struct super_block *sb);
294295
void security_sb_free(struct super_block *sb);
295296
void security_free_mnt_opts(void **mnt_opts);
296297
int security_sb_eat_lsm_opts(char *options, void **mnt_opts);
@@ -631,6 +632,9 @@ static inline int security_sb_alloc(struct super_block *sb)
631632
return 0;
632633
}
633634

635+
static inline void security_sb_delete(struct super_block *sb)
636+
{ }
637+
634638
static inline void security_sb_free(struct super_block *sb)
635639
{ }
636640

security/security.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,11 @@ int security_sb_alloc(struct super_block *sb)
900900
return rc;
901901
}
902902

903+
void security_sb_delete(struct super_block *sb)
904+
{
905+
call_void_hook(sb_delete, sb);
906+
}
907+
903908
void security_sb_free(struct super_block *sb)
904909
{
905910
call_void_hook(sb_free_security, sb);

0 commit comments

Comments
 (0)