OSDN Git Service

cifs: Fix uninitialized memory reads for oparms.mode
[tomoyo/tomoyo-test1.git] / fs / cifs / smb2ops.c
index e6bcd2b..43beec5 100644 (file)
@@ -729,12 +729,13 @@ smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon,
        struct cifs_fid fid;
        struct cached_fid *cfid = NULL;
 
-       oparms.tcon = tcon;
-       oparms.desired_access = FILE_READ_ATTRIBUTES;
-       oparms.disposition = FILE_OPEN;
-       oparms.create_options = cifs_create_options(cifs_sb, 0);
-       oparms.fid = &fid;
-       oparms.reconnect = false;
+       oparms = (struct cifs_open_parms) {
+               .tcon = tcon,
+               .desired_access = FILE_READ_ATTRIBUTES,
+               .disposition = FILE_OPEN,
+               .create_options = cifs_create_options(cifs_sb, 0),
+               .fid = &fid,
+       };
 
        rc = open_cached_dir(xid, tcon, "", cifs_sb, false, &cfid);
        if (rc == 0)
@@ -771,12 +772,13 @@ smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon,
        struct cifs_open_parms oparms;
        struct cifs_fid fid;
 
-       oparms.tcon = tcon;
-       oparms.desired_access = FILE_READ_ATTRIBUTES;
-       oparms.disposition = FILE_OPEN;
-       oparms.create_options = cifs_create_options(cifs_sb, 0);
-       oparms.fid = &fid;
-       oparms.reconnect = false;
+       oparms = (struct cifs_open_parms) {
+               .tcon = tcon,
+               .desired_access = FILE_READ_ATTRIBUTES,
+               .disposition = FILE_OPEN,
+               .create_options = cifs_create_options(cifs_sb, 0),
+               .fid = &fid,
+       };
 
        rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
                       NULL, NULL);
@@ -816,12 +818,13 @@ smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
        if (!utf16_path)
                return -ENOMEM;
 
-       oparms.tcon = tcon;
-       oparms.desired_access = FILE_READ_ATTRIBUTES;
-       oparms.disposition = FILE_OPEN;
-       oparms.create_options = cifs_create_options(cifs_sb, 0);
-       oparms.fid = &fid;
-       oparms.reconnect = false;
+       oparms = (struct cifs_open_parms) {
+               .tcon = tcon,
+               .desired_access = FILE_READ_ATTRIBUTES,
+               .disposition = FILE_OPEN,
+               .create_options = cifs_create_options(cifs_sb, 0),
+               .fid = &fid,
+       };
 
        rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL,
                       &err_iov, &err_buftype);
@@ -1097,13 +1100,13 @@ smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
        rqst[0].rq_iov = open_iov;
        rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
 
-       memset(&oparms, 0, sizeof(oparms));
-       oparms.tcon = tcon;
-       oparms.desired_access = FILE_WRITE_EA;
-       oparms.disposition = FILE_OPEN;
-       oparms.create_options = cifs_create_options(cifs_sb, 0);
-       oparms.fid = &fid;
-       oparms.reconnect = false;
+       oparms = (struct cifs_open_parms) {
+               .tcon = tcon,
+               .desired_access = FILE_WRITE_EA,
+               .disposition = FILE_OPEN,
+               .create_options = cifs_create_options(cifs_sb, 0),
+               .fid = &fid,
+       };
 
        rc = SMB2_open_init(tcon, server,
                            &rqst[0], &oplock, &oparms, utf16_path);
