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 5CC3913C689; Tue, 14 May 2024 10:39:35 +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=1715683175; cv=none; b=Zk/oS4xuE8jN6df0Blv/ZHGhYSzpQBguIAooYMhtiDFRwHDikHxAAYJWguyd0O7qQhUSZhek6/UKc4jmCKllc8UiiH2BVHQ6+LO3XELtszR4yp3Br2zM+mMb6tMrNohgDutPXdegEMC8imb/E/zIHh2KhUU7Ta7JRwkkTlFpkus= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715683175; c=relaxed/simple; bh=iQpi7/GCLZYwqW5OF70V89qv+CLNB9gfbSE6vdViPLM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PEGxMsZwfZ8MCSJHh9hpWzdX/gX0+kqyb+DDZgKd8xR3jjKbpDNSh6XrwlwITpxxB6Q+bggJ1bjfeNRbqs91oBTHjnvWiBJwopiGO8rmeuBxd98GOk3BSkGGhjHGaQ1Q1UTw0Olk7JYU9csmaIKK3u8qPId6ULcF+KxfaSTdJsI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=1YF/W67A; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="1YF/W67A" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BC6E5C2BD10; Tue, 14 May 2024 10:39:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1715683175; bh=iQpi7/GCLZYwqW5OF70V89qv+CLNB9gfbSE6vdViPLM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1YF/W67AzO9sV9BB+y48+IMteTPh9aNrgHQXeSCx93VVZQl5OPn4Afsrm6pQHqEaw /P+zu9nOMWgOMJkdcXJdvyKH4gs5+IdS+eAig4jSMj3tVnyhhTJ6EIIe7A6ZeNWO/d FWS/5IaGNLfNCZUspmJucMDpN8MJ190VG8Ye/1zM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Maurizio Lombardi , Mike Christie , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 6.8 147/336] scsi: target: Fix SELinux error when systemd-modules loads the target module Date: Tue, 14 May 2024 12:15:51 +0200 Message-ID: <20240514101044.151836730@linuxfoundation.org> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240514101038.595152603@linuxfoundation.org> References: <20240514101038.595152603@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.8-stable review patch. If anyone has any objections, please let me know. ------------------ 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 c1fbcdd161826..c40217f44b1bc 100644 --- a/drivers/target/target_core_configfs.c +++ b/drivers/target/target_core_configfs.c @@ -3672,6 +3672,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" @@ -3748,11 +3750,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