[Devel] [PATCH RH9 4/6] ext4: Don't show the active balloon to user
Kirill Tkhai
ktkhai at virtuozzo.com
Tue Oct 5 18:42:41 MSK 2021
From: Maxim V. Patlasov <mpatlasov at parallels.com>
This is a port of
e123b6d ext4: Don't show the active balloon to user
Fix the readdir and lookup. The former one pretends the inode doesn't
exists, the latter one denies an access to on. Reporting negative dentry
in lookup is pointless, as in that case smth will have to be don the
ext4_create callback :\
[VvS RH79 rebase vz7.170.x]: minor context changes
(cherry picked from vz7 commit c231c40a93927f3080067e5d880ef11841de278c)
Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>
Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
fs/ext4/dir.c | 15 ++++++++++++++-
fs/ext4/namei.c | 9 +++++++++
2 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c
index ffb295aa891c..8ed108299fbb 100644
--- a/fs/ext4/dir.c
+++ b/fs/ext4/dir.c
@@ -123,6 +123,14 @@ int __ext4_check_dir_entry(const char *function, unsigned int line,
return 1;
}
+static inline int ext4_balloon(struct super_block *sb, unsigned ino)
+{
+ struct ext4_sb_info *sbi;
+
+ sbi = EXT4_SB(sb);
+ return sbi->s_balloon_ino && (sbi->s_balloon_ino->i_ino == ino);
+}
+
static int ext4_readdir(struct file *file, struct dir_context *ctx)
{
unsigned int offset;
@@ -267,7 +275,8 @@ static int ext4_readdir(struct file *file, struct dir_context *ctx)
}
offset += ext4_rec_len_from_disk(de->rec_len,
sb->s_blocksize);
- if (le32_to_cpu(de->inode)) {
+ if (le32_to_cpu(de->inode) &&
+ !ext4_balloon(sb, le32_to_cpu(de->inode))) {
if (!IS_ENCRYPTED(inode)) {
if (!dir_emit(ctx, de->name,
de->name_len,
@@ -534,6 +543,9 @@ static int call_filldir(struct file *file, struct dir_context *ctx,
}
ctx->pos = hash2pos(file, fname->hash, fname->minor_hash);
while (fname) {
+ if (ext4_balloon(sb, fname->inode))
+ goto skip;
+
if (!dir_emit(ctx, fname->name,
fname->name_len,
fname->inode,
@@ -541,6 +553,7 @@ static int call_filldir(struct file *file, struct dir_context *ctx,
info->extra_fname = fname;
return 1;
}
+skip:
fname = fname->next;
}
return 0;
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index f3bbcd4efb56..4a71df8bf8d8 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -1797,6 +1797,11 @@ static struct dentry *ext4_lookup(struct inode *dir, struct dentry *dentry, unsi
iput(inode);
return ERR_PTR(-EPERM);
}
+ if (!IS_ERR(inode) &&
+ inode == EXT4_SB(inode->i_sb)->s_balloon_ino) {
+ iput(inode);
+ return ERR_PTR(-EPERM);
+ }
}
#ifdef CONFIG_UNICODE
@@ -3392,6 +3397,10 @@ static int ext4_unlink(struct inode *dir, struct dentry *dentry)
retval = dquot_initialize(d_inode(dentry));
if (retval)
goto out_trace;
+ if (d_inode(dentry) == EXT4_SB(dir->i_sb)->s_balloon_ino) {
+ retval = -EPERM;
+ goto out_trace;
+ }
handle = ext4_journal_start(dir, EXT4_HT_DIR,
EXT4_DATA_TRANS_BLOCKS(dir->i_sb));
More information about the Devel
mailing list