Skip to content

Commit 97a54ef

Browse files
maurizio-lombardimartinkpetersen
authored andcommitted
scsi: target: Fix SELinux error when systemd-modules loads the target module
If the systemd-modules service loads the target module, the credentials of that userspace process will be used to validate the access to the target db directory. SELinux will prevent it, reporting an error like the following: kernel: audit: type=1400 audit(1676301082.205:4): avc: denied { read } for pid=1020 comm="systemd-modules" name="target" dev="dm-3" ino=4657583 scontext=system_u:system_r:systemd_modules_load_t:s0 tcontext=system_u:object_r:targetd_etc_rw_t:s0 tclass=dir permissive=0 Fix the error by using the kernel credentials to access the db directory Signed-off-by: Maurizio Lombardi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Mike Christie <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent d4e655c commit 97a54ef

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

drivers/target/target_core_configfs.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3672,6 +3672,8 @@ static int __init target_core_init_configfs(void)
36723672
{
36733673
struct configfs_subsystem *subsys = &target_core_fabrics;
36743674
struct t10_alua_lu_gp *lu_gp;
3675+
struct cred *kern_cred;
3676+
const struct cred *old_cred;
36753677
int ret;
36763678

36773679
pr_debug("TARGET_CORE[0]: Loading Generic Kernel Storage"
@@ -3748,11 +3750,21 @@ static int __init target_core_init_configfs(void)
37483750
if (ret < 0)
37493751
goto out;
37503752

3753+
/* We use the kernel credentials to access the target directory */
3754+
kern_cred = prepare_kernel_cred(&init_task);
3755+
if (!kern_cred) {
3756+
ret = -ENOMEM;
3757+
goto out;
3758+
}
3759+
old_cred = override_creds(kern_cred);
37513760
target_init_dbroot();
3761+
revert_creds(old_cred);
3762+
put_cred(kern_cred);
37523763

37533764
return 0;
37543765

37553766
out:
3767+
target_xcopy_release_pt();
37563768
configfs_unregister_subsystem(subsys);
37573769
core_dev_release_virtual_lun0();
37583770
rd_module_exit();

0 commit comments

Comments
 (0)