fs: port vfs_*() helpers to struct mnt_idmap
[linux-block.git] / fs / ksmbd / smb2pdu.c
index 9306e10753f9a791a2669d381447a7df29272582..f787f66b329c189ccb37323679f41e036f5ebbe1 100644 (file)
@@ -903,7 +903,7 @@ static void decode_encrypt_ctxt(struct ksmbd_conn *conn,
                return;
        }
 
-       if (!(server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_ENCRYPTION))
+       if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_ENCRYPTION_OFF)
                return;
 
        for (i = 0; i < cph_cnt; i++) {
@@ -1508,7 +1508,8 @@ static int ntlm_authenticate(struct ksmbd_work *work)
                        return -EINVAL;
                }
                sess->enc = true;
-               rsp->SessionFlags = SMB2_SESSION_FLAG_ENCRYPT_DATA_LE;
+               if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_ENCRYPTION)
+                       rsp->SessionFlags = SMB2_SESSION_FLAG_ENCRYPT_DATA_LE;
                /*
                 * signing is disable if encryption is enable
                 * on this session
@@ -1599,7 +1600,8 @@ static int krb5_authenticate(struct ksmbd_work *work)
                        return -EINVAL;
                }
                sess->enc = true;
-               rsp->SessionFlags = SMB2_SESSION_FLAG_ENCRYPT_DATA_LE;
+               if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_ENCRYPTION)
+                       rsp->SessionFlags = SMB2_SESSION_FLAG_ENCRYPT_DATA_LE;
                sess->sign = false;
        }
 
@@ -3438,7 +3440,7 @@ static int smb2_populate_readdir_entry(struct ksmbd_conn *conn, int info_level,
                goto free_conv_name;
        }
 
-       struct_sz = readdir_info_level_struct_sz(info_level) - 1 + conv_len;
+       struct_sz = readdir_info_level_struct_sz(info_level) + conv_len;
        next_entry_offset = ALIGN(struct_sz, KSMBD_DIR_INFO_ALIGNMENT);
        d_info->last_entry_off_align = next_entry_offset - struct_sz;
 
@@ -3690,7 +3692,7 @@ static int reserve_populate_dentry(struct ksmbd_dir_info *d_info,
                return -EOPNOTSUPP;
 
        conv_len = (d_info->name_len + 1) * 2;
-       next_entry_offset = ALIGN(struct_sz - 1 + conv_len,
+       next_entry_offset = ALIGN(struct_sz + conv_len,
                                  KSMBD_DIR_INFO_ALIGNMENT);
 
        if (next_entry_offset > d_info->out_buf_len) {
@@ -5613,6 +5615,7 @@ static int set_file_basic_info(struct ksmbd_file *fp,
        struct iattr attrs;
        struct file *filp;
        struct inode *inode;
+       struct mnt_idmap *idmap;
        struct user_namespace *user_ns;
        int rc = 0;
 
@@ -5622,7 +5625,8 @@ static int set_file_basic_info(struct ksmbd_file *fp,
        attrs.ia_valid = 0;
        filp = fp->filp;
        inode = file_inode(filp);
-       user_ns = file_mnt_user_ns(filp);
+       idmap = file_mnt_idmap(filp);
+       user_ns = mnt_idmap_owner(idmap);
 
        if (file_info->CreationTime)
                fp->create_time = le64_to_cpu(file_info->CreationTime);
@@ -5684,7 +5688,7 @@ static int set_file_basic_info(struct ksmbd_file *fp,
                inode_lock(inode);
                inode->i_ctime = attrs.ia_ctime;
                attrs.ia_valid &= ~ATTR_CTIME;
-               rc = notify_change(user_ns, dentry, &attrs, NULL);
+               rc = notify_change(idmap, dentry, &attrs, NULL);
                inode_unlock(inode);
        }
        return rc;
@@ -6751,7 +6755,7 @@ static int smb2_set_flock_flags(struct file_lock *flock, int flags)
        case SMB2_LOCKFLAG_UNLOCK:
                ksmbd_debug(SMB, "received unlock request\n");
                flock->fl_type = F_UNLCK;
-               cmd = 0;
+               cmd = F_SETLK;
                break;
        }
 
@@ -6855,6 +6859,7 @@ int smb2_lock(struct ksmbd_work *work)
                if (lock_start > U64_MAX - lock_length) {
                        pr_err("Invalid lock range requested\n");
                        rsp->hdr.Status = STATUS_INVALID_LOCK_RANGE;
+                       locks_free_lock(flock);
                        goto out;
                }
 
@@ -6874,6 +6879,7 @@ int smb2_lock(struct ksmbd_work *work)
                                    "the end offset(%llx) is smaller than the start offset(%llx)\n",
                                    flock->fl_end, flock->fl_start);
                        rsp->hdr.Status = STATUS_INVALID_LOCK_RANGE;
+                       locks_free_lock(flock);
                        goto out;
                }
 
@@ -6885,6 +6891,7 @@ int smb2_lock(struct ksmbd_work *work)
                                    flock->fl_type != F_UNLCK) {
                                        pr_err("conflict two locks in one request\n");
                                        err = -EINVAL;
+                                       locks_free_lock(flock);
                                        goto out;
                                }
                        }
@@ -6893,6 +6900,7 @@ int smb2_lock(struct ksmbd_work *work)
                smb_lock = smb2_lock_init(flock, cmd, flags, &lock_list);
                if (!smb_lock) {
                        err = -EINVAL;
+                       locks_free_lock(flock);
                        goto out;
                }
        }
@@ -7129,7 +7137,7 @@ out:
                rlock->fl_start = smb_lock->start;
                rlock->fl_end = smb_lock->end;
 
-               rc = vfs_lock_file(filp, 0, rlock, NULL);
+               rc = vfs_lock_file(filp, F_SETLK, rlock, NULL);
                if (rc)
                        pr_err("rollback unlock fail : %d\n", rc);