Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp2617308lqt; Mon, 22 Apr 2024 16:57:06 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWjEGamdySIeNpdMkE0q0+83F6mLJbz7uj/7+9o4qxPL06Fh1zGbBpteIF8nQ1SI70is4sjqM6UoXenNFav3+MlS/l8iTBt++JlyKlH5w== X-Google-Smtp-Source: AGHT+IF3IHWzkX1B2nzrVGOuOMW6l9vabieXGBrGBNAUAxE2EY2HLHVl4Wa7xo03ATUX6i6eUcy5 X-Received: by 2002:a05:6a20:c6cd:b0:1ac:b640:8f with SMTP id gw13-20020a056a20c6cd00b001acb640008fmr13096014pzb.61.1713830226510; Mon, 22 Apr 2024 16:57:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713830226; cv=pass; d=google.com; s=arc-20160816; b=zvZj0RdUWR2YS0wrym3dPJXSslB2MRmQgi03wAsFwhBBIpXizmUvFVSFFjRkc5Ciql kRkRE9uR0mMXCYwilTs1HjHAPWq6efTLkrCAMf2+VNbb75Fynrx0f8StDwxem0kNcfaR X4ZZ2PVmWESaW5ftHH4sLdU+08kzFUlqoAltl1r0JHtgCOJIe/NYoQhQiQOYzEYul1wX fWEHiLKL3Af1sGO+SMoUPbcZkwl4N01O4/uwtl3mteLDhW/CxAiEaSgJLJKDLeFTLWY4 fhJOj2wCU8WtVZ4n7O5eIeeej61IbSi17mXkR3BSO5k1gkPb7XTwCO3qVmy+6Mf4wHSL IDKA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=C6bLgKEN9qAYgGaJIWw1cy63sJyqQI7/prfkBijJ00k=; fh=8FXj8WORQxIIVHcjcrrVWwSx5y2GS+9fK5Xwar47PDo=; b=h0MxM7YkzTAHBIi4x4WwC3BLxwMb6ivosCgj2xhMgqMxiyJH2r23BiJyxWA6gC/hji oUeM3Kk6GXC9HqieNl1MC+kePhbJT5QJWjtttVqFkNnRLpeiJ1Z+4SUh/Z97sXHb+g4/ tUwykWtQyuYIgX9q6yFQhXTw8e6OmcbuMHohtY8jQc7SVHx8TEzuQB1XaL6HbF1epOSp 3qVYnPk6pOuNI28IqSwNcCRRE/M5bS01HnefQovhVkmSNJH6P9yiLG3BLckWd6xUMErT k4D44pyGl0mZsnTJUbhQI3hvaRxOQV+LJHFrNcMhRAjbyG2h1GXqnjAiVwNx/iBmq6DW yJyQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lCXYPCdJ; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-154231-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-154231-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id f14-20020a056a0022ce00b006ed1790830fsi8760751pfj.75.2024.04.22.16.57.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 16:57:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-154231-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lCXYPCdJ; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-154231-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-154231-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 90C7D287DDF for ; Mon, 22 Apr 2024 23:57:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C84FB157495; Mon, 22 Apr 2024 23:54:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lCXYPCdJ" 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 E419D47F51; Mon, 22 Apr 2024 23:54:31 +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=1713830072; cv=none; b=h9A1QudGRAQG5IBwHbOU4ZBEyXsI1gzlq4Bj2eEeGaNAke4r+/iKLGH+rPx7LF4FqE7RmSTOfdPRcIVTu+/+AvMRrEJ50ruOYp+qWteyy5Bavsr0/Zty5F49vdMWvAp2bk9WGfzLDzJiHSA+ONS2v3MRZSPeKnqZRdhUFNNmlDQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713830072; c=relaxed/simple; bh=KlMbEl0NNUiSxTwSRNqwjjsGlwj+BgTY5HNovbG8Vo0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=D0zMZ2nRBv52PTb+ysb6Ak98fuyXcemAEmiFfipYZHcNLvNsnGDQ+Rnu7/FgDUP9ZhluCz1oiTwXQ+ntwlrewutnKn0i2GsxZaUkHpRtO0egiY4Eub7kuX8pjdoFBL3Z84DqKK8TfPBF44J5y1wt7gJ/+LTvLLcn6eEDKlEGfe0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lCXYPCdJ; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id DBAF6C3277B; Mon, 22 Apr 2024 23:54:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713830071; bh=KlMbEl0NNUiSxTwSRNqwjjsGlwj+BgTY5HNovbG8Vo0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lCXYPCdJD1CEdgtszxDR3vgpJBDalYVsCbDBVVtdM/7gbc/vjFDoy5WnPvBoMnJlx 8NQrSol5lXBShwQ/JyVvKm43Srp2LME8rkHDRR2QZnk86IPOih5oG7WCmlS5LvLxtc kRvYDzUHK6NuDiOC+eu71jX3CyHxdoV6ZajAnq7GknY2/y1RbBvW0YTok4xVvPRihD tpnystuygoPNjr8Jf01Ql2oPSv9+ZAPfAroRn7O05/2UMFxbZWEuHfawRSHy+0vIVO JfHcZ9x0Svj5M0TGUkMioU9fpN39SBxNthkjwUQ9Ft5M9kadLK41nUWE6lTaOwk/P7 kKoZEHOGFAkew== 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 6.8 14/43] scsi: target: Fix SELinux error when systemd-modules loads the target module Date: Mon, 22 Apr 2024 19:14:00 -0400 Message-ID: <20240422231521.1592991-14-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240422231521.1592991-1-sashal@kernel.org> References: <20240422231521.1592991-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.8.7 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 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