Skip to content

Commit 9859935

Browse files
oberpargregkh
authored andcommitted
s390/hypfs: Avoid unnecessary ioctl registration in debugfs
[ Upstream commit fec7bdf ] Currently, hypfs registers ioctl callbacks for all debugfs files, despite only one file requiring them. This leads to unintended exposure of unused interfaces to user space and can trigger side effects such as restricted access when kernel lockdown is enabled. Restrict ioctl registration to only those files that implement ioctl functionality to avoid interface clutter and unnecessary access restrictions. Tested-by: Mete Durlu <[email protected]> Reviewed-by: Vasily Gorbik <[email protected]> Fixes: 5496197 ("debugfs: Restrict debugfs when the kernel is locked down") Signed-off-by: Peter Oberparleiter <[email protected]> Signed-off-by: Alexander Gordeev <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 24a6279 commit 9859935

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

arch/s390/hypfs/hypfs_dbfs.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,23 +66,27 @@ static long dbfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
6666
long rc;
6767

6868
mutex_lock(&df->lock);
69-
if (df->unlocked_ioctl)
70-
rc = df->unlocked_ioctl(file, cmd, arg);
71-
else
72-
rc = -ENOTTY;
69+
rc = df->unlocked_ioctl(file, cmd, arg);
7370
mutex_unlock(&df->lock);
7471
return rc;
7572
}
7673

77-
static const struct file_operations dbfs_ops = {
74+
static const struct file_operations dbfs_ops_ioctl = {
7875
.read = dbfs_read,
7976
.unlocked_ioctl = dbfs_ioctl,
8077
};
8178

79+
static const struct file_operations dbfs_ops = {
80+
.read = dbfs_read,
81+
};
82+
8283
void hypfs_dbfs_create_file(struct hypfs_dbfs_file *df)
8384
{
84-
df->dentry = debugfs_create_file(df->name, 0400, dbfs_dir, df,
85-
&dbfs_ops);
85+
const struct file_operations *fops = &dbfs_ops;
86+
87+
if (df->unlocked_ioctl)
88+
fops = &dbfs_ops_ioctl;
89+
df->dentry = debugfs_create_file(df->name, 0400, dbfs_dir, df, fops);
8690
mutex_init(&df->lock);
8791
}
8892

0 commit comments

Comments
 (0)