From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from canpmsgout04.his.huawei.com (canpmsgout04.his.huawei.com [113.46.200.219]) (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 41A2E47798A; Thu, 24 Sep 2026 10:22:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.219 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790245358; cv=none; b=GU8tCY87XwKF37fiORPkaLm8kk+UziTIpwCNlrabkfF/WieJuTpnsEF35fIJU+NknPsyTXMtNnd83N29V3P5OkZQzQUY8/6NyXuumBjmlt7sz9xgcOfdCpkISdVpK8lFKMfYrtB+RADlNeBMFUp797reBoPStjv6y9lUflYB49Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790245358; c=relaxed/simple; bh=xMvFOKaxRGN6FGa6PSSXKKHP5V98CEeeE7KMOo+FrJw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pIgxLG1clqBRQN2aid8gSA+HrO8tjxMkP0eRn/QToRonYDc+ZCS3oVfoR4WJwLihQnNhB6Z8FLInKyRC+9mcUM2TWXfEV31P88SYwrZqtb8zSQlB4zRS7yVztVgo7yTxaFuZePjEYGF820vBnI2W+Z6911+3jHH97H+gLpsNYvE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=RG4Fy1P9; arc=none smtp.client-ip=113.46.200.219 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="RG4Fy1P9" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=scpxykvaJ6IR0KlcEgHZABm57FbZxqSwIYwnIN+9DX4=; b=RG4Fy1P9Pg5DYIVbIy0nl2VdXcQNa74ATc2Jcd+Zs88h1LrMMcvA69omrEFDvLsYjwCEQ1r/C Reu8+9doJVu3Ipnjl7gGbys5Q9k2e27W6y4afo7ii1c3JwpUPsLCo/L7Icpyvfl4U7+ZJcHeLQM DjZh8YvQO/MuLdRvgOB/00E= Received: from mail.maildlp.com (unknown [172.19.162.140]) by canpmsgout04.his.huawei.com (SkyGuard) with ESMTPS id 4hr8jD6QrRz1prM0; Thu, 24 Sep 2026 18:10:24 +0800 (CST) Received: from whupemk100010.china.huawei.com (unknown [7.152.184.41]) by mail.maildlp.com (Postfix) with ESMTPS id A27C2202E6; Thu, 24 Sep 2026 18:22:32 +0800 (CST) Received: from octopus.huawei.com (10.67.174.191) by whupemk100010.china.huawei.com (7.152.184.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.45; Thu, 24 Sep 2026 18:22:28 +0800 From: Cai Xinchen To: , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH RFC -next 02/12] LSM: pass struct path to the inode_setsecctx hook Date: Thu, 24 Sep 2026 18:48:21 +0800 Message-ID: <20260924104831.1081137-3-caixinchen1@huawei.com> X-Mailer: git-send-email 2.18.0.huawei.25 In-Reply-To: <20260924104831.1081137-1-caixinchen1@huawei.com> References: <20260924104831.1081137-1-caixinchen1@huawei.com> Precedence: bulk X-Mailing-List: linux-security-module@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain X-ClientProxiedBy: kwepems200001.china.huawei.com (7.221.188.67) To whupemk100010.china.huawei.com (7.152.184.41) The inode_setsecctx hook and its security_inode_setsecctx() caller in fs/nfsd operate on a dentry even though both have a struct path available. The SELinux and Smack implementations write the label through __vfs_setxattr_locked(), whose idmap argument they hardcode to &nop_mnt_idmap. Switch the hook to take a const struct path so that the upcoming conversion of the xattr helpers to struct path can be reflected directly in the implementations. For now the implementations keep passing &nop_mnt_idmap together with path->dentry to __vfs_setxattr_locked(), preserving the current behavior; they will be switched to pass the path itself once the xattr helpers take one. Assisted-by: opencode: glm-5.3 Signed-off-by: Cai Xinchen --- fs/nfsd/vfs.c | 2 +- include/linux/lsm_hook_defs.h | 2 +- include/linux/security.h | 4 ++-- security/security.c | 6 +++--- security/selinux/hooks.c | 6 +++--- security/smack/smack_lsm.c | 6 +++--- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index ed8e04cc794e..922337083fe9 100644 --- a/fs/nfsd/vfs.c +++ b/fs/nfsd/vfs.c @@ -625,7 +625,7 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, break; } if (attr->na_seclabel && attr->na_seclabel->len) - attr->na_labelerr = security_inode_setsecctx(dentry, + attr->na_labelerr = security_inode_setsecctx(&path, attr->na_seclabel->data, attr->na_seclabel->len); if (IS_ENABLED(CONFIG_FS_POSIX_ACL) && attr->na_dpacl) { if (!S_ISDIR(inode->i_mode)) diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h index f4939137e66b..b22f7928523e 100644 --- a/include/linux/lsm_hook_defs.h +++ b/include/linux/lsm_hook_defs.h @@ -314,7 +314,7 @@ LSM_HOOK(int, 0, secctx_to_secid, const char *secdata, u32 seclen, u32 *secid) LSM_HOOK(void, LSM_RET_VOID, release_secctx, struct lsm_context *cp) LSM_HOOK(void, LSM_RET_VOID, inode_invalidate_secctx, struct inode *inode) LSM_HOOK(int, 0, inode_notifysecctx, struct inode *inode, void *ctx, u32 ctxlen) -LSM_HOOK(int, 0, inode_setsecctx, struct dentry *dentry, void *ctx, u32 ctxlen) +LSM_HOOK(int, 0, inode_setsecctx, const struct path *path, void *ctx, u32 ctxlen) LSM_HOOK(int, -EOPNOTSUPP, inode_getsecctx, struct inode *inode, struct lsm_context *cp) diff --git a/include/linux/security.h b/include/linux/security.h index e3c8b4479a0a..6ac9fb634017 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -589,7 +589,7 @@ int security_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid); void security_release_secctx(struct lsm_context *cp); void security_inode_invalidate_secctx(struct inode *inode); int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen); -int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen); +int security_inode_setsecctx(const struct path *path, void *ctx, u32 ctxlen); int security_inode_getsecctx(struct inode *inode, struct lsm_context *cp); int security_locked_down(enum lockdown_reason what); int lsm_fill_user_ctx(struct lsm_ctx __user *uctx, u32 *uctx_len, @@ -1637,7 +1637,7 @@ static inline int security_inode_notifysecctx(struct inode *inode, void *ctx, u3 { return -EOPNOTSUPP; } -static inline int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen) +static inline int security_inode_setsecctx(const struct path *path, void *ctx, u32 ctxlen) { return -EOPNOTSUPP; } diff --git a/security/security.c b/security/security.c index bf0ec31f1047..de3ed5c18802 100644 --- a/security/security.c +++ b/security/security.c @@ -4134,7 +4134,7 @@ EXPORT_SYMBOL(security_inode_notifysecctx); /** * security_inode_setsecctx() - Change the security label of an inode - * @dentry: inode + * @path: inode * @ctx: secctx * @ctxlen: length of secctx * @@ -4148,9 +4148,9 @@ EXPORT_SYMBOL(security_inode_notifysecctx); * * Return: Returns 0 on success, error on failure. */ -int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen) +int security_inode_setsecctx(const struct path *path, void *ctx, u32 ctxlen) { - return call_int_hook(inode_setsecctx, dentry, ctx, ctxlen); + return call_int_hook(inode_setsecctx, path, ctx, ctxlen); } EXPORT_SYMBOL(security_inode_setsecctx); diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index f2394cf6646e..8af024fe4fb5 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -7166,10 +7166,10 @@ static int selinux_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen /* * called with inode->i_mutex locked */ -static int selinux_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen) +static int selinux_inode_setsecctx(const struct path *path, void *ctx, u32 ctxlen) { - return __vfs_setxattr_locked(&nop_mnt_idmap, dentry, XATTR_NAME_SELINUX, - ctx, ctxlen, 0, NULL); + return __vfs_setxattr_locked(&nop_mnt_idmap, path->dentry, + XATTR_NAME_SELINUX, ctx, ctxlen, 0, NULL); } static int selinux_inode_getsecctx(struct inode *inode, struct lsm_context *cp) diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c index 4439821a5e57..d9e9f4a52567 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -4978,10 +4978,10 @@ static int smack_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen) ctxlen, 0); } -static int smack_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen) +static int smack_inode_setsecctx(const struct path *path, void *ctx, u32 ctxlen) { - return __vfs_setxattr_locked(&nop_mnt_idmap, dentry, XATTR_NAME_SMACK, - ctx, ctxlen, 0, NULL); + return __vfs_setxattr_locked(&nop_mnt_idmap, path->dentry, + XATTR_NAME_SMACK, ctx, ctxlen, 0, NULL); } static int smack_inode_getsecctx(struct inode *inode, struct lsm_context *cp) -- 2.18.0.huawei.25