From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2E7791BED69; Mon, 22 Apr 2024 23:58:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713830324; cv=none; b=reW5TnOCuf1z7af0YFj4HojijgYGtrPkG6eZ497Q0/oYXqyJIIIDEufDHOluJAnyhnYO5XiaEzN2LNPoXajOS8siH5KklnRcxy3QF6laa3EU5H78mXIvsFMXA2JMbWgUiumhAxaHem9tknY1yB51tZqIwn4W77h9XMo5Z0SwgpE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713830324; c=relaxed/simple; bh=Yss3o7fLI47a8f+5stXrldZUeTkSW0vSnzgdcoLyQ9s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HVvTBVhS2QqL9jfnjrAm2ZZU4TmBsdyStNMyt6w6bopW6e3BH6poiU1vKXyM9D8KG3BGZIk5mNZfloJb1pB8KVllmfca5ApYkKjibQMzRc0PJ6txz/BDWQuvO9XcNo2C4kpx+nH7f0N+G17ZYz68Djxy/YNLLTstARntCOAVlBM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=W8oqDx5r; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="W8oqDx5r" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 216B2C113CC; Mon, 22 Apr 2024 23:58:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713830324; bh=Yss3o7fLI47a8f+5stXrldZUeTkSW0vSnzgdcoLyQ9s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W8oqDx5r5M9ZeM1UpqiJffSg9tejmJBQEyFtXgGiiSAYYFhdpackYra7MoD27NfOQ l3DBodPGiOYb/hzjitLcyJG97iiES8WmURRJBnSR4yUVhhF+T174HDAx3U/PRJ3ckW q/GPnxG/uSt122SO8mRdAF7Phdn/KoYdloJbylnoNmBvVhW+74jk8o0cfrH9Z0xIHq 0p35KbltKZqqkOXnGwgzsBwxvsqcUOXRjiIiTS+vtgq6L4bb335apn+QqTmHuoRLZc BPUo7GRZa++Gz3tLp+INHNCmePBE+Wh9xtXrTRCrukL7Mo+iWZnweF3VKe5bFtNU/H co72eQSTAu3NQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Maurizio Lombardi , Mike Christie , "Martin K . Petersen" , Sasha Levin , linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Subject: [PATCH AUTOSEL 5.10 5/9] scsi: target: Fix SELinux error when systemd-modules loads the target module Date: Mon, 22 Apr 2024 19:19:46 -0400 Message-ID: <20240422231955.1613650-5-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240422231955.1613650-1-sashal@kernel.org> References: <20240422231955.1613650-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 5.10.215 Content-Transfer-Encoding: 8bit From: Maurizio Lombardi [ Upstream commit 97a54ef596c3fd24ec2b227ba8aaf2cf5415e779 ] 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 Link: https://lore.kernel.org/r/20240215143944.847184-2-mlombard@redhat.com Reviewed-by: Mike Christie Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/target/target_core_configfs.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/target/target_core_configfs.c b/drivers/target/target_core_configfs.c index 56ae882fb7b39..4d2fbe1429b69 100644 --- a/drivers/target/target_core_configfs.c +++ b/drivers/target/target_core_configfs.c @@ -3532,6 +3532,8 @@ static int __init target_core_init_configfs(void) { struct configfs_subsystem *subsys = &target_core_fabrics; struct t10_alua_lu_gp *lu_gp; + struct cred *kern_cred; + const struct cred *old_cred; int ret; pr_debug("TARGET_CORE[0]: Loading Generic Kernel Storage" @@ -3608,11 +3610,21 @@ static int __init target_core_init_configfs(void) if (ret < 0) goto out; + /* We use the kernel credentials to access the target directory */ + kern_cred = prepare_kernel_cred(&init_task); + if (!kern_cred) { + ret = -ENOMEM; + goto out; + } + old_cred = override_creds(kern_cred); target_init_dbroot(); + revert_creds(old_cred); + put_cred(kern_cred); return 0; out: + target_xcopy_release_pt(); configfs_unregister_subsystem(subsys); core_dev_release_virtual_lun0(); rd_module_exit(); -- 2.43.0