vfs_link() expects its callers to enforce protected hardlink policy via may_linkat() prior to creating a hardlink. Move the declaration of may_linkat() from fs/internal.h to include/linux/fs.h and export it with EXPORT_SYMBOL_GPL() so modular in-kernel file servers such as NFSD can invoke it before calling vfs_link(). This prepares for fixing missing hardlink restrictions in nfsd_link(), which was discovered by an AI-assisted code review tool (ARTIST), validated in QEMU without kernel modifications or error injection, and verified with kernel builds and checkpatch.pl. Fixes: 800179c9b8a1 ("fs: add link restrictions") Cc: stable@vger.kernel.org Signed-off-by: Dominik Maier --- fs/internal.h | 1 - fs/namei.c | 1 + include/linux/fs.h | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/internal.h b/fs/internal.h index 3f2fbac..7c30669 100644 --- a/fs/internal.h +++ b/fs/internal.h @@ -54,7 +54,6 @@ extern int filename_lookup(int dfd, struct filename *name, unsigned flags, struct path *path, const struct path *root); int filename_rmdir(int dfd, struct filename *name); int filename_unlinkat(int dfd, struct filename *name); -int may_linkat(const struct mnt_idmap *idmap, const struct path *link); int filename_renameat2(int olddfd, struct filename *oldname, int newdfd, struct filename *newname, unsigned int flags); int filename_mkdirat(int dfd, struct filename *name, umode_t mode); diff --git a/fs/namei.c b/fs/namei.c index 925aeb6..8f7c2dc 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -1385,6 +1385,7 @@ int may_linkat(const struct mnt_idmap *idmap, const struct path *link) audit_log_path_denied(AUDIT_ANOM_LINK, "linkat"); return -EPERM; } +EXPORT_SYMBOL_GPL(may_linkat); /** * may_create_in_sticky - Check whether an O_CREAT open in a sticky directory diff --git a/include/linux/fs.h b/include/linux/fs.h index 5b3a100..c165f27 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2740,6 +2740,7 @@ int may_delete_dentry(const struct mnt_idmap *idmap, struct inode *dir, struct dentry *victim, bool isdir); int may_create_dentry(const struct mnt_idmap *idmap, struct inode *dir, struct dentry *child); +int may_linkat(const struct mnt_idmap *idmap, const struct path *link); static inline bool execute_ok(struct inode *inode) { -- 2.56.1.750.gf70dc682cf-goog