Skip to content

Commit 972d840

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 <meted@linux.ibm.com> Reviewed-by: Vasily Gorbik <gor@linux.ibm.com> Fixes: 5496197 ("debugfs: Restrict debugfs when the kernel is locked down") Signed-off-by: Peter Oberparleiter <oberpar@linux.ibm.com> Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 81a0f00 commit 972d840

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
@@ -64,24 +64,28 @@ static long dbfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
6464
long rc;
6565

6666
mutex_lock(&df->lock);
67-
if (df->unlocked_ioctl)
68-
rc = df->unlocked_ioctl(file, cmd, arg);
69-
else
70-
rc = -ENOTTY;
67+
rc = df->unlocked_ioctl(file, cmd, arg);
7168
mutex_unlock(&df->lock);
7269
return rc;
7370
}
7471

75-
static const struct file_operations dbfs_ops = {
72+
static const struct file_operations dbfs_ops_ioctl = {
7673
.read = dbfs_read,
7774
.llseek = no_llseek,
7875
.unlocked_ioctl = dbfs_ioctl,
7976
};
8077

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

0 commit comments

Comments
 (0)