staging/lustre/llite: strengthen checks for hsm flags and archive id
authorBruno Faccini <bruno.faccini@intel.com>
Mon, 14 Sep 2015 22:41:20 +0000 (18:41 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 15 Sep 2015 13:26:52 +0000 (06:26 -0700)
Prior to this patch undefined flags bits and out of range
archive id can be set.

Signed-off-by: Bruno Faccini <bruno.faccini@intel.com>
Reviewed-on: http://review.whamcloud.com/13337
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5757
Reviewed-by: frank zago <fzago@cray.com>
Reviewed-by: Henri Doreau <henri.doreau@cea.fr>
Signed-off-by: Oleg Drokin <oleg.drokin@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/lustre/lustre/include/lustre/lustre_idl.h
drivers/staging/lustre/lustre/llite/file.c

index e79af19ce853b9b6ba6a4535ac045e70d2c26066..9416d95702bae9e6a2830a924c9e5151f3c4601f 100644 (file)
@@ -365,6 +365,13 @@ static inline __u64 fid_ver_oid(const struct lu_fid *fid)
        return ((__u64)fid_ver(fid) << 32 | fid_oid(fid));
 }
 
+/* copytool uses a 32b bitmask field to encode archive-Ids during register
+ * with MDT thru kuc.
+ * archive num = 0 => all
+ * archive num from 1 to 32
+ */
+#define LL_HSM_MAX_ARCHIVE (sizeof(__u32) * 8)
+
 /**
  * Note that reserved SEQ numbers below 12 will conflict with ldiskfs
  * inodes in the IGIF namespace, so these reserved SEQ numbers can be
index e332326011d1dce00bd6682144faa6dc22a28bfb..b6100325723db11800f067aab87e64acc23a6b31 100644 (file)
@@ -2118,12 +2118,21 @@ static int ll_hsm_state_set(struct inode *inode, struct hsm_state_set *hss)
        struct md_op_data       *op_data;
        int                      rc;
 
+       /* Detect out-of range masks */
+       if ((hss->hss_setmask | hss->hss_clearmask) & ~HSM_FLAGS_MASK)
+               return -EINVAL;
+
        /* Non-root users are forbidden to set or clear flags which are
         * NOT defined in HSM_USER_MASK. */
        if (((hss->hss_setmask | hss->hss_clearmask) & ~HSM_USER_MASK) &&
            !capable(CFS_CAP_SYS_ADMIN))
                return -EPERM;
 
+       /* Detect out-of range archive id */
+       if ((hss->hss_valid & HSS_ARCHIVE_ID) &&
+           (hss->hss_archive_id > LL_HSM_MAX_ARCHIVE))
+               return -EINVAL;
+
        op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
                                     LUSTRE_OPC_ANY, hss);
        if (IS_ERR(op_data))