Skip to content

Commit 9b872cc

Browse files
committed
ntfs3: add legacy ntfs file operations
To ensure that ioctl()s can't be used to circumvent write restrictions. Signed-off-by: Christian Brauner <[email protected]>
1 parent d55f90e commit 9b872cc

File tree

4 files changed

+33
-4
lines changed

4 files changed

+33
-4
lines changed

fs/ntfs3/dir.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,4 +616,11 @@ const struct file_operations ntfs_dir_operations = {
616616
.compat_ioctl = ntfs_compat_ioctl,
617617
#endif
618618
};
619+
620+
const struct file_operations ntfs_legacy_dir_operations = {
621+
.llseek = generic_file_llseek,
622+
.read = generic_read_dir,
623+
.iterate_shared = ntfs_readdir,
624+
.open = ntfs_file_open,
625+
};
619626
// clang-format on

fs/ntfs3/file.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,4 +1236,12 @@ const struct file_operations ntfs_file_operations = {
12361236
.fallocate = ntfs_fallocate,
12371237
.release = ntfs_file_release,
12381238
};
1239+
1240+
const struct file_operations ntfs_legacy_file_operations = {
1241+
.llseek = generic_file_llseek,
1242+
.read_iter = ntfs_file_read_iter,
1243+
.splice_read = ntfs_file_splice_read,
1244+
.open = ntfs_file_open,
1245+
.release = ntfs_file_release,
1246+
};
12391247
// clang-format on

fs/ntfs3/inode.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,10 @@ static struct inode *ntfs_read_mft(struct inode *inode,
440440
* Usually a hard links to directories are disabled.
441441
*/
442442
inode->i_op = &ntfs_dir_inode_operations;
443-
inode->i_fop = &ntfs_dir_operations;
443+
if (is_legacy_ntfs(inode->i_sb))
444+
inode->i_fop = &ntfs_legacy_dir_operations;
445+
else
446+
inode->i_fop = &ntfs_dir_operations;
444447
ni->i_valid = 0;
445448
} else if (S_ISLNK(mode)) {
446449
ni->std_fa &= ~FILE_ATTRIBUTE_DIRECTORY;
@@ -450,7 +453,10 @@ static struct inode *ntfs_read_mft(struct inode *inode,
450453
} else if (S_ISREG(mode)) {
451454
ni->std_fa &= ~FILE_ATTRIBUTE_DIRECTORY;
452455
inode->i_op = &ntfs_file_inode_operations;
453-
inode->i_fop = &ntfs_file_operations;
456+
if (is_legacy_ntfs(inode->i_sb))
457+
inode->i_fop = &ntfs_legacy_file_operations;
458+
else
459+
inode->i_fop = &ntfs_file_operations;
454460
inode->i_mapping->a_ops = is_compressed(ni) ? &ntfs_aops_cmpr :
455461
&ntfs_aops;
456462
if (ino != MFT_REC_MFT)
@@ -1614,7 +1620,10 @@ struct inode *ntfs_create_inode(struct mnt_idmap *idmap, struct inode *dir,
16141620

16151621
if (S_ISDIR(mode)) {
16161622
inode->i_op = &ntfs_dir_inode_operations;
1617-
inode->i_fop = &ntfs_dir_operations;
1623+
if (is_legacy_ntfs(inode->i_sb))
1624+
inode->i_fop = &ntfs_legacy_dir_operations;
1625+
else
1626+
inode->i_fop = &ntfs_dir_operations;
16181627
} else if (S_ISLNK(mode)) {
16191628
inode->i_op = &ntfs_link_inode_operations;
16201629
inode->i_fop = NULL;
@@ -1623,7 +1632,10 @@ struct inode *ntfs_create_inode(struct mnt_idmap *idmap, struct inode *dir,
16231632
inode_nohighmem(inode);
16241633
} else if (S_ISREG(mode)) {
16251634
inode->i_op = &ntfs_file_inode_operations;
1626-
inode->i_fop = &ntfs_file_operations;
1635+
if (is_legacy_ntfs(inode->i_sb))
1636+
inode->i_fop = &ntfs_legacy_file_operations;
1637+
else
1638+
inode->i_fop = &ntfs_file_operations;
16271639
inode->i_mapping->a_ops = is_compressed(ni) ? &ntfs_aops_cmpr :
16281640
&ntfs_aops;
16291641
init_rwsem(&ni->file.run_lock);

fs/ntfs3/ntfs_fs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ struct inode *dir_search_u(struct inode *dir, const struct cpu_str *uni,
493493
struct ntfs_fnd *fnd);
494494
bool dir_is_empty(struct inode *dir);
495495
extern const struct file_operations ntfs_dir_operations;
496+
extern const struct file_operations ntfs_legacy_dir_operations;
496497

497498
/* Globals from file.c */
498499
int ntfs_getattr(struct mnt_idmap *idmap, const struct path *path,
@@ -507,6 +508,7 @@ long ntfs_compat_ioctl(struct file *filp, u32 cmd, unsigned long arg);
507508
extern const struct inode_operations ntfs_special_inode_operations;
508509
extern const struct inode_operations ntfs_file_inode_operations;
509510
extern const struct file_operations ntfs_file_operations;
511+
extern const struct file_operations ntfs_legacy_file_operations;
510512

511513
/* Globals from frecord.c */
512514
void ni_remove_mi(struct ntfs_inode *ni, struct mft_inode *mi);

0 commit comments

Comments
 (0)