--- zzzz-none-000/linux-3.18.24/mm/filemap.c 2015-10-31 20:39:51.000000000 +0000 +++ rtl96-5690pro-762/linux-3.18.24/mm/filemap.c 2024-08-14 08:36:37.000000000 +0000 @@ -2261,6 +2261,20 @@ * Returns appropriate error code that caller should return or * zero in case that write should be allowed. */ +#ifdef CONFIG_YUEME_TMPFS_FEATURE +extern unsigned long tmpfs_file_size_limit; +extern int rtk_appframework_path_check(struct task_struct *pt); +#endif + +#ifdef CONFIG_YUEME_FS_CHECK_FEATURE +#if defined(CONFIG_YAFFS_FS) || defined(CONFIG_UBIFS_FS) +/* for YAFFS and UBIFS */ +#define YAFFS_MAGIC 0x5941ff53 +/* From ubifs.h */ +#define UBIFS_MAGIC 0x24051905 +extern unsigned long yueme_appf_fs_check(struct file *file, loff_t *pos, size_t *count); +#endif +#endif inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, int isblk) { struct inode *inode = file->f_mapping->host; @@ -2274,6 +2288,30 @@ if (file->f_flags & O_APPEND) *pos = i_size_read(inode); + +#ifdef CONFIG_YUEME_TMPFS_FEATURE + if (inode->i_sb && (inode->i_sb->s_magic == TMPFS_MAGIC)) { + if ((*pos >= tmpfs_file_size_limit) && (rtk_appframework_path_check(current))) { + pr_err("Task(%s) violated tmpfs's file_size_limit(%lu).\n" , current->comm, tmpfs_file_size_limit); + send_sig(SIGXFSZ, current, 0); + return -EFBIG; + } + if ((*count > tmpfs_file_size_limit - (typeof(limit))*pos) && (rtk_appframework_path_check(current))) { + *count = tmpfs_file_size_limit - (typeof(limit))*pos; + } + } +#endif +#ifdef CONFIG_YUEME_FS_CHECK_FEATURE +#if defined(CONFIG_YAFFS_FS) || defined(CONFIG_UBIFS_FS) + if (inode->i_sb && ((inode->i_sb->s_magic == YAFFS_MAGIC) || (inode->i_sb->s_magic == UBIFS_MAGIC))) { + if (yueme_appf_fs_check( file, pos, count)) { + pr_err("Task(%s) violated YUEME's FileSystem limit.\n" , current->comm); + send_sig(SIGXFSZ, current, 0); + return -EFBIG; + } + } +#endif +#endif if (limit != RLIM_INFINITY) { if (*pos >= limit) { send_sig(SIGXFSZ, current, 0);