Skip to content

Commit c43f7b8

Browse files
author
Tyler Hicks
committed
eCryptfs: Handle ioctl calls with unlocked and compat functions
Lower filesystems that only implemented unlocked_ioctl weren't being passed ioctl calls because eCryptfs only checked for lower_file->f_op->ioctl and returned -ENOTTY if it was NULL. eCryptfs shouldn't implement ioctl(), since it doesn't require the BKL. This patch introduces ecryptfs_unlocked_ioctl() and ecryptfs_compat_ioctl(), which passes the calls on to the lower file system. https://bugs.launchpad.net/ecryptfs/+bug/469664 Reported-by: James Dupin <james.dupin@gmail.com> Cc: stable@kernel.org Signed-off-by: Tyler Hicks <tyhicks@linux.vnet.ibm.com>
1 parent a1275c3 commit c43f7b8

1 file changed

Lines changed: 35 additions & 21 deletions

File tree

‎fs/ecryptfs/file.c‎

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -292,12 +292,40 @@ static int ecryptfs_fasync(int fd, struct file *file, int flag)
292292
return rc;
293293
}
294294

295-
static int ecryptfs_ioctl(struct inode *inode, struct file *file,
296-
unsigned int cmd, unsigned long arg);
295+
static long
296+
ecryptfs_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
297+
{
298+
struct file *lower_file = NULL;
299+
long rc = -ENOTTY;
300+
301+
if (ecryptfs_file_to_private(file))
302+
lower_file = ecryptfs_file_to_lower(file);
303+
if (lower_file && lower_file->f_op && lower_file->f_op->unlocked_ioctl)
304+
rc = lower_file->f_op->unlocked_ioctl(lower_file, cmd, arg);
305+
return rc;
306+
}
307+
308+
#ifdef CONFIG_COMPAT
309+
static long
310+
ecryptfs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
311+
{
312+
struct file *lower_file = NULL;
313+
long rc = -ENOIOCTLCMD;
314+
315+
if (ecryptfs_file_to_private(file))
316+
lower_file = ecryptfs_file_to_lower(file);
317+
if (lower_file && lower_file->f_op && lower_file->f_op->compat_ioctl)
318+
rc = lower_file->f_op->compat_ioctl(lower_file, cmd, arg);
319+
return rc;
320+
}
321+
#endif
297322

298323
const struct file_operations ecryptfs_dir_fops = {
299324
.readdir = ecryptfs_readdir,
300-
.ioctl = ecryptfs_ioctl,
325+
.unlocked_ioctl = ecryptfs_unlocked_ioctl,
326+
#ifdef CONFIG_COMPAT
327+
.compat_ioctl = ecryptfs_compat_ioctl,
328+
#endif
301329
.open = ecryptfs_open,
302330
.flush = ecryptfs_flush,
303331
.release = ecryptfs_release,
@@ -313,7 +341,10 @@ const struct file_operations ecryptfs_main_fops = {
313341
.write = do_sync_write,
314342
.aio_write = generic_file_aio_write,
315343
.readdir = ecryptfs_readdir,
316-
.ioctl = ecryptfs_ioctl,
344+
.unlocked_ioctl = ecryptfs_unlocked_ioctl,
345+
#ifdef CONFIG_COMPAT
346+
.compat_ioctl = ecryptfs_compat_ioctl,
347+
#endif
317348
.mmap = generic_file_mmap,
318349
.open = ecryptfs_open,
319350
.flush = ecryptfs_flush,
@@ -322,20 +353,3 @@ const struct file_operations ecryptfs_main_fops = {
322353
.fasync = ecryptfs_fasync,
323354
.splice_read = generic_file_splice_read,
324355
};
325-
326-
static int
327-
ecryptfs_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
328-
unsigned long arg)
329-
{
330-
int rc = 0;
331-
struct file *lower_file = NULL;
332-
333-
if (ecryptfs_file_to_private(file))
334-
lower_file = ecryptfs_file_to_lower(file);
335-
if (lower_file && lower_file->f_op && lower_file->f_op->ioctl)
336-
rc = lower_file->f_op->ioctl(ecryptfs_inode_to_lower(inode),
337-
lower_file, cmd, arg);
338-
else
339-
rc = -ENOTTY;
340-
return rc;
341-
}

0 commit comments

Comments
 (0)