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
cifs_ioctl_query_info(unsigned int xid,struct file * filep,unsigned long p)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
cifs_ioctl_copychunk(unsigned int xid,struct file * dst_file,unsigned long srcfd)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
smb_mnt_get_tcon_info(struct cifs_tcon * tcon,void __user * arg)12067062c84SSteve French static long smb_mnt_get_tcon_info(struct cifs_tcon *tcon, void __user *arg)
12167062c84SSteve French {
12267062c84SSteve French int rc = 0;
12367062c84SSteve French struct smb_mnt_tcon_info tcon_inf;
12467062c84SSteve French
12567062c84SSteve French tcon_inf.tid = tcon->tid;
12667062c84SSteve French tcon_inf.session_id = tcon->ses->Suid;
12767062c84SSteve French
12867062c84SSteve French if (copy_to_user(arg, &tcon_inf, sizeof(struct smb_mnt_tcon_info)))
12967062c84SSteve French rc = -EFAULT;
13067062c84SSteve French
13167062c84SSteve French return rc;
13267062c84SSteve French }
13367062c84SSteve French
smb_mnt_get_fsinfo(unsigned int xid,struct cifs_tcon * tcon,void __user * arg)13438c8a9a5SSteve French static long smb_mnt_get_fsinfo(unsigned int xid, struct cifs_tcon *tcon,
13538c8a9a5SSteve French void __user *arg)
13638c8a9a5SSteve French {
13738c8a9a5SSteve French int rc = 0;
13838c8a9a5SSteve French struct smb_mnt_fs_info *fsinf;
13938c8a9a5SSteve French
14038c8a9a5SSteve French fsinf = kzalloc(sizeof(struct smb_mnt_fs_info), GFP_KERNEL);
14138c8a9a5SSteve French if (fsinf == NULL)
14238c8a9a5SSteve French return -ENOMEM;
14338c8a9a5SSteve French
14438c8a9a5SSteve French fsinf->version = 1;
14538c8a9a5SSteve French fsinf->protocol_id = tcon->ses->server->vals->protocol_id;
146bb536892SSteve French fsinf->tcon_flags = tcon->Flags;
14738c8a9a5SSteve French fsinf->device_characteristics =
14838c8a9a5SSteve French le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics);
14938c8a9a5SSteve French fsinf->device_type = le32_to_cpu(tcon->fsDevInfo.DeviceType);
15038c8a9a5SSteve French fsinf->fs_attributes = le32_to_cpu(tcon->fsAttrInfo.Attributes);
15138c8a9a5SSteve French fsinf->max_path_component =
15238c8a9a5SSteve French le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength);
15338c8a9a5SSteve French fsinf->vol_serial_number = tcon->vol_serial_number;
15438c8a9a5SSteve French fsinf->vol_create_time = le64_to_cpu(tcon->vol_create_time);
15538c8a9a5SSteve French fsinf->share_flags = tcon->share_flags;
15638c8a9a5SSteve French fsinf->share_caps = le32_to_cpu(tcon->capabilities);
15738c8a9a5SSteve French fsinf->sector_flags = tcon->ss_flags;
15838c8a9a5SSteve French fsinf->optimal_sector_size = tcon->perf_sector_size;
15938c8a9a5SSteve French fsinf->max_bytes_chunk = tcon->max_bytes_chunk;
16038c8a9a5SSteve French fsinf->maximal_access = tcon->maximal_access;
16138c8a9a5SSteve French fsinf->cifs_posix_caps = le64_to_cpu(tcon->fsUnixInfo.Capability);
16238c8a9a5SSteve French
16338c8a9a5SSteve French if (copy_to_user(arg, fsinf, sizeof(struct smb_mnt_fs_info)))
16438c8a9a5SSteve French rc = -EFAULT;
16538c8a9a5SSteve French
16638c8a9a5SSteve French kfree(fsinf);
16738c8a9a5SSteve French return rc;
16838c8a9a5SSteve French }
16938c8a9a5SSteve French
cifs_shutdown(struct super_block * sb,unsigned long arg)17038c8a9a5SSteve French static int cifs_shutdown(struct super_block *sb, unsigned long arg)
17138c8a9a5SSteve French {
17238c8a9a5SSteve French struct cifs_sb_info *sbi = CIFS_SB(sb);
17338c8a9a5SSteve French __u32 flags;
17438c8a9a5SSteve French
17538c8a9a5SSteve French if (!capable(CAP_SYS_ADMIN))
17638c8a9a5SSteve French return -EPERM;
17738c8a9a5SSteve French
17838c8a9a5SSteve French if (get_user(flags, (__u32 __user *)arg))
17938c8a9a5SSteve French return -EFAULT;
18038c8a9a5SSteve French
18138c8a9a5SSteve French if (flags > CIFS_GOING_FLAGS_NOLOGFLUSH)
18238c8a9a5SSteve French return -EINVAL;
18338c8a9a5SSteve French
18438c8a9a5SSteve French if (cifs_forced_shutdown(sbi))
18538c8a9a5SSteve French return 0;
18638c8a9a5SSteve French
18738c8a9a5SSteve French cifs_dbg(VFS, "shut down requested (%d)", flags);
18838c8a9a5SSteve French /* trace_cifs_shutdown(sb, flags);*/
18938c8a9a5SSteve French
19038c8a9a5SSteve French /*
19138c8a9a5SSteve French * see:
19238c8a9a5SSteve French * https://man7.org/linux/man-pages/man2/ioctl_xfs_goingdown.2.html
19338c8a9a5SSteve French * for more information and description of original intent of the flags
19438c8a9a5SSteve French */
19538c8a9a5SSteve French switch (flags) {
19638c8a9a5SSteve French /*
19738c8a9a5SSteve French * We could add support later for default flag which requires:
19838c8a9a5SSteve French * "Flush all dirty data and metadata to disk"
19938c8a9a5SSteve French * would need to call syncfs or equivalent to flush page cache for
20038c8a9a5SSteve French * the mount and then issue fsync to server (if nostrictsync not set)
20138c8a9a5SSteve French */
20238c8a9a5SSteve French case CIFS_GOING_FLAGS_DEFAULT:
20338c8a9a5SSteve French cifs_dbg(FYI, "shutdown with default flag not supported\n");
20438c8a9a5SSteve French return -EINVAL;
20538c8a9a5SSteve French /*
20638c8a9a5SSteve French * FLAGS_LOGFLUSH is easy since it asks to write out metadata (not
20738c8a9a5SSteve French * data) but metadata writes are not cached on the client, so can treat
20838c8a9a5SSteve French * it similarly to NOLOGFLUSH
20938c8a9a5SSteve French */
21038c8a9a5SSteve French case CIFS_GOING_FLAGS_LOGFLUSH:
21138c8a9a5SSteve French case CIFS_GOING_FLAGS_NOLOGFLUSH:
21238c8a9a5SSteve French sbi->mnt_cifs_flags |= CIFS_MOUNT_SHUTDOWN;
21338c8a9a5SSteve French return 0;
21438c8a9a5SSteve French default:
21538c8a9a5SSteve French return -EINVAL;
21638c8a9a5SSteve French }
21738c8a9a5SSteve French return 0;
21838c8a9a5SSteve French }
21938c8a9a5SSteve French
cifs_dump_full_key(struct cifs_tcon * tcon,struct smb3_full_key_debug_info __user * in)22038c8a9a5SSteve French static int cifs_dump_full_key(struct cifs_tcon *tcon, struct smb3_full_key_debug_info __user *in)
22138c8a9a5SSteve French {
22238c8a9a5SSteve French struct smb3_full_key_debug_info out;
22338c8a9a5SSteve French struct cifs_ses *ses;
22438c8a9a5SSteve French int rc = 0;
22538c8a9a5SSteve French bool found = false;
22638c8a9a5SSteve French u8 __user *end;
22738c8a9a5SSteve French
22838c8a9a5SSteve French if (!smb3_encryption_required(tcon)) {
22938c8a9a5SSteve French rc = -EOPNOTSUPP;
23038c8a9a5SSteve French goto out;
23138c8a9a5SSteve French }
23238c8a9a5SSteve French
23338c8a9a5SSteve French /* copy user input into our output buffer */
23438c8a9a5SSteve French if (copy_from_user(&out, in, sizeof(out))) {
23538c8a9a5SSteve French rc = -EINVAL;
23638c8a9a5SSteve French goto out;
23738c8a9a5SSteve French }
23838c8a9a5SSteve French
23938c8a9a5SSteve French if (!out.session_id) {
24038c8a9a5SSteve French /* if ses id is 0, use current user session */
24138c8a9a5SSteve French ses = tcon->ses;
24238c8a9a5SSteve French } else {
24338c8a9a5SSteve French /* otherwise if a session id is given, look for it in all our sessions */
24438c8a9a5SSteve French struct cifs_ses *ses_it = NULL;
24538c8a9a5SSteve French struct TCP_Server_Info *server_it = NULL;
24638c8a9a5SSteve French
24738c8a9a5SSteve French spin_lock(&cifs_tcp_ses_lock);
24838c8a9a5SSteve French list_for_each_entry(server_it, &cifs_tcp_ses_list, tcp_ses_list) {
24938c8a9a5SSteve French list_for_each_entry(ses_it, &server_it->smb_ses_list, smb_ses_list) {
25010e17ca4SPaulo Alcantara spin_lock(&ses_it->ses_lock);
25110e17ca4SPaulo Alcantara if (ses_it->ses_status != SES_EXITING &&
25210e17ca4SPaulo Alcantara ses_it->Suid == out.session_id) {
25338c8a9a5SSteve French ses = ses_it;
25438c8a9a5SSteve French /*
25538c8a9a5SSteve French * since we are using the session outside the crit
25638c8a9a5SSteve French * section, we need to make sure it won't be released
25738c8a9a5SSteve French * so increment its refcount
25838c8a9a5SSteve French */
25938c8a9a5SSteve French cifs_smb_ses_inc_refcount(ses);
26010e17ca4SPaulo Alcantara spin_unlock(&ses_it->ses_lock);
26138c8a9a5SSteve French found = true;
26238c8a9a5SSteve French goto search_end;
26338c8a9a5SSteve French }
26410e17ca4SPaulo Alcantara spin_unlock(&ses_it->ses_lock);
26538c8a9a5SSteve French }
26638c8a9a5SSteve French }
26738c8a9a5SSteve French search_end:
26838c8a9a5SSteve French spin_unlock(&cifs_tcp_ses_lock);
26938c8a9a5SSteve French if (!found) {
27038c8a9a5SSteve French rc = -ENOENT;
27138c8a9a5SSteve French goto out;
27238c8a9a5SSteve French }
27338c8a9a5SSteve French }
27438c8a9a5SSteve French
27538c8a9a5SSteve French switch (ses->server->cipher_type) {
27638c8a9a5SSteve French case SMB2_ENCRYPTION_AES128_CCM:
27738c8a9a5SSteve French case SMB2_ENCRYPTION_AES128_GCM:
27838c8a9a5SSteve French out.session_key_length = CIFS_SESS_KEY_SIZE;
27938c8a9a5SSteve French out.server_in_key_length = out.server_out_key_length = SMB3_GCM128_CRYPTKEY_SIZE;
28038c8a9a5SSteve French break;
28138c8a9a5SSteve French case SMB2_ENCRYPTION_AES256_CCM:
28238c8a9a5SSteve French case SMB2_ENCRYPTION_AES256_GCM:
28338c8a9a5SSteve French out.session_key_length = CIFS_SESS_KEY_SIZE;
28438c8a9a5SSteve French out.server_in_key_length = out.server_out_key_length = SMB3_GCM256_CRYPTKEY_SIZE;
28538c8a9a5SSteve French break;
28638c8a9a5SSteve French default:
28738c8a9a5SSteve French rc = -EOPNOTSUPP;
28838c8a9a5SSteve French goto out;
28938c8a9a5SSteve French }
29038c8a9a5SSteve French
29138c8a9a5SSteve French /* check if user buffer is big enough to store all the keys */
29238c8a9a5SSteve French if (out.in_size < sizeof(out) + out.session_key_length + out.server_in_key_length
29338c8a9a5SSteve French + out.server_out_key_length) {
29438c8a9a5SSteve French rc = -ENOBUFS;
29538c8a9a5SSteve French goto out;
29638c8a9a5SSteve French }
29738c8a9a5SSteve French
29838c8a9a5SSteve French out.session_id = ses->Suid;
29938c8a9a5SSteve French out.cipher_type = le16_to_cpu(ses->server->cipher_type);
30038c8a9a5SSteve French
30138c8a9a5SSteve French /* overwrite user input with our output */
30238c8a9a5SSteve French if (copy_to_user(in, &out, sizeof(out))) {
30338c8a9a5SSteve French rc = -EINVAL;
30438c8a9a5SSteve French goto out;
30538c8a9a5SSteve French }
30638c8a9a5SSteve French
30738c8a9a5SSteve French /* append all the keys at the end of the user buffer */
30838c8a9a5SSteve French end = in->data;
30938c8a9a5SSteve French if (copy_to_user(end, ses->auth_key.response, out.session_key_length)) {
31038c8a9a5SSteve French rc = -EINVAL;
31138c8a9a5SSteve French goto out;
31238c8a9a5SSteve French }
31338c8a9a5SSteve French end += out.session_key_length;
31438c8a9a5SSteve French
31538c8a9a5SSteve French if (copy_to_user(end, ses->smb3encryptionkey, out.server_in_key_length)) {
31638c8a9a5SSteve French rc = -EINVAL;
31738c8a9a5SSteve French goto out;
31838c8a9a5SSteve French }
31938c8a9a5SSteve French end += out.server_in_key_length;
32038c8a9a5SSteve French
32138c8a9a5SSteve French if (copy_to_user(end, ses->smb3decryptionkey, out.server_out_key_length)) {
32238c8a9a5SSteve French rc = -EINVAL;
32338c8a9a5SSteve French goto out;
32438c8a9a5SSteve French }
32538c8a9a5SSteve French
32638c8a9a5SSteve French out:
32738c8a9a5SSteve French if (found)
32838c8a9a5SSteve French cifs_put_smb_ses(ses);
32938c8a9a5SSteve French return rc;
33038c8a9a5SSteve French }
33138c8a9a5SSteve French
cifs_ioctl(struct file * filep,unsigned int command,unsigned long arg)33238c8a9a5SSteve French long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg)
33338c8a9a5SSteve French {
33438c8a9a5SSteve French struct inode *inode = file_inode(filep);
33538c8a9a5SSteve French struct smb3_key_debug_info pkey_inf;
33638c8a9a5SSteve French int rc = -ENOTTY; /* strange error - but the precedent */
33738c8a9a5SSteve French unsigned int xid;
33838c8a9a5SSteve French struct cifsFileInfo *pSMBFile = filep->private_data;
33938c8a9a5SSteve French struct cifs_tcon *tcon;
34038c8a9a5SSteve French struct tcon_link *tlink;
34138c8a9a5SSteve French struct cifs_sb_info *cifs_sb;
34238c8a9a5SSteve French __u64 ExtAttrBits = 0;
343fdd7d1ffSSteve French #ifdef CONFIG_CIFS_POSIX
344fdd7d1ffSSteve French #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
34538c8a9a5SSteve French __u64 caps;
346fdd7d1ffSSteve French #endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
347fdd7d1ffSSteve French #endif /* CONFIG_CIFS_POSIX */
34838c8a9a5SSteve French
34938c8a9a5SSteve French xid = get_xid();
35038c8a9a5SSteve French
35138c8a9a5SSteve French cifs_dbg(FYI, "cifs ioctl 0x%x\n", command);
352*25f3604fSSteve French if (pSMBFile == NULL)
353*25f3604fSSteve French trace_smb3_ioctl(xid, 0, command);
354*25f3604fSSteve French else
355*25f3604fSSteve French trace_smb3_ioctl(xid, pSMBFile->fid.persistent_fid, command);
356*25f3604fSSteve French
35738c8a9a5SSteve French switch (command) {
35838c8a9a5SSteve French case FS_IOC_GETFLAGS:
35938c8a9a5SSteve French if (pSMBFile == NULL)
36038c8a9a5SSteve French break;
36138c8a9a5SSteve French tcon = tlink_tcon(pSMBFile->tlink);
36238c8a9a5SSteve French #ifdef CONFIG_CIFS_POSIX
36338c8a9a5SSteve French #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
364fdd7d1ffSSteve French caps = le64_to_cpu(tcon->fsUnixInfo.Capability);
36538c8a9a5SSteve French if (CIFS_UNIX_EXTATTR_CAP & caps) {
36638c8a9a5SSteve French __u64 ExtAttrMask = 0;
36738c8a9a5SSteve French rc = CIFSGetExtAttr(xid, tcon,
36838c8a9a5SSteve French pSMBFile->fid.netfid,
36938c8a9a5SSteve French &ExtAttrBits, &ExtAttrMask);
37038c8a9a5SSteve French if (rc == 0)
37138c8a9a5SSteve French rc = put_user(ExtAttrBits &
37238c8a9a5SSteve French FS_FL_USER_VISIBLE,
37338c8a9a5SSteve French (int __user *)arg);
37438c8a9a5SSteve French if (rc != -EOPNOTSUPP)
37538c8a9a5SSteve French break;
37638c8a9a5SSteve French }
37738c8a9a5SSteve French #endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
37838c8a9a5SSteve French #endif /* CONFIG_CIFS_POSIX */
37938c8a9a5SSteve French rc = 0;
38038c8a9a5SSteve French if (CIFS_I(inode)->cifsAttrs & ATTR_COMPRESSED) {
38138c8a9a5SSteve French /* add in the compressed bit */
38238c8a9a5SSteve French ExtAttrBits = FS_COMPR_FL;
38338c8a9a5SSteve French rc = put_user(ExtAttrBits & FS_FL_USER_VISIBLE,
38438c8a9a5SSteve French (int __user *)arg);
38538c8a9a5SSteve French }
38638c8a9a5SSteve French break;
38738c8a9a5SSteve French case FS_IOC_SETFLAGS:
38838c8a9a5SSteve French if (pSMBFile == NULL)
38938c8a9a5SSteve French break;
39038c8a9a5SSteve French tcon = tlink_tcon(pSMBFile->tlink);
39138c8a9a5SSteve French /* caps = le64_to_cpu(tcon->fsUnixInfo.Capability); */
39238c8a9a5SSteve French
39338c8a9a5SSteve French if (get_user(ExtAttrBits, (int __user *)arg)) {
39438c8a9a5SSteve French rc = -EFAULT;
39538c8a9a5SSteve French break;
39638c8a9a5SSteve French }
39738c8a9a5SSteve French
39838c8a9a5SSteve French /*
39938c8a9a5SSteve French * if (CIFS_UNIX_EXTATTR_CAP & caps)
40038c8a9a5SSteve French * rc = CIFSSetExtAttr(xid, tcon,
40138c8a9a5SSteve French * pSMBFile->fid.netfid,
40238c8a9a5SSteve French * extAttrBits,
40338c8a9a5SSteve French * &ExtAttrMask);
40438c8a9a5SSteve French * if (rc != -EOPNOTSUPP)
40538c8a9a5SSteve French * break;
40638c8a9a5SSteve French */
40738c8a9a5SSteve French
40838c8a9a5SSteve French /* Currently only flag we can set is compressed flag */
40938c8a9a5SSteve French if ((ExtAttrBits & FS_COMPR_FL) == 0)
41038c8a9a5SSteve French break;
41138c8a9a5SSteve French
41238c8a9a5SSteve French /* Try to set compress flag */
41338c8a9a5SSteve French if (tcon->ses->server->ops->set_compression) {
41438c8a9a5SSteve French rc = tcon->ses->server->ops->set_compression(
41538c8a9a5SSteve French xid, tcon, pSMBFile);
41638c8a9a5SSteve French cifs_dbg(FYI, "set compress flag rc %d\n", rc);
41738c8a9a5SSteve French }
41838c8a9a5SSteve French break;
41938c8a9a5SSteve French case CIFS_IOC_COPYCHUNK_FILE:
42038c8a9a5SSteve French rc = cifs_ioctl_copychunk(xid, filep, arg);
42138c8a9a5SSteve French break;
42238c8a9a5SSteve French case CIFS_QUERY_INFO:
42338c8a9a5SSteve French rc = cifs_ioctl_query_info(xid, filep, arg);
42438c8a9a5SSteve French break;
42538c8a9a5SSteve French case CIFS_IOC_SET_INTEGRITY:
42638c8a9a5SSteve French if (pSMBFile == NULL)
42738c8a9a5SSteve French break;
42838c8a9a5SSteve French tcon = tlink_tcon(pSMBFile->tlink);
42938c8a9a5SSteve French if (tcon->ses->server->ops->set_integrity)
43038c8a9a5SSteve French rc = tcon->ses->server->ops->set_integrity(xid,
43138c8a9a5SSteve French tcon, pSMBFile);
43238c8a9a5SSteve French else
43338c8a9a5SSteve French rc = -EOPNOTSUPP;
43438c8a9a5SSteve French break;
43538c8a9a5SSteve French case CIFS_IOC_GET_MNT_INFO:
43638c8a9a5SSteve French if (pSMBFile == NULL)
43738c8a9a5SSteve French break;
43838c8a9a5SSteve French tcon = tlink_tcon(pSMBFile->tlink);
43938c8a9a5SSteve French rc = smb_mnt_get_fsinfo(xid, tcon, (void __user *)arg);
44038c8a9a5SSteve French break;
44167062c84SSteve French case CIFS_IOC_GET_TCON_INFO:
44267062c84SSteve French cifs_sb = CIFS_SB(inode->i_sb);
44367062c84SSteve French tlink = cifs_sb_tlink(cifs_sb);
44467062c84SSteve French if (IS_ERR(tlink)) {
44567062c84SSteve French rc = PTR_ERR(tlink);
44667062c84SSteve French break;
44767062c84SSteve French }
44867062c84SSteve French tcon = tlink_tcon(tlink);
44967062c84SSteve French rc = smb_mnt_get_tcon_info(tcon, (void __user *)arg);
45067062c84SSteve French cifs_put_tlink(tlink);
45167062c84SSteve French break;
45238c8a9a5SSteve French case CIFS_ENUMERATE_SNAPSHOTS:
45338c8a9a5SSteve French if (pSMBFile == NULL)
45438c8a9a5SSteve French break;
45538c8a9a5SSteve French if (arg == 0) {
45638c8a9a5SSteve French rc = -EINVAL;
45738c8a9a5SSteve French goto cifs_ioc_exit;
45838c8a9a5SSteve French }
45938c8a9a5SSteve French tcon = tlink_tcon(pSMBFile->tlink);
46038c8a9a5SSteve French if (tcon->ses->server->ops->enum_snapshots)
46138c8a9a5SSteve French rc = tcon->ses->server->ops->enum_snapshots(xid, tcon,
46238c8a9a5SSteve French pSMBFile, (void __user *)arg);
46338c8a9a5SSteve French else
46438c8a9a5SSteve French rc = -EOPNOTSUPP;
46538c8a9a5SSteve French break;
46638c8a9a5SSteve French case CIFS_DUMP_KEY:
46738c8a9a5SSteve French /*
46838c8a9a5SSteve French * Dump encryption keys. This is an old ioctl that only
46938c8a9a5SSteve French * handles AES-128-{CCM,GCM}.
47038c8a9a5SSteve French */
47138c8a9a5SSteve French if (!capable(CAP_SYS_ADMIN)) {
47238c8a9a5SSteve French rc = -EACCES;
47338c8a9a5SSteve French break;
47438c8a9a5SSteve French }
47538c8a9a5SSteve French
476b3edef6bSShyam Prasad N cifs_sb = CIFS_SB(inode->i_sb);
477b3edef6bSShyam Prasad N tlink = cifs_sb_tlink(cifs_sb);
478b3edef6bSShyam Prasad N if (IS_ERR(tlink)) {
479b3edef6bSShyam Prasad N rc = PTR_ERR(tlink);
480b3edef6bSShyam Prasad N break;
481b3edef6bSShyam Prasad N }
482b3edef6bSShyam Prasad N tcon = tlink_tcon(tlink);
48338c8a9a5SSteve French if (!smb3_encryption_required(tcon)) {
48438c8a9a5SSteve French rc = -EOPNOTSUPP;
485b3edef6bSShyam Prasad N cifs_put_tlink(tlink);
48638c8a9a5SSteve French break;
48738c8a9a5SSteve French }
48838c8a9a5SSteve French pkey_inf.cipher_type =
48938c8a9a5SSteve French le16_to_cpu(tcon->ses->server->cipher_type);
49038c8a9a5SSteve French pkey_inf.Suid = tcon->ses->Suid;
49138c8a9a5SSteve French memcpy(pkey_inf.auth_key, tcon->ses->auth_key.response,
49238c8a9a5SSteve French 16 /* SMB2_NTLMV2_SESSKEY_SIZE */);
49338c8a9a5SSteve French memcpy(pkey_inf.smb3decryptionkey,
49438c8a9a5SSteve French tcon->ses->smb3decryptionkey, SMB3_SIGN_KEY_SIZE);
49538c8a9a5SSteve French memcpy(pkey_inf.smb3encryptionkey,
49638c8a9a5SSteve French tcon->ses->smb3encryptionkey, SMB3_SIGN_KEY_SIZE);
49738c8a9a5SSteve French if (copy_to_user((void __user *)arg, &pkey_inf,
49838c8a9a5SSteve French sizeof(struct smb3_key_debug_info)))
49938c8a9a5SSteve French rc = -EFAULT;
50038c8a9a5SSteve French else
50138c8a9a5SSteve French rc = 0;
502b3edef6bSShyam Prasad N cifs_put_tlink(tlink);
50338c8a9a5SSteve French break;
50438c8a9a5SSteve French case CIFS_DUMP_FULL_KEY:
50538c8a9a5SSteve French /*
50638c8a9a5SSteve French * Dump encryption keys (handles any key sizes)
50738c8a9a5SSteve French */
50838c8a9a5SSteve French if (pSMBFile == NULL)
50938c8a9a5SSteve French break;
51038c8a9a5SSteve French if (!capable(CAP_SYS_ADMIN)) {
51138c8a9a5SSteve French rc = -EACCES;
51238c8a9a5SSteve French break;
51338c8a9a5SSteve French }
514b3edef6bSShyam Prasad N cifs_sb = CIFS_SB(inode->i_sb);
515b3edef6bSShyam Prasad N tlink = cifs_sb_tlink(cifs_sb);
516a171eb5cSShyam Prasad N if (IS_ERR(tlink)) {
517a171eb5cSShyam Prasad N rc = PTR_ERR(tlink);
518a171eb5cSShyam Prasad N break;
519a171eb5cSShyam Prasad N }
520a171eb5cSShyam Prasad N
521b3edef6bSShyam Prasad N tcon = tlink_tcon(tlink);
52238c8a9a5SSteve French rc = cifs_dump_full_key(tcon, (void __user *)arg);
523b3edef6bSShyam Prasad N cifs_put_tlink(tlink);
52438c8a9a5SSteve French break;
52538c8a9a5SSteve French case CIFS_IOC_NOTIFY:
52638c8a9a5SSteve French if (!S_ISDIR(inode->i_mode)) {
52738c8a9a5SSteve French /* Notify can only be done on directories */
52838c8a9a5SSteve French rc = -EOPNOTSUPP;
52938c8a9a5SSteve French break;
53038c8a9a5SSteve French }
53138c8a9a5SSteve French cifs_sb = CIFS_SB(inode->i_sb);
53238c8a9a5SSteve French tlink = cifs_sb_tlink(cifs_sb);
53338c8a9a5SSteve French if (IS_ERR(tlink)) {
53438c8a9a5SSteve French rc = PTR_ERR(tlink);
53538c8a9a5SSteve French break;
53638c8a9a5SSteve French }
53738c8a9a5SSteve French tcon = tlink_tcon(tlink);
53838c8a9a5SSteve French if (tcon && tcon->ses->server->ops->notify) {
53938c8a9a5SSteve French rc = tcon->ses->server->ops->notify(xid,
54038c8a9a5SSteve French filep, (void __user *)arg,
54138c8a9a5SSteve French false /* no ret data */);
54238c8a9a5SSteve French cifs_dbg(FYI, "ioctl notify rc %d\n", rc);
54338c8a9a5SSteve French } else
54438c8a9a5SSteve French rc = -EOPNOTSUPP;
54538c8a9a5SSteve French cifs_put_tlink(tlink);
54638c8a9a5SSteve French break;
54738c8a9a5SSteve French case CIFS_IOC_NOTIFY_INFO:
54838c8a9a5SSteve French if (!S_ISDIR(inode->i_mode)) {
54938c8a9a5SSteve French /* Notify can only be done on directories */
55038c8a9a5SSteve French rc = -EOPNOTSUPP;
55138c8a9a5SSteve French break;
55238c8a9a5SSteve French }
55338c8a9a5SSteve French cifs_sb = CIFS_SB(inode->i_sb);
55438c8a9a5SSteve French tlink = cifs_sb_tlink(cifs_sb);
55538c8a9a5SSteve French if (IS_ERR(tlink)) {
55638c8a9a5SSteve French rc = PTR_ERR(tlink);
55738c8a9a5SSteve French break;
55838c8a9a5SSteve French }
55938c8a9a5SSteve French tcon = tlink_tcon(tlink);
56038c8a9a5SSteve French if (tcon && tcon->ses->server->ops->notify) {
56138c8a9a5SSteve French rc = tcon->ses->server->ops->notify(xid,
56238c8a9a5SSteve French filep, (void __user *)arg,
56338c8a9a5SSteve French true /* return details */);
56438c8a9a5SSteve French cifs_dbg(FYI, "ioctl notify info rc %d\n", rc);
56538c8a9a5SSteve French } else
56638c8a9a5SSteve French rc = -EOPNOTSUPP;
56738c8a9a5SSteve French cifs_put_tlink(tlink);
56838c8a9a5SSteve French break;
56938c8a9a5SSteve French case CIFS_IOC_SHUTDOWN:
57038c8a9a5SSteve French rc = cifs_shutdown(inode->i_sb, arg);
57138c8a9a5SSteve French break;
57238c8a9a5SSteve French default:
57338c8a9a5SSteve French cifs_dbg(FYI, "unsupported ioctl\n");
57438c8a9a5SSteve French break;
57538c8a9a5SSteve French }
57638c8a9a5SSteve French cifs_ioc_exit:
57738c8a9a5SSteve French free_xid(xid);
57838c8a9a5SSteve French return rc;
57938c8a9a5SSteve French }
580