@@ -1453,12 +1456,12 @@ smb2_ioctl_query_info(const unsigned int xid,
        rqst[0].rq_iov = &vars->open_iov[0];
        rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
 
-       memset(&oparms, 0, sizeof(oparms));
-       oparms.tcon = tcon;
-       oparms.disposition = FILE_OPEN;
-       oparms.create_options = cifs_create_options(cifs_sb, create_options);
-       oparms.fid = &fid;
-       oparms.reconnect = false;
+       oparms = (struct cifs_open_parms) {
+               .tcon = tcon,
+               .disposition = FILE_OPEN,
+               .create_options = cifs_create_options(cifs_sb, create_options),
+               .fid = &fid,
+       };
 
        if (qi.flags & PASSTHRU_FSCTL) {
                switch (qi.info_type & FSCTL_DEVICE_ACCESS_MASK) {
@@ -2088,12 +2091,13 @@ smb3_notify(const unsigned int xid, struct file *pfile,
        }
 
        tcon = cifs_sb_master_tcon(cifs_sb);
-       oparms.tcon = tcon;
-       oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
-       oparms.disposition = FILE_OPEN;
-       oparms.create_options = cifs_create_options(cifs_sb, 0);
-       oparms.fid = &fid;
-       oparms.reconnect = false;
+       oparms = (struct cifs_open_parms) {
+               .tcon = tcon,
+               .desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA,
+               .disposition = FILE_OPEN,
+               .create_options = cifs_create_options(cifs_sb, 0),
+               .fid = &fid,
+       };
 
        rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL,
                       NULL);
@@ -2159,12 +2163,13 @@ smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
        rqst[0].rq_iov = open_iov;
        rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
 
-       oparms.tcon = tcon;
-       oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
-       oparms.disposition = FILE_OPEN;
-       oparms.create_options = cifs_create_options(cifs_sb, 0);
-       oparms.fid = fid;
-       oparms.reconnect = false;
+       oparms = (struct cifs_open_parms) {
+               .tcon = tcon,
+               .desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA,
+               .disposition = FILE_OPEN,
+               .create_options = cifs_create_options(cifs_sb, 0),
+               .fid = fid,
+       };
 
        rc = SMB2_open_init(tcon, server,
                            &rqst[0], &oplock, &oparms, utf16_path);
@@ -2490,12 +2495,13 @@ smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon,
        rqst[0].rq_iov = open_iov;
        rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
 
-       oparms.tcon = tcon;
-       oparms.desired_access = desired_access;
-       oparms.disposition = FILE_OPEN;
-       oparms.create_options = cifs_create_options(cifs_sb, 0);
-       oparms.fid = &fid;
-       oparms.reconnect = false;
+       oparms = (struct cifs_open_parms) {
+               .tcon = tcon,
+               .desired_access = desired_access,
+               .disposition = FILE_OPEN,
+               .create_options = cifs_create_options(cifs_sb, 0),
+               .fid = &fid,
+       };
 
        rc = SMB2_open_init(tcon, server,
                            &rqst[0], &oplock, &oparms, utf16_path);
@@ -2623,12 +2629,13 @@ smb311_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
        if (!tcon->posix_extensions)
                return smb2_queryfs(xid, tcon, cifs_sb, buf);
 
-       oparms.tcon = tcon;
-       oparms.desired_access = FILE_READ_ATTRIBUTES;
-       oparms.disposition = FILE_OPEN;
-       oparms.create_options = cifs_create_options(cifs_sb, 0);
-       oparms.fid = &fid;
-       oparms.reconnect = false;
+       oparms = (struct cifs_open_parms) {
+               .tcon = tcon,
+               .desired_access = FILE_READ_ATTRIBUTES,
+               .disposition = FILE_OPEN,
+               .create_options = cifs_create_options(cifs_sb, 0),
+               .fid = &fid,
+       };
 
        rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
                       NULL, NULL);
@@ -2916,13 +2923,13 @@ smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
        rqst[0].rq_iov = open_iov;
        rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
 
-       memset(&oparms, 0, sizeof(oparms));
-       oparms.tcon = tcon;
-       oparms.desired_access = FILE_READ_ATTRIBUTES;
-       oparms.disposition = FILE_OPEN;
-       oparms.create_options = cifs_create_options(cifs_sb, create_options);
-       oparms.fid = &fid;
-       oparms.reconnect = false;
+       oparms = (struct cifs_open_parms) {
+               .tcon = tcon,
+               .desired_access = FILE_READ_ATTRIBUTES,
+               .disposition = FILE_OPEN,
+               .create_options = cifs_create_options(cifs_sb, create_options),
+               .fid = &fid,
+       };
 
        rc = SMB2_open_init(tcon, server,
                            &rqst[0], &oplock, &oparms, utf16_path);
@@ -3056,13 +3063,13 @@ smb2_query_reparse_tag(const unsigned int xid, struct cifs_tcon *tcon,
        rqst[0].rq_iov = open_iov;
        rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
 
-       memset(&oparms, 0, sizeof(oparms));
-       oparms.tcon = tcon;
-       oparms.desired_access = FILE_READ_ATTRIBUTES;
-       oparms.disposition = FILE_OPEN;
-       oparms.create_options = cifs_create_options(cifs_sb, OPEN_REPARSE_POINT);
-       oparms.fid = &fid;
-       oparms.reconnect = false;
+       oparms = (struct cifs_open_parms) {
+               .tcon = tcon,
+               .desired_access = FILE_READ_ATTRIBUTES,
+               .disposition = FILE_OPEN,
+               .create_options = cifs_create_options(cifs_sb, OPEN_REPARSE_POINT),
+               .fid = &fid,
+       };
 
        rc = SMB2_open_init(tcon, server,
                            &rqst[0], &oplock, &oparms, utf16_path);
@@ -3196,17 +3203,20 @@ get_smb2_acl_by_path(struct cifs_sb_info *cifs_sb,
                return ERR_PTR(rc);
        }
 
-       oparms.tcon = tcon;
-       oparms.desired_access = READ_CONTROL;
-       oparms.disposition = FILE_OPEN;
-       /*
-        * When querying an ACL, even if the file is a symlink we want to open
-        * the source not the target, and so the protocol requires that the
-        * client specify this flag when opening a reparse point
-        */
-       oparms.create_options = cifs_create_options(cifs_sb, 0) | OPEN_REPARSE_POINT;
-       oparms.fid = &fid;
-       oparms.reconnect = false;
+       oparms = (struct cifs_open_parms) {
+               .tcon = tcon,
+               .desired_access = READ_CONTROL,
+               .disposition = FILE_OPEN,
+               /*
+                * When querying an ACL, even if the file is a symlink
+                * we want to open the source not the target, and so
+                * the protocol requires that the client specify this
+                * flag when opening a reparse point
+                */
+               .create_options = cifs_create_options(cifs_sb, 0) |
+                                 OPEN_REPARSE_POINT,
+               .fid = &fid,
+       };
 
        if (info & SACL_SECINFO)
                oparms.desired_access |= SYSTEM_SECURITY;
@@ -3265,13 +3275,14 @@ set_smb2_acl(struct cifs_ntsd *pnntsd, __u32 acllen,
                return rc;
        }
 
-       oparms.tcon = tcon;
-       oparms.desired_access = access_flags;
-       oparms.create_options = cifs_create_options(cifs_sb, 0);
-       oparms.disposition = FILE_OPEN;
-       oparms.path = path;
-       oparms.fid = &fid;
-       oparms.reconnect = false;
+       oparms = (struct cifs_open_parms) {
+               .tcon = tcon,
+               .desired_access = access_flags,
+               .create_options = cifs_create_options(cifs_sb, 0),
+               .disposition = FILE_OPEN,
+               .path = path,
+               .fid = &fid,
+       };
 
        rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL,
                       NULL, NULL);
@@ -4274,6 +4285,12 @@ static void *smb2_get_aead_req(struct crypto_aead *tfm, const struct smb_rqst *r
        sg_init_table(*sgl, num_sgs);
        sg = *sgl;
 
+       /*
+        * The first rqst has a transform header where the
+        * first 20 bytes are not part of the encrypted blob.
+        */
+       skip = 20;
+
        /* Assumes the first rqst has a transform header as the first iov.
         * I.e.
         * rqst[0].rq_iov[0]  is transform header
@@ -4281,17 +4298,15 @@ static void *smb2_get_aead_req(struct crypto_aead *tfm, const struct smb_rqst *r
         * rqst[1+].rq_iov[0+] data to be encrypted/decrypted
         */
        for (i = 0; i < num_rqst; i++) {
-               /*
-                * The first rqst has a transform header where the
-                * first 20 bytes are not part of the encrypted blob.
-                */
                for (j = 0; j < rqst[i].rq_nvec; j++) {
                        struct kvec *iov = &rqst[i].rq_iov[j];
 
-                       skip = (i == 0) && (j == 0) ? 20 : 0;
                        addr = (unsigned long)iov->iov_base + skip;
                        len = iov->iov_len - skip;
                        sg = cifs_sg_set_buf(sg, (void *)addr, len);
+
+                       /* See the above comment on the 'skip' assignment */
+                       skip = 0;
                }
                for (j = 0; j < rqst[i].rq_npages; j++) {
                        rqst_page_get_length(&rqst[i], j, &len, &off);
@@ -5134,15 +5149,16 @@ smb2_make_node(unsigned int xid, struct inode *inode,
 
        cifs_dbg(FYI, "sfu compat create special file\n");
 
-       oparms.tcon = tcon;
-       oparms.cifs_sb = cifs_sb;
-       oparms.desired_access = GENERIC_WRITE;
-       oparms.create_options = cifs_create_options(cifs_sb, CREATE_NOT_DIR |
-                                                   CREATE_OPTION_SPECIAL);
-       oparms.disposition = FILE_CREATE;
-       oparms.path = full_path;
-       oparms.fid = &fid;
-       oparms.reconnect = false;
+       oparms = (struct cifs_open_parms) {
+               .tcon = tcon,
+               .cifs_sb = cifs_sb,
+               .desired_access = GENERIC_WRITE,
+               .create_options = cifs_create_options(cifs_sb, CREATE_NOT_DIR |
+                                                     CREATE_OPTION_SPECIAL),
+               .disposition = FILE_CREATE,
+               .path = full_path,
+               .fid = &fid,
+       };
 
        if (tcon->ses->server->oplocks)
                oplock = REQ_OPLOCK;