xref: /linux/fs/ecryptfs/file.c (revision 5a0e3ad6af8660be21ca98a971cd00f331318c05)
1237fead6SMichael Halcrow /**
2237fead6SMichael Halcrow  * eCryptfs: Linux filesystem encryption layer
3237fead6SMichael Halcrow  *
4237fead6SMichael Halcrow  * Copyright (C) 1997-2004 Erez Zadok
5237fead6SMichael Halcrow  * Copyright (C) 2001-2004 Stony Brook University
6dd2a3b7aSMichael Halcrow  * Copyright (C) 2004-2007 International Business Machines Corp.
7237fead6SMichael Halcrow  *   Author(s): Michael A. Halcrow <mhalcrow@us.ibm.com>
8237fead6SMichael Halcrow  *   		Michael C. Thompson <mcthomps@us.ibm.com>
9237fead6SMichael Halcrow  *
10237fead6SMichael Halcrow  * This program is free software; you can redistribute it and/or
11237fead6SMichael Halcrow  * modify it under the terms of the GNU General Public License as
12237fead6SMichael Halcrow  * published by the Free Software Foundation; either version 2 of the
13237fead6SMichael Halcrow  * License, or (at your option) any later version.
14237fead6SMichael Halcrow  *
15237fead6SMichael Halcrow  * This program is distributed in the hope that it will be useful, but
16237fead6SMichael Halcrow  * WITHOUT ANY WARRANTY; without even the implied warranty of
17237fead6SMichael Halcrow  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18237fead6SMichael Halcrow  * General Public License for more details.
19237fead6SMichael Halcrow  *
20237fead6SMichael Halcrow  * You should have received a copy of the GNU General Public License
21237fead6SMichael Halcrow  * along with this program; if not, write to the Free Software
22237fead6SMichael Halcrow  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23237fead6SMichael Halcrow  * 02111-1307, USA.
24237fead6SMichael Halcrow  */
25237fead6SMichael Halcrow 
26237fead6SMichael Halcrow #include <linux/file.h>
27237fead6SMichael Halcrow #include <linux/poll.h>
28*5a0e3ad6STejun Heo #include <linux/slab.h>
29237fead6SMichael Halcrow #include <linux/mount.h>
30237fead6SMichael Halcrow #include <linux/pagemap.h>
31237fead6SMichael Halcrow #include <linux/security.h>
32237fead6SMichael Halcrow #include <linux/compat.h>
330cc72dc7SJosef "Jeff" Sipek #include <linux/fs_stack.h>
34dda6445eSJonathan Corbet #include <linux/smp_lock.h>
35237fead6SMichael Halcrow #include "ecryptfs_kernel.h"
36237fead6SMichael Halcrow 
37237fead6SMichael Halcrow /**
38237fead6SMichael Halcrow  * ecryptfs_read_update_atime
39237fead6SMichael Halcrow  *
40237fead6SMichael Halcrow  * generic_file_read updates the atime of upper layer inode.  But, it
41237fead6SMichael Halcrow  * doesn't give us a chance to update the atime of the lower layer
42237fead6SMichael Halcrow  * inode.  This function is a wrapper to generic_file_read.  It
43237fead6SMichael Halcrow  * updates the atime of the lower level inode if generic_file_read
44237fead6SMichael Halcrow  * returns without any errors. This is to be used only for file reads.
45237fead6SMichael Halcrow  * The function to be used for directory reads is ecryptfs_read.
46237fead6SMichael Halcrow  */
47237fead6SMichael Halcrow static ssize_t ecryptfs_read_update_atime(struct kiocb *iocb,
48237fead6SMichael Halcrow 				const struct iovec *iov,
49237fead6SMichael Halcrow 				unsigned long nr_segs, loff_t pos)
50237fead6SMichael Halcrow {
51237fead6SMichael Halcrow 	int rc;
52237fead6SMichael Halcrow 	struct dentry *lower_dentry;
53237fead6SMichael Halcrow 	struct vfsmount *lower_vfsmount;
54237fead6SMichael Halcrow 	struct file *file = iocb->ki_filp;
55237fead6SMichael Halcrow 
56237fead6SMichael Halcrow 	rc = generic_file_aio_read(iocb, iov, nr_segs, pos);
57237fead6SMichael Halcrow 	/*
58237fead6SMichael Halcrow 	 * Even though this is a async interface, we need to wait
59237fead6SMichael Halcrow 	 * for IO to finish to update atime
60237fead6SMichael Halcrow 	 */
61237fead6SMichael Halcrow 	if (-EIOCBQUEUED == rc)
62237fead6SMichael Halcrow 		rc = wait_on_sync_kiocb(iocb);
63237fead6SMichael Halcrow 	if (rc >= 0) {
64bd243a4bSJosef "Jeff" Sipek 		lower_dentry = ecryptfs_dentry_to_lower(file->f_path.dentry);
65bd243a4bSJosef "Jeff" Sipek 		lower_vfsmount = ecryptfs_dentry_to_lower_mnt(file->f_path.dentry);
66237fead6SMichael Halcrow 		touch_atime(lower_vfsmount, lower_dentry);
67237fead6SMichael Halcrow 	}
68237fead6SMichael Halcrow 	return rc;
69237fead6SMichael Halcrow }
70237fead6SMichael Halcrow 
71237fead6SMichael Halcrow struct ecryptfs_getdents_callback {
72237fead6SMichael Halcrow 	void *dirent;
73237fead6SMichael Halcrow 	struct dentry *dentry;
74237fead6SMichael Halcrow 	filldir_t filldir;
75237fead6SMichael Halcrow 	int filldir_called;
76237fead6SMichael Halcrow 	int entries_written;
77237fead6SMichael Halcrow };
78237fead6SMichael Halcrow 
797d6c7045SMichael Halcrow /* Inspired by generic filldir in fs/readdir.c */
80237fead6SMichael Halcrow static int
81addd65adSMichael Halcrow ecryptfs_filldir(void *dirent, const char *lower_name, int lower_namelen,
82addd65adSMichael Halcrow 		 loff_t offset, u64 ino, unsigned int d_type)
83237fead6SMichael Halcrow {
84237fead6SMichael Halcrow 	struct ecryptfs_getdents_callback *buf =
85237fead6SMichael Halcrow 	    (struct ecryptfs_getdents_callback *)dirent;
86a8f12864SMichael Halcrow 	size_t name_size;
87addd65adSMichael Halcrow 	char *name;
88237fead6SMichael Halcrow 	int rc;
89237fead6SMichael Halcrow 
90237fead6SMichael Halcrow 	buf->filldir_called++;
91addd65adSMichael Halcrow 	rc = ecryptfs_decode_and_decrypt_filename(&name, &name_size,
92addd65adSMichael Halcrow 						  buf->dentry, lower_name,
93addd65adSMichael Halcrow 						  lower_namelen);
94addd65adSMichael Halcrow 	if (rc) {
95addd65adSMichael Halcrow 		printk(KERN_ERR "%s: Error attempting to decode and decrypt "
96addd65adSMichael Halcrow 		       "filename [%s]; rc = [%d]\n", __func__, lower_name,
97addd65adSMichael Halcrow 		       rc);
98237fead6SMichael Halcrow 		goto out;
99237fead6SMichael Halcrow 	}
100addd65adSMichael Halcrow 	rc = buf->filldir(buf->dirent, name, name_size, offset, ino, d_type);
101addd65adSMichael Halcrow 	kfree(name);
102237fead6SMichael Halcrow 	if (rc >= 0)
103237fead6SMichael Halcrow 		buf->entries_written++;
104237fead6SMichael Halcrow out:
105237fead6SMichael Halcrow 	return rc;
106237fead6SMichael Halcrow }
107237fead6SMichael Halcrow 
108237fead6SMichael Halcrow /**
109237fead6SMichael Halcrow  * ecryptfs_readdir
110addd65adSMichael Halcrow  * @file: The eCryptfs directory file
111addd65adSMichael Halcrow  * @dirent: Directory entry handle
112237fead6SMichael Halcrow  * @filldir: The filldir callback function
113237fead6SMichael Halcrow  */
114237fead6SMichael Halcrow static int ecryptfs_readdir(struct file *file, void *dirent, filldir_t filldir)
115237fead6SMichael Halcrow {
116237fead6SMichael Halcrow 	int rc;
117237fead6SMichael Halcrow 	struct file *lower_file;
118237fead6SMichael Halcrow 	struct inode *inode;
119237fead6SMichael Halcrow 	struct ecryptfs_getdents_callback buf;
120237fead6SMichael Halcrow 
121237fead6SMichael Halcrow 	lower_file = ecryptfs_file_to_lower(file);
122237fead6SMichael Halcrow 	lower_file->f_pos = file->f_pos;
123bd243a4bSJosef "Jeff" Sipek 	inode = file->f_path.dentry->d_inode;
124237fead6SMichael Halcrow 	memset(&buf, 0, sizeof(buf));
125237fead6SMichael Halcrow 	buf.dirent = dirent;
126bd243a4bSJosef "Jeff" Sipek 	buf.dentry = file->f_path.dentry;
127237fead6SMichael Halcrow 	buf.filldir = filldir;
128237fead6SMichael Halcrow 	buf.filldir_called = 0;
129237fead6SMichael Halcrow 	buf.entries_written = 0;
130237fead6SMichael Halcrow 	rc = vfs_readdir(lower_file, ecryptfs_filldir, (void *)&buf);
131237fead6SMichael Halcrow 	file->f_pos = lower_file->f_pos;
1327d6c7045SMichael Halcrow 	if (rc < 0)
1337d6c7045SMichael Halcrow 		goto out;
1347d6c7045SMichael Halcrow 	if (buf.filldir_called && !buf.entries_written)
1357d6c7045SMichael Halcrow 		goto out;
136237fead6SMichael Halcrow 	if (rc >= 0)
1377d6c7045SMichael Halcrow 		fsstack_copy_attr_atime(inode,
1387d6c7045SMichael Halcrow 					lower_file->f_path.dentry->d_inode);
1397d6c7045SMichael Halcrow out:
140237fead6SMichael Halcrow 	return rc;
141237fead6SMichael Halcrow }
142237fead6SMichael Halcrow 
143237fead6SMichael Halcrow struct kmem_cache *ecryptfs_file_info_cache;
144237fead6SMichael Halcrow 
145237fead6SMichael Halcrow /**
146237fead6SMichael Halcrow  * ecryptfs_open
147237fead6SMichael Halcrow  * @inode: inode speciying file to open
148237fead6SMichael Halcrow  * @file: Structure to return filled in
149237fead6SMichael Halcrow  *
150237fead6SMichael Halcrow  * Opens the file specified by inode.
151237fead6SMichael Halcrow  *
152237fead6SMichael Halcrow  * Returns zero on success; non-zero otherwise
153237fead6SMichael Halcrow  */
154237fead6SMichael Halcrow static int ecryptfs_open(struct inode *inode, struct file *file)
155237fead6SMichael Halcrow {
156237fead6SMichael Halcrow 	int rc = 0;
157237fead6SMichael Halcrow 	struct ecryptfs_crypt_stat *crypt_stat = NULL;
158237fead6SMichael Halcrow 	struct ecryptfs_mount_crypt_stat *mount_crypt_stat;
159bd243a4bSJosef "Jeff" Sipek 	struct dentry *ecryptfs_dentry = file->f_path.dentry;
160237fead6SMichael Halcrow 	/* Private value of ecryptfs_dentry allocated in
161237fead6SMichael Halcrow 	 * ecryptfs_lookup() */
1624aa25bcbSJulia Lawall 	struct dentry *lower_dentry;
163237fead6SMichael Halcrow 	struct ecryptfs_file_info *file_info;
164237fead6SMichael Halcrow 
165e77a56ddSMichael Halcrow 	mount_crypt_stat = &ecryptfs_superblock_to_private(
166e77a56ddSMichael Halcrow 		ecryptfs_dentry->d_sb)->mount_crypt_stat;
167e77a56ddSMichael Halcrow 	if ((mount_crypt_stat->flags & ECRYPTFS_ENCRYPTED_VIEW_ENABLED)
168e77a56ddSMichael Halcrow 	    && ((file->f_flags & O_WRONLY) || (file->f_flags & O_RDWR)
169e77a56ddSMichael Halcrow 		|| (file->f_flags & O_CREAT) || (file->f_flags & O_TRUNC)
170e77a56ddSMichael Halcrow 		|| (file->f_flags & O_APPEND))) {
171e77a56ddSMichael Halcrow 		printk(KERN_WARNING "Mount has encrypted view enabled; "
172e77a56ddSMichael Halcrow 		       "files may only be read\n");
173e77a56ddSMichael Halcrow 		rc = -EPERM;
174e77a56ddSMichael Halcrow 		goto out;
175e77a56ddSMichael Halcrow 	}
176237fead6SMichael Halcrow 	/* Released in ecryptfs_release or end of function if failure */
177c3762229SRobert P. J. Day 	file_info = kmem_cache_zalloc(ecryptfs_file_info_cache, GFP_KERNEL);
178237fead6SMichael Halcrow 	ecryptfs_set_file_private(file, file_info);
179237fead6SMichael Halcrow 	if (!file_info) {
180237fead6SMichael Halcrow 		ecryptfs_printk(KERN_ERR,
181237fead6SMichael Halcrow 				"Error attempting to allocate memory\n");
182237fead6SMichael Halcrow 		rc = -ENOMEM;
183237fead6SMichael Halcrow 		goto out;
184237fead6SMichael Halcrow 	}
185237fead6SMichael Halcrow 	lower_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry);
186237fead6SMichael Halcrow 	crypt_stat = &ecryptfs_inode_to_private(inode)->crypt_stat;
187237fead6SMichael Halcrow 	mutex_lock(&crypt_stat->cs_mutex);
188e2bd99ecSMichael Halcrow 	if (!(crypt_stat->flags & ECRYPTFS_POLICY_APPLIED)) {
189237fead6SMichael Halcrow 		ecryptfs_printk(KERN_DEBUG, "Setting flags for stat...\n");
190237fead6SMichael Halcrow 		/* Policy code enabled in future release */
1912ed92554SMichael Halcrow 		crypt_stat->flags |= (ECRYPTFS_POLICY_APPLIED
1922ed92554SMichael Halcrow 				      | ECRYPTFS_ENCRYPTED);
193237fead6SMichael Halcrow 	}
194237fead6SMichael Halcrow 	mutex_unlock(&crypt_stat->cs_mutex);
19572b55fffSMichael Halcrow 	if (!ecryptfs_inode_to_private(inode)->lower_file) {
19672b55fffSMichael Halcrow 		rc = ecryptfs_init_persistent_file(ecryptfs_dentry);
19772b55fffSMichael Halcrow 		if (rc) {
19872b55fffSMichael Halcrow 			printk(KERN_ERR "%s: Error attempting to initialize "
19972b55fffSMichael Halcrow 			       "the persistent file for the dentry with name "
20072b55fffSMichael Halcrow 			       "[%s]; rc = [%d]\n", __func__,
20172b55fffSMichael Halcrow 			       ecryptfs_dentry->d_name.name, rc);
20272b55fffSMichael Halcrow 			goto out;
20372b55fffSMichael Halcrow 		}
20472b55fffSMichael Halcrow 	}
205e27759d7SErez Zadok 	if ((ecryptfs_inode_to_private(inode)->lower_file->f_flags & O_RDONLY)
206e27759d7SErez Zadok 	    && !(file->f_flags & O_RDONLY)) {
207e27759d7SErez Zadok 		rc = -EPERM;
208e27759d7SErez Zadok 		printk(KERN_WARNING "%s: Lower persistent file is RO; eCryptfs "
209e27759d7SErez Zadok 		       "file must hence be opened RO\n", __func__);
210e27759d7SErez Zadok 		goto out;
211e27759d7SErez Zadok 	}
2122ed92554SMichael Halcrow 	ecryptfs_set_file_lower(
2132ed92554SMichael Halcrow 		file, ecryptfs_inode_to_private(inode)->lower_file);
214237fead6SMichael Halcrow 	if (S_ISDIR(ecryptfs_dentry->d_inode->i_mode)) {
215237fead6SMichael Halcrow 		ecryptfs_printk(KERN_DEBUG, "This is a directory\n");
2162f9b12a3SMichael Halcrow 		mutex_lock(&crypt_stat->cs_mutex);
217e2bd99ecSMichael Halcrow 		crypt_stat->flags &= ~(ECRYPTFS_ENCRYPTED);
2182f9b12a3SMichael Halcrow 		mutex_unlock(&crypt_stat->cs_mutex);
219237fead6SMichael Halcrow 		rc = 0;
220237fead6SMichael Halcrow 		goto out;
221237fead6SMichael Halcrow 	}
222237fead6SMichael Halcrow 	mutex_lock(&crypt_stat->cs_mutex);
223e2bd99ecSMichael Halcrow 	if (!(crypt_stat->flags & ECRYPTFS_POLICY_APPLIED)
224e2bd99ecSMichael Halcrow 	    || !(crypt_stat->flags & ECRYPTFS_KEY_VALID)) {
225d7cdc5feSMichael Halcrow 		rc = ecryptfs_read_metadata(ecryptfs_dentry);
226237fead6SMichael Halcrow 		if (rc) {
227237fead6SMichael Halcrow 			ecryptfs_printk(KERN_DEBUG,
228237fead6SMichael Halcrow 					"Valid headers not found\n");
229237fead6SMichael Halcrow 			if (!(mount_crypt_stat->flags
230237fead6SMichael Halcrow 			      & ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED)) {
231237fead6SMichael Halcrow 				rc = -EIO;
23225bd8174SMichael Halcrow 				printk(KERN_WARNING "Either the lower file "
233237fead6SMichael Halcrow 				       "is not in a valid eCryptfs format, "
23425bd8174SMichael Halcrow 				       "or the key could not be retrieved. "
23525bd8174SMichael Halcrow 				       "Plaintext passthrough mode is not "
236237fead6SMichael Halcrow 				       "enabled; returning -EIO\n");
237237fead6SMichael Halcrow 				mutex_unlock(&crypt_stat->cs_mutex);
2382ed92554SMichael Halcrow 				goto out_free;
239237fead6SMichael Halcrow 			}
240237fead6SMichael Halcrow 			rc = 0;
241e2bd99ecSMichael Halcrow 			crypt_stat->flags &= ~(ECRYPTFS_ENCRYPTED);
242237fead6SMichael Halcrow 			mutex_unlock(&crypt_stat->cs_mutex);
243237fead6SMichael Halcrow 			goto out;
244237fead6SMichael Halcrow 		}
245237fead6SMichael Halcrow 	}
246237fead6SMichael Halcrow 	mutex_unlock(&crypt_stat->cs_mutex);
247237fead6SMichael Halcrow 	ecryptfs_printk(KERN_DEBUG, "inode w/ addr = [0x%p], i_ino = [0x%.16x] "
248237fead6SMichael Halcrow 			"size: [0x%.16x]\n", inode, inode->i_ino,
249237fead6SMichael Halcrow 			i_size_read(inode));
250237fead6SMichael Halcrow 	goto out;
2512ed92554SMichael Halcrow out_free:
252237fead6SMichael Halcrow 	kmem_cache_free(ecryptfs_file_info_cache,
253237fead6SMichael Halcrow 			ecryptfs_file_to_private(file));
254237fead6SMichael Halcrow out:
255237fead6SMichael Halcrow 	return rc;
256237fead6SMichael Halcrow }
257237fead6SMichael Halcrow 
258237fead6SMichael Halcrow static int ecryptfs_flush(struct file *file, fl_owner_t td)
259237fead6SMichael Halcrow {
260237fead6SMichael Halcrow 	int rc = 0;
261237fead6SMichael Halcrow 	struct file *lower_file = NULL;
262237fead6SMichael Halcrow 
263237fead6SMichael Halcrow 	lower_file = ecryptfs_file_to_lower(file);
264237fead6SMichael Halcrow 	if (lower_file->f_op && lower_file->f_op->flush)
265237fead6SMichael Halcrow 		rc = lower_file->f_op->flush(lower_file, td);
266237fead6SMichael Halcrow 	return rc;
267237fead6SMichael Halcrow }
268237fead6SMichael Halcrow 
269237fead6SMichael Halcrow static int ecryptfs_release(struct inode *inode, struct file *file)
270237fead6SMichael Halcrow {
2712ed92554SMichael Halcrow 	kmem_cache_free(ecryptfs_file_info_cache,
2722ed92554SMichael Halcrow 			ecryptfs_file_to_private(file));
2732ed92554SMichael Halcrow 	return 0;
274237fead6SMichael Halcrow }
275237fead6SMichael Halcrow 
276237fead6SMichael Halcrow static int
277237fead6SMichael Halcrow ecryptfs_fsync(struct file *file, struct dentry *dentry, int datasync)
278237fead6SMichael Halcrow {
2794c728ef5SChristoph Hellwig 	return vfs_fsync(ecryptfs_file_to_lower(file),
2804c728ef5SChristoph Hellwig 			 ecryptfs_dentry_to_lower(dentry),
281237fead6SMichael Halcrow 			 datasync);
282237fead6SMichael Halcrow }
283237fead6SMichael Halcrow 
284237fead6SMichael Halcrow static int ecryptfs_fasync(int fd, struct file *file, int flag)
285237fead6SMichael Halcrow {
286237fead6SMichael Halcrow 	int rc = 0;
287237fead6SMichael Halcrow 	struct file *lower_file = NULL;
288237fead6SMichael Halcrow 
289dda6445eSJonathan Corbet 	lock_kernel();
290237fead6SMichael Halcrow 	lower_file = ecryptfs_file_to_lower(file);
291237fead6SMichael Halcrow 	if (lower_file->f_op && lower_file->f_op->fasync)
292237fead6SMichael Halcrow 		rc = lower_file->f_op->fasync(fd, lower_file, flag);
293dda6445eSJonathan Corbet 	unlock_kernel();
294237fead6SMichael Halcrow 	return rc;
295237fead6SMichael Halcrow }
296237fead6SMichael Halcrow 
297237fead6SMichael Halcrow static int ecryptfs_ioctl(struct inode *inode, struct file *file,
298237fead6SMichael Halcrow 			  unsigned int cmd, unsigned long arg);
299237fead6SMichael Halcrow 
300237fead6SMichael Halcrow const struct file_operations ecryptfs_dir_fops = {
301237fead6SMichael Halcrow 	.readdir = ecryptfs_readdir,
302237fead6SMichael Halcrow 	.ioctl = ecryptfs_ioctl,
303237fead6SMichael Halcrow 	.open = ecryptfs_open,
304237fead6SMichael Halcrow 	.flush = ecryptfs_flush,
305237fead6SMichael Halcrow 	.release = ecryptfs_release,
306237fead6SMichael Halcrow 	.fsync = ecryptfs_fsync,
307237fead6SMichael Halcrow 	.fasync = ecryptfs_fasync,
308e9f6a99cSMichael Halcrow 	.splice_read = generic_file_splice_read,
309237fead6SMichael Halcrow };
310237fead6SMichael Halcrow 
311237fead6SMichael Halcrow const struct file_operations ecryptfs_main_fops = {
31253a2731fSMichael Halcrow 	.llseek = generic_file_llseek,
313237fead6SMichael Halcrow 	.read = do_sync_read,
314237fead6SMichael Halcrow 	.aio_read = ecryptfs_read_update_atime,
315237fead6SMichael Halcrow 	.write = do_sync_write,
316237fead6SMichael Halcrow 	.aio_write = generic_file_aio_write,
317237fead6SMichael Halcrow 	.readdir = ecryptfs_readdir,
318237fead6SMichael Halcrow 	.ioctl = ecryptfs_ioctl,
319237fead6SMichael Halcrow 	.mmap = generic_file_mmap,
320237fead6SMichael Halcrow 	.open = ecryptfs_open,
321237fead6SMichael Halcrow 	.flush = ecryptfs_flush,
322237fead6SMichael Halcrow 	.release = ecryptfs_release,
323237fead6SMichael Halcrow 	.fsync = ecryptfs_fsync,
324237fead6SMichael Halcrow 	.fasync = ecryptfs_fasync,
325e9f6a99cSMichael Halcrow 	.splice_read = generic_file_splice_read,
326237fead6SMichael Halcrow };
327237fead6SMichael Halcrow 
328237fead6SMichael Halcrow static int
329237fead6SMichael Halcrow ecryptfs_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
330237fead6SMichael Halcrow 	       unsigned long arg)
331237fead6SMichael Halcrow {
332237fead6SMichael Halcrow 	int rc = 0;
333237fead6SMichael Halcrow 	struct file *lower_file = NULL;
334237fead6SMichael Halcrow 
335237fead6SMichael Halcrow 	if (ecryptfs_file_to_private(file))
336237fead6SMichael Halcrow 		lower_file = ecryptfs_file_to_lower(file);
337237fead6SMichael Halcrow 	if (lower_file && lower_file->f_op && lower_file->f_op->ioctl)
338237fead6SMichael Halcrow 		rc = lower_file->f_op->ioctl(ecryptfs_inode_to_lower(inode),
339237fead6SMichael Halcrow 					     lower_file, cmd, arg);
340237fead6SMichael Halcrow 	else
341237fead6SMichael Halcrow 		rc = -ENOTTY;
342237fead6SMichael Halcrow 	return rc;
343237fead6SMichael Halcrow }
344