138c8a9a5SSteve French // SPDX-License-Identifier: LGPL-2.1 238c8a9a5SSteve French /* 338c8a9a5SSteve French * 438c8a9a5SSteve French * vfs operations that deal with io control 538c8a9a5SSteve French * 638c8a9a5SSteve French * Copyright (C) International Business Machines Corp., 2005,2013 738c8a9a5SSteve French * Author(s): Steve French (sfrench@us.ibm.com) 838c8a9a5SSteve French * 938c8a9a5SSteve French */ 1038c8a9a5SSteve French 1138c8a9a5SSteve French #include <linux/fs.h> 1238c8a9a5SSteve French #include <linux/file.h> 1338c8a9a5SSteve French #include <linux/mount.h> 1438c8a9a5SSteve French #include <linux/mm.h> 1538c8a9a5SSteve French #include <linux/pagemap.h> 1638c8a9a5SSteve French #include "cifspdu.h" 1738c8a9a5SSteve French #include "cifsglob.h" 1838c8a9a5SSteve French #include "cifsproto.h" 1938c8a9a5SSteve French #include "cifs_debug.h" 2038c8a9a5SSteve French #include "cifsfs.h" 2138c8a9a5SSteve French #include "cifs_ioctl.h" 2238c8a9a5SSteve French #include "smb2proto.h" 2338c8a9a5SSteve French #include "smb2glob.h" 2438c8a9a5SSteve French #include <linux/btrfs.h> 2538c8a9a5SSteve French 2638c8a9a5SSteve French static long cifs_ioctl_query_info(unsigned int xid, struct file *filep, 2738c8a9a5SSteve French unsigned long p) 2838c8a9a5SSteve French { 2938c8a9a5SSteve French struct inode *inode = file_inode(filep); 3038c8a9a5SSteve French struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); 3138c8a9a5SSteve French struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb); 3238c8a9a5SSteve French struct dentry *dentry = filep->f_path.dentry; 3338c8a9a5SSteve French const unsigned char *path; 3438c8a9a5SSteve French void *page = alloc_dentry_path(); 3538c8a9a5SSteve French __le16 *utf16_path = NULL, root_path; 3638c8a9a5SSteve French int rc = 0; 3738c8a9a5SSteve French 3838c8a9a5SSteve French path = build_path_from_dentry(dentry, page); 3938c8a9a5SSteve French if (IS_ERR(path)) { 4038c8a9a5SSteve French free_dentry_path(page); 4138c8a9a5SSteve French return PTR_ERR(path); 4238c8a9a5SSteve French } 4338c8a9a5SSteve French 4438c8a9a5SSteve French cifs_dbg(FYI, "%s %s\n", __func__, path); 4538c8a9a5SSteve French 4638c8a9a5SSteve French if (!path[0]) { 4738c8a9a5SSteve French root_path = 0; 4838c8a9a5SSteve French utf16_path = &root_path; 4938c8a9a5SSteve French } else { 5038c8a9a5SSteve French utf16_path = cifs_convert_path_to_utf16(path + 1, cifs_sb); 5138c8a9a5SSteve French if (!utf16_path) { 5238c8a9a5SSteve French rc = -ENOMEM; 5338c8a9a5SSteve French goto ici_exit; 5438c8a9a5SSteve French } 5538c8a9a5SSteve French } 5638c8a9a5SSteve French 5738c8a9a5SSteve French if (tcon->ses->server->ops->ioctl_query_info) 5838c8a9a5SSteve French rc = tcon->ses->server->ops->ioctl_query_info( 5938c8a9a5SSteve French xid, tcon, cifs_sb, utf16_path, 6038c8a9a5SSteve French filep->private_data ? 0 : 1, p); 6138c8a9a5SSteve French else 6238c8a9a5SSteve French rc = -EOPNOTSUPP; 6338c8a9a5SSteve French 6438c8a9a5SSteve French ici_exit: 6538c8a9a5SSteve French if (utf16_path != &root_path) 6638c8a9a5SSteve French kfree(utf16_path); 6738c8a9a5SSteve French free_dentry_path(page); 6838c8a9a5SSteve French return rc; 6938c8a9a5SSteve French } 7038c8a9a5SSteve French 7138c8a9a5SSteve French static long cifs_ioctl_copychunk(unsigned int xid, struct file *dst_file, 7238c8a9a5SSteve French unsigned long srcfd) 7338c8a9a5SSteve French { 7438c8a9a5SSteve French int rc; 7538c8a9a5SSteve French struct fd src_file; 7638c8a9a5SSteve French struct inode *src_inode; 7738c8a9a5SSteve French 7838c8a9a5SSteve French cifs_dbg(FYI, "ioctl copychunk range\n"); 7938c8a9a5SSteve French /* the destination must be opened for writing */ 8038c8a9a5SSteve French if (!(dst_file->f_mode & FMODE_WRITE)) { 8138c8a9a5SSteve French cifs_dbg(FYI, "file target not open for write\n"); 8238c8a9a5SSteve French return -EINVAL; 8338c8a9a5SSteve French } 8438c8a9a5SSteve French 8538c8a9a5SSteve French /* check if target volume is readonly and take reference */ 8638c8a9a5SSteve French rc = mnt_want_write_file(dst_file); 8738c8a9a5SSteve French if (rc) { 8838c8a9a5SSteve French cifs_dbg(FYI, "mnt_want_write failed with rc %d\n", rc); 8938c8a9a5SSteve French return rc; 9038c8a9a5SSteve French } 9138c8a9a5SSteve French 9238c8a9a5SSteve French src_file = fdget(srcfd); 9338c8a9a5SSteve French if (!src_file.file) { 9438c8a9a5SSteve French rc = -EBADF; 9538c8a9a5SSteve French goto out_drop_write; 9638c8a9a5SSteve French } 9738c8a9a5SSteve French 9838c8a9a5SSteve French if (src_file.file->f_op->unlocked_ioctl != cifs_ioctl) { 9938c8a9a5SSteve French rc = -EBADF; 10038c8a9a5SSteve French cifs_dbg(VFS, "src file seems to be from a different filesystem type\n"); 10138c8a9a5SSteve French goto out_fput; 10238c8a9a5SSteve French } 10338c8a9a5SSteve French 10438c8a9a5SSteve French src_inode = file_inode(src_file.file); 10538c8a9a5SSteve French rc = -EINVAL; 10638c8a9a5SSteve French if (S_ISDIR(src_inode->i_mode)) 10738c8a9a5SSteve French goto out_fput; 10838c8a9a5SSteve French 10938c8a9a5SSteve French rc = cifs_file_copychunk_range(xid, src_file.file, 0, dst_file, 0, 11038c8a9a5SSteve French src_inode->i_size, 0); 11138c8a9a5SSteve French if (rc > 0) 11238c8a9a5SSteve French rc = 0; 11338c8a9a5SSteve French out_fput: 11438c8a9a5SSteve French fdput(src_file); 11538c8a9a5SSteve French out_drop_write: 11638c8a9a5SSteve French mnt_drop_write_file(dst_file); 11738c8a9a5SSteve French return rc; 11838c8a9a5SSteve French } 11938c8a9a5SSteve French 12038c8a9a5SSteve French static long smb_mnt_get_fsinfo(unsigned int xid, struct cifs_tcon *tcon, 12138c8a9a5SSteve French void __user *arg) 12238c8a9a5SSteve French { 12338c8a9a5SSteve French int rc = 0; 12438c8a9a5SSteve French struct smb_mnt_fs_info *fsinf; 12538c8a9a5SSteve French 12638c8a9a5SSteve French fsinf = kzalloc(sizeof(struct smb_mnt_fs_info), GFP_KERNEL); 12738c8a9a5SSteve French if (fsinf == NULL) 12838c8a9a5SSteve French return -ENOMEM; 12938c8a9a5SSteve French 13038c8a9a5SSteve French fsinf->version = 1; 13138c8a9a5SSteve French fsinf->protocol_id = tcon->ses->server->vals->protocol_id; 13238c8a9a5SSteve French fsinf->device_characteristics = 13338c8a9a5SSteve French le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics); 13438c8a9a5SSteve French fsinf->device_type = le32_to_cpu(tcon->fsDevInfo.DeviceType); 13538c8a9a5SSteve French fsinf->fs_attributes = le32_to_cpu(tcon->fsAttrInfo.Attributes); 13638c8a9a5SSteve French fsinf->max_path_component = 13738c8a9a5SSteve French le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength); 13838c8a9a5SSteve French fsinf->vol_serial_number = tcon->vol_serial_number; 13938c8a9a5SSteve French fsinf->vol_create_time = le64_to_cpu(tcon->vol_create_time); 14038c8a9a5SSteve French fsinf->share_flags = tcon->share_flags; 14138c8a9a5SSteve French fsinf->share_caps = le32_to_cpu(tcon->capabilities); 14238c8a9a5SSteve French fsinf->sector_flags = tcon->ss_flags; 14338c8a9a5SSteve French fsinf->optimal_sector_size = tcon->perf_sector_size; 14438c8a9a5SSteve French fsinf->max_bytes_chunk = tcon->max_bytes_chunk; 14538c8a9a5SSteve French fsinf->maximal_access = tcon->maximal_access; 14638c8a9a5SSteve French fsinf->cifs_posix_caps = le64_to_cpu(tcon->fsUnixInfo.Capability); 14738c8a9a5SSteve French 14838c8a9a5SSteve French if (copy_to_user(arg, fsinf, sizeof(struct smb_mnt_fs_info))) 14938c8a9a5SSteve French rc = -EFAULT; 15038c8a9a5SSteve French 15138c8a9a5SSteve French kfree(fsinf); 15238c8a9a5SSteve French return rc; 15338c8a9a5SSteve French } 15438c8a9a5SSteve French 15538c8a9a5SSteve French static int cifs_shutdown(struct super_block *sb, unsigned long arg) 15638c8a9a5SSteve French { 15738c8a9a5SSteve French struct cifs_sb_info *sbi = CIFS_SB(sb); 15838c8a9a5SSteve French __u32 flags; 15938c8a9a5SSteve French 16038c8a9a5SSteve French if (!capable(CAP_SYS_ADMIN)) 16138c8a9a5SSteve French return -EPERM; 16238c8a9a5SSteve French 16338c8a9a5SSteve French if (get_user(flags, (__u32 __user *)arg)) 16438c8a9a5SSteve French return -EFAULT; 16538c8a9a5SSteve French 16638c8a9a5SSteve French if (flags > CIFS_GOING_FLAGS_NOLOGFLUSH) 16738c8a9a5SSteve French return -EINVAL; 16838c8a9a5SSteve French 16938c8a9a5SSteve French if (cifs_forced_shutdown(sbi)) 17038c8a9a5SSteve French return 0; 17138c8a9a5SSteve French 17238c8a9a5SSteve French cifs_dbg(VFS, "shut down requested (%d)", flags); 17338c8a9a5SSteve French /* trace_cifs_shutdown(sb, flags);*/ 17438c8a9a5SSteve French 17538c8a9a5SSteve French /* 17638c8a9a5SSteve French * see: 17738c8a9a5SSteve French * https://man7.org/linux/man-pages/man2/ioctl_xfs_goingdown.2.html 17838c8a9a5SSteve French * for more information and description of original intent of the flags 17938c8a9a5SSteve French */ 18038c8a9a5SSteve French switch (flags) { 18138c8a9a5SSteve French /* 18238c8a9a5SSteve French * We could add support later for default flag which requires: 18338c8a9a5SSteve French * "Flush all dirty data and metadata to disk" 18438c8a9a5SSteve French * would need to call syncfs or equivalent to flush page cache for 18538c8a9a5SSteve French * the mount and then issue fsync to server (if nostrictsync not set) 18638c8a9a5SSteve French */ 18738c8a9a5SSteve French case CIFS_GOING_FLAGS_DEFAULT: 18838c8a9a5SSteve French cifs_dbg(FYI, "shutdown with default flag not supported\n"); 18938c8a9a5SSteve French return -EINVAL; 19038c8a9a5SSteve French /* 19138c8a9a5SSteve French * FLAGS_LOGFLUSH is easy since it asks to write out metadata (not 19238c8a9a5SSteve French * data) but metadata writes are not cached on the client, so can treat 19338c8a9a5SSteve French * it similarly to NOLOGFLUSH 19438c8a9a5SSteve French */ 19538c8a9a5SSteve French case CIFS_GOING_FLAGS_LOGFLUSH: 19638c8a9a5SSteve French case CIFS_GOING_FLAGS_NOLOGFLUSH: 19738c8a9a5SSteve French sbi->mnt_cifs_flags |= CIFS_MOUNT_SHUTDOWN; 19838c8a9a5SSteve French return 0; 19938c8a9a5SSteve French default: 20038c8a9a5SSteve French return -EINVAL; 20138c8a9a5SSteve French } 20238c8a9a5SSteve French return 0; 20338c8a9a5SSteve French } 20438c8a9a5SSteve French 20538c8a9a5SSteve French static int cifs_dump_full_key(struct cifs_tcon *tcon, struct smb3_full_key_debug_info __user *in) 20638c8a9a5SSteve French { 20738c8a9a5SSteve French struct smb3_full_key_debug_info out; 20838c8a9a5SSteve French struct cifs_ses *ses; 20938c8a9a5SSteve French int rc = 0; 21038c8a9a5SSteve French bool found = false; 21138c8a9a5SSteve French u8 __user *end; 21238c8a9a5SSteve French 21338c8a9a5SSteve French if (!smb3_encryption_required(tcon)) { 21438c8a9a5SSteve French rc = -EOPNOTSUPP; 21538c8a9a5SSteve French goto out; 21638c8a9a5SSteve French } 21738c8a9a5SSteve French 21838c8a9a5SSteve French /* copy user input into our output buffer */ 21938c8a9a5SSteve French if (copy_from_user(&out, in, sizeof(out))) { 22038c8a9a5SSteve French rc = -EINVAL; 22138c8a9a5SSteve French goto out; 22238c8a9a5SSteve French } 22338c8a9a5SSteve French 22438c8a9a5SSteve French if (!out.session_id) { 22538c8a9a5SSteve French /* if ses id is 0, use current user session */ 22638c8a9a5SSteve French ses = tcon->ses; 22738c8a9a5SSteve French } else { 22838c8a9a5SSteve French /* otherwise if a session id is given, look for it in all our sessions */ 22938c8a9a5SSteve French struct cifs_ses *ses_it = NULL; 23038c8a9a5SSteve French struct TCP_Server_Info *server_it = NULL; 23138c8a9a5SSteve French 23238c8a9a5SSteve French spin_lock(&cifs_tcp_ses_lock); 23338c8a9a5SSteve French list_for_each_entry(server_it, &cifs_tcp_ses_list, tcp_ses_list) { 23438c8a9a5SSteve French list_for_each_entry(ses_it, &server_it->smb_ses_list, smb_ses_list) { 23538c8a9a5SSteve French if (ses_it->Suid == out.session_id) { 23638c8a9a5SSteve French ses = ses_it; 23738c8a9a5SSteve French /* 23838c8a9a5SSteve French * since we are using the session outside the crit 23938c8a9a5SSteve French * section, we need to make sure it won't be released 24038c8a9a5SSteve French * so increment its refcount 24138c8a9a5SSteve French */ 24238c8a9a5SSteve French cifs_smb_ses_inc_refcount(ses); 24338c8a9a5SSteve French found = true; 24438c8a9a5SSteve French goto search_end; 24538c8a9a5SSteve French } 24638c8a9a5SSteve French } 24738c8a9a5SSteve French } 24838c8a9a5SSteve French search_end: 24938c8a9a5SSteve French spin_unlock(&cifs_tcp_ses_lock); 25038c8a9a5SSteve French if (!found) { 25138c8a9a5SSteve French rc = -ENOENT; 25238c8a9a5SSteve French goto out; 25338c8a9a5SSteve French } 25438c8a9a5SSteve French } 25538c8a9a5SSteve French 25638c8a9a5SSteve French switch (ses->server->cipher_type) { 25738c8a9a5SSteve French case SMB2_ENCRYPTION_AES128_CCM: 25838c8a9a5SSteve French case SMB2_ENCRYPTION_AES128_GCM: 25938c8a9a5SSteve French out.session_key_length = CIFS_SESS_KEY_SIZE; 26038c8a9a5SSteve French out.server_in_key_length = out.server_out_key_length = SMB3_GCM128_CRYPTKEY_SIZE; 26138c8a9a5SSteve French break; 26238c8a9a5SSteve French case SMB2_ENCRYPTION_AES256_CCM: 26338c8a9a5SSteve French case SMB2_ENCRYPTION_AES256_GCM: 26438c8a9a5SSteve French out.session_key_length = CIFS_SESS_KEY_SIZE; 26538c8a9a5SSteve French out.server_in_key_length = out.server_out_key_length = SMB3_GCM256_CRYPTKEY_SIZE; 26638c8a9a5SSteve French break; 26738c8a9a5SSteve French default: 26838c8a9a5SSteve French rc = -EOPNOTSUPP; 26938c8a9a5SSteve French goto out; 27038c8a9a5SSteve French } 27138c8a9a5SSteve French 27238c8a9a5SSteve French /* check if user buffer is big enough to store all the keys */ 27338c8a9a5SSteve French if (out.in_size < sizeof(out) + out.session_key_length + out.server_in_key_length 27438c8a9a5SSteve French + out.server_out_key_length) { 27538c8a9a5SSteve French rc = -ENOBUFS; 27638c8a9a5SSteve French goto out; 27738c8a9a5SSteve French } 27838c8a9a5SSteve French 27938c8a9a5SSteve French out.session_id = ses->Suid; 28038c8a9a5SSteve French out.cipher_type = le16_to_cpu(ses->server->cipher_type); 28138c8a9a5SSteve French 28238c8a9a5SSteve French /* overwrite user input with our output */ 28338c8a9a5SSteve French if (copy_to_user(in, &out, sizeof(out))) { 28438c8a9a5SSteve French rc = -EINVAL; 28538c8a9a5SSteve French goto out; 28638c8a9a5SSteve French } 28738c8a9a5SSteve French 28838c8a9a5SSteve French /* append all the keys at the end of the user buffer */ 28938c8a9a5SSteve French end = in->data; 29038c8a9a5SSteve French if (copy_to_user(end, ses->auth_key.response, out.session_key_length)) { 29138c8a9a5SSteve French rc = -EINVAL; 29238c8a9a5SSteve French goto out; 29338c8a9a5SSteve French } 29438c8a9a5SSteve French end += out.session_key_length; 29538c8a9a5SSteve French 29638c8a9a5SSteve French if (copy_to_user(end, ses->smb3encryptionkey, out.server_in_key_length)) { 29738c8a9a5SSteve French rc = -EINVAL; 29838c8a9a5SSteve French goto out; 29938c8a9a5SSteve French } 30038c8a9a5SSteve French end += out.server_in_key_length; 30138c8a9a5SSteve French 30238c8a9a5SSteve French if (copy_to_user(end, ses->smb3decryptionkey, out.server_out_key_length)) { 30338c8a9a5SSteve French rc = -EINVAL; 30438c8a9a5SSteve French goto out; 30538c8a9a5SSteve French } 30638c8a9a5SSteve French 30738c8a9a5SSteve French out: 30838c8a9a5SSteve French if (found) 30938c8a9a5SSteve French cifs_put_smb_ses(ses); 31038c8a9a5SSteve French return rc; 31138c8a9a5SSteve French } 31238c8a9a5SSteve French 31338c8a9a5SSteve French long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg) 31438c8a9a5SSteve French { 31538c8a9a5SSteve French struct inode *inode = file_inode(filep); 31638c8a9a5SSteve French struct smb3_key_debug_info pkey_inf; 31738c8a9a5SSteve French int rc = -ENOTTY; /* strange error - but the precedent */ 31838c8a9a5SSteve French unsigned int xid; 31938c8a9a5SSteve French struct cifsFileInfo *pSMBFile = filep->private_data; 32038c8a9a5SSteve French struct cifs_tcon *tcon; 32138c8a9a5SSteve French struct tcon_link *tlink; 32238c8a9a5SSteve French struct cifs_sb_info *cifs_sb; 32338c8a9a5SSteve French __u64 ExtAttrBits = 0; 324*fdd7d1ffSSteve French #ifdef CONFIG_CIFS_POSIX 325*fdd7d1ffSSteve French #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY 32638c8a9a5SSteve French __u64 caps; 327*fdd7d1ffSSteve French #endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */ 328*fdd7d1ffSSteve French #endif /* CONFIG_CIFS_POSIX */ 32938c8a9a5SSteve French 33038c8a9a5SSteve French xid = get_xid(); 33138c8a9a5SSteve French 33238c8a9a5SSteve French cifs_dbg(FYI, "cifs ioctl 0x%x\n", command); 33338c8a9a5SSteve French switch (command) { 33438c8a9a5SSteve French case FS_IOC_GETFLAGS: 33538c8a9a5SSteve French if (pSMBFile == NULL) 33638c8a9a5SSteve French break; 33738c8a9a5SSteve French tcon = tlink_tcon(pSMBFile->tlink); 33838c8a9a5SSteve French #ifdef CONFIG_CIFS_POSIX 33938c8a9a5SSteve French #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY 340*fdd7d1ffSSteve French caps = le64_to_cpu(tcon->fsUnixInfo.Capability); 34138c8a9a5SSteve French if (CIFS_UNIX_EXTATTR_CAP & caps) { 34238c8a9a5SSteve French __u64 ExtAttrMask = 0; 34338c8a9a5SSteve French rc = CIFSGetExtAttr(xid, tcon, 34438c8a9a5SSteve French pSMBFile->fid.netfid, 34538c8a9a5SSteve French &ExtAttrBits, &ExtAttrMask); 34638c8a9a5SSteve French if (rc == 0) 34738c8a9a5SSteve French rc = put_user(ExtAttrBits & 34838c8a9a5SSteve French FS_FL_USER_VISIBLE, 34938c8a9a5SSteve French (int __user *)arg); 35038c8a9a5SSteve French if (rc != -EOPNOTSUPP) 35138c8a9a5SSteve French break; 35238c8a9a5SSteve French } 35338c8a9a5SSteve French #endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */ 35438c8a9a5SSteve French #endif /* CONFIG_CIFS_POSIX */ 35538c8a9a5SSteve French rc = 0; 35638c8a9a5SSteve French if (CIFS_I(inode)->cifsAttrs & ATTR_COMPRESSED) { 35738c8a9a5SSteve French /* add in the compressed bit */ 35838c8a9a5SSteve French ExtAttrBits = FS_COMPR_FL; 35938c8a9a5SSteve French rc = put_user(ExtAttrBits & FS_FL_USER_VISIBLE, 36038c8a9a5SSteve French (int __user *)arg); 36138c8a9a5SSteve French } 36238c8a9a5SSteve French break; 36338c8a9a5SSteve French case FS_IOC_SETFLAGS: 36438c8a9a5SSteve French if (pSMBFile == NULL) 36538c8a9a5SSteve French break; 36638c8a9a5SSteve French tcon = tlink_tcon(pSMBFile->tlink); 36738c8a9a5SSteve French /* caps = le64_to_cpu(tcon->fsUnixInfo.Capability); */ 36838c8a9a5SSteve French 36938c8a9a5SSteve French if (get_user(ExtAttrBits, (int __user *)arg)) { 37038c8a9a5SSteve French rc = -EFAULT; 37138c8a9a5SSteve French break; 37238c8a9a5SSteve French } 37338c8a9a5SSteve French 37438c8a9a5SSteve French /* 37538c8a9a5SSteve French * if (CIFS_UNIX_EXTATTR_CAP & caps) 37638c8a9a5SSteve French * rc = CIFSSetExtAttr(xid, tcon, 37738c8a9a5SSteve French * pSMBFile->fid.netfid, 37838c8a9a5SSteve French * extAttrBits, 37938c8a9a5SSteve French * &ExtAttrMask); 38038c8a9a5SSteve French * if (rc != -EOPNOTSUPP) 38138c8a9a5SSteve French * break; 38238c8a9a5SSteve French */ 38338c8a9a5SSteve French 38438c8a9a5SSteve French /* Currently only flag we can set is compressed flag */ 38538c8a9a5SSteve French if ((ExtAttrBits & FS_COMPR_FL) == 0) 38638c8a9a5SSteve French break; 38738c8a9a5SSteve French 38838c8a9a5SSteve French /* Try to set compress flag */ 38938c8a9a5SSteve French if (tcon->ses->server->ops->set_compression) { 39038c8a9a5SSteve French rc = tcon->ses->server->ops->set_compression( 39138c8a9a5SSteve French xid, tcon, pSMBFile); 39238c8a9a5SSteve French cifs_dbg(FYI, "set compress flag rc %d\n", rc); 39338c8a9a5SSteve French } 39438c8a9a5SSteve French break; 39538c8a9a5SSteve French case CIFS_IOC_COPYCHUNK_FILE: 39638c8a9a5SSteve French rc = cifs_ioctl_copychunk(xid, filep, arg); 39738c8a9a5SSteve French break; 39838c8a9a5SSteve French case CIFS_QUERY_INFO: 39938c8a9a5SSteve French rc = cifs_ioctl_query_info(xid, filep, arg); 40038c8a9a5SSteve French break; 40138c8a9a5SSteve French case CIFS_IOC_SET_INTEGRITY: 40238c8a9a5SSteve French if (pSMBFile == NULL) 40338c8a9a5SSteve French break; 40438c8a9a5SSteve French tcon = tlink_tcon(pSMBFile->tlink); 40538c8a9a5SSteve French if (tcon->ses->server->ops->set_integrity) 40638c8a9a5SSteve French rc = tcon->ses->server->ops->set_integrity(xid, 40738c8a9a5SSteve French tcon, pSMBFile); 40838c8a9a5SSteve French else 40938c8a9a5SSteve French rc = -EOPNOTSUPP; 41038c8a9a5SSteve French break; 41138c8a9a5SSteve French case CIFS_IOC_GET_MNT_INFO: 41238c8a9a5SSteve French if (pSMBFile == NULL) 41338c8a9a5SSteve French break; 41438c8a9a5SSteve French tcon = tlink_tcon(pSMBFile->tlink); 41538c8a9a5SSteve French rc = smb_mnt_get_fsinfo(xid, tcon, (void __user *)arg); 41638c8a9a5SSteve French break; 41738c8a9a5SSteve French case CIFS_ENUMERATE_SNAPSHOTS: 41838c8a9a5SSteve French if (pSMBFile == NULL) 41938c8a9a5SSteve French break; 42038c8a9a5SSteve French if (arg == 0) { 42138c8a9a5SSteve French rc = -EINVAL; 42238c8a9a5SSteve French goto cifs_ioc_exit; 42338c8a9a5SSteve French } 42438c8a9a5SSteve French tcon = tlink_tcon(pSMBFile->tlink); 42538c8a9a5SSteve French if (tcon->ses->server->ops->enum_snapshots) 42638c8a9a5SSteve French rc = tcon->ses->server->ops->enum_snapshots(xid, tcon, 42738c8a9a5SSteve French pSMBFile, (void __user *)arg); 42838c8a9a5SSteve French else 42938c8a9a5SSteve French rc = -EOPNOTSUPP; 43038c8a9a5SSteve French break; 43138c8a9a5SSteve French case CIFS_DUMP_KEY: 43238c8a9a5SSteve French /* 43338c8a9a5SSteve French * Dump encryption keys. This is an old ioctl that only 43438c8a9a5SSteve French * handles AES-128-{CCM,GCM}. 43538c8a9a5SSteve French */ 43638c8a9a5SSteve French if (pSMBFile == NULL) 43738c8a9a5SSteve French break; 43838c8a9a5SSteve French if (!capable(CAP_SYS_ADMIN)) { 43938c8a9a5SSteve French rc = -EACCES; 44038c8a9a5SSteve French break; 44138c8a9a5SSteve French } 44238c8a9a5SSteve French 44338c8a9a5SSteve French tcon = tlink_tcon(pSMBFile->tlink); 44438c8a9a5SSteve French if (!smb3_encryption_required(tcon)) { 44538c8a9a5SSteve French rc = -EOPNOTSUPP; 44638c8a9a5SSteve French break; 44738c8a9a5SSteve French } 44838c8a9a5SSteve French pkey_inf.cipher_type = 44938c8a9a5SSteve French le16_to_cpu(tcon->ses->server->cipher_type); 45038c8a9a5SSteve French pkey_inf.Suid = tcon->ses->Suid; 45138c8a9a5SSteve French memcpy(pkey_inf.auth_key, tcon->ses->auth_key.response, 45238c8a9a5SSteve French 16 /* SMB2_NTLMV2_SESSKEY_SIZE */); 45338c8a9a5SSteve French memcpy(pkey_inf.smb3decryptionkey, 45438c8a9a5SSteve French tcon->ses->smb3decryptionkey, SMB3_SIGN_KEY_SIZE); 45538c8a9a5SSteve French memcpy(pkey_inf.smb3encryptionkey, 45638c8a9a5SSteve French tcon->ses->smb3encryptionkey, SMB3_SIGN_KEY_SIZE); 45738c8a9a5SSteve French if (copy_to_user((void __user *)arg, &pkey_inf, 45838c8a9a5SSteve French sizeof(struct smb3_key_debug_info))) 45938c8a9a5SSteve French rc = -EFAULT; 46038c8a9a5SSteve French else 46138c8a9a5SSteve French rc = 0; 46238c8a9a5SSteve French break; 46338c8a9a5SSteve French case CIFS_DUMP_FULL_KEY: 46438c8a9a5SSteve French /* 46538c8a9a5SSteve French * Dump encryption keys (handles any key sizes) 46638c8a9a5SSteve French */ 46738c8a9a5SSteve French if (pSMBFile == NULL) 46838c8a9a5SSteve French break; 46938c8a9a5SSteve French if (!capable(CAP_SYS_ADMIN)) { 47038c8a9a5SSteve French rc = -EACCES; 47138c8a9a5SSteve French break; 47238c8a9a5SSteve French } 47338c8a9a5SSteve French tcon = tlink_tcon(pSMBFile->tlink); 47438c8a9a5SSteve French rc = cifs_dump_full_key(tcon, (void __user *)arg); 47538c8a9a5SSteve French break; 47638c8a9a5SSteve French case CIFS_IOC_NOTIFY: 47738c8a9a5SSteve French if (!S_ISDIR(inode->i_mode)) { 47838c8a9a5SSteve French /* Notify can only be done on directories */ 47938c8a9a5SSteve French rc = -EOPNOTSUPP; 48038c8a9a5SSteve French break; 48138c8a9a5SSteve French } 48238c8a9a5SSteve French cifs_sb = CIFS_SB(inode->i_sb); 48338c8a9a5SSteve French tlink = cifs_sb_tlink(cifs_sb); 48438c8a9a5SSteve French if (IS_ERR(tlink)) { 48538c8a9a5SSteve French rc = PTR_ERR(tlink); 48638c8a9a5SSteve French break; 48738c8a9a5SSteve French } 48838c8a9a5SSteve French tcon = tlink_tcon(tlink); 48938c8a9a5SSteve French if (tcon && tcon->ses->server->ops->notify) { 49038c8a9a5SSteve French rc = tcon->ses->server->ops->notify(xid, 49138c8a9a5SSteve French filep, (void __user *)arg, 49238c8a9a5SSteve French false /* no ret data */); 49338c8a9a5SSteve French cifs_dbg(FYI, "ioctl notify rc %d\n", rc); 49438c8a9a5SSteve French } else 49538c8a9a5SSteve French rc = -EOPNOTSUPP; 49638c8a9a5SSteve French cifs_put_tlink(tlink); 49738c8a9a5SSteve French break; 49838c8a9a5SSteve French case CIFS_IOC_NOTIFY_INFO: 49938c8a9a5SSteve French if (!S_ISDIR(inode->i_mode)) { 50038c8a9a5SSteve French /* Notify can only be done on directories */ 50138c8a9a5SSteve French rc = -EOPNOTSUPP; 50238c8a9a5SSteve French break; 50338c8a9a5SSteve French } 50438c8a9a5SSteve French cifs_sb = CIFS_SB(inode->i_sb); 50538c8a9a5SSteve French tlink = cifs_sb_tlink(cifs_sb); 50638c8a9a5SSteve French if (IS_ERR(tlink)) { 50738c8a9a5SSteve French rc = PTR_ERR(tlink); 50838c8a9a5SSteve French break; 50938c8a9a5SSteve French } 51038c8a9a5SSteve French tcon = tlink_tcon(tlink); 51138c8a9a5SSteve French if (tcon && tcon->ses->server->ops->notify) { 51238c8a9a5SSteve French rc = tcon->ses->server->ops->notify(xid, 51338c8a9a5SSteve French filep, (void __user *)arg, 51438c8a9a5SSteve French true /* return details */); 51538c8a9a5SSteve French cifs_dbg(FYI, "ioctl notify info rc %d\n", rc); 51638c8a9a5SSteve French } else 51738c8a9a5SSteve French rc = -EOPNOTSUPP; 51838c8a9a5SSteve French cifs_put_tlink(tlink); 51938c8a9a5SSteve French break; 52038c8a9a5SSteve French case CIFS_IOC_SHUTDOWN: 52138c8a9a5SSteve French rc = cifs_shutdown(inode->i_sb, arg); 52238c8a9a5SSteve French break; 52338c8a9a5SSteve French default: 52438c8a9a5SSteve French cifs_dbg(FYI, "unsupported ioctl\n"); 52538c8a9a5SSteve French break; 52638c8a9a5SSteve French } 52738c8a9a5SSteve French cifs_ioc_exit: 52838c8a9a5SSteve French free_xid(xid); 52938c8a9a5SSteve French return rc; 53038c8a9a5SSteve French } 531