]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
libcephfs: vet the CEPH_REQ_* flags in the C wrappers
authorJeff Layton <jlayton@redhat.com>
Fri, 18 Nov 2016 18:59:49 +0000 (13:59 -0500)
committerJeff Layton <jlayton@redhat.com>
Fri, 18 Nov 2016 18:59:49 +0000 (13:59 -0500)
Ensure that we can add new flags in the future by not allowing anyone
to set flags that we don't currently recognize.

Fixes: http://tracker.ceph.com/issues/17911
Signed-off-by: Jeff Layton <jlayton@redhat.com>
src/include/cephfs/ceph_statx.h
src/libcephfs.cc

index 73c8a957fed294f25ff6432e9017a37193c7aafb..17f598146a05e948f8093b6d42f6091956780b81 100644 (file)
@@ -62,11 +62,19 @@ struct ceph_statx {
 #define CEPH_STATX_VERSION     0x00001000U     /* Want/got stx_version */
 #define CEPH_STATX_ALL_STATS   0x00001fffU     /* All supported stats */
 
-/* statx request flags. Callers can set these in the "flags" field */
+/*
+ * Compatability macros until these defines make their way into glibc
+ */
 #ifndef AT_NO_ATTR_SYNC
 #define AT_NO_ATTR_SYNC                0x4000 /* Don't sync attributes with the server */
 #endif
 
+/*
+ * The statx interfaces only allow these flags. In order to allow us to add
+ * others in the future, we disallow setting any that aren't recognized.
+ */
+#define CEPH_REQ_FLAG_MASK             (AT_SYMLINK_NOFOLLOW|AT_NO_ATTR_SYNC)
+
 #ifdef __cplusplus
 }
 #endif
index 288f6a7c80e696f81fec905110c891411186cddc..5199855797da27a970bce3706a27433158e594e3 100644 (file)
@@ -33,7 +33,6 @@
 
 #include "include/cephfs/libcephfs.h"
 
-
 struct ceph_mount_info
 {
 public:
@@ -522,6 +521,8 @@ extern "C" int ceph_readdirplus_r(struct ceph_mount_info *cmount, struct ceph_di
 {
   if (!cmount->is_mounted())
     return -ENOTCONN;
+  if (flags & ~CEPH_REQ_FLAG_MASK)
+    return -EINVAL;
   return cmount->get_client()->readdirplus_r(reinterpret_cast<dir_result_t*>(dirp), de, stx, want, flags, out);
 }
 
@@ -629,6 +630,8 @@ extern "C" int ceph_statx(struct ceph_mount_info *cmount, const char *path,
 {
   if (!cmount->is_mounted())
     return -ENOTCONN;
+  if (flags & ~CEPH_REQ_FLAG_MASK)
+    return -EINVAL;
   return cmount->get_client()->statx(path, stx, cmount->default_perms,
                                     want, flags);
 }
@@ -646,6 +649,8 @@ extern "C" int ceph_setattrx(struct ceph_mount_info *cmount, const char *relpath
 {
   if (!cmount->is_mounted())
     return -ENOTCONN;
+  if (flags & ~CEPH_REQ_FLAG_MASK)
+    return -EINVAL;
   return cmount->get_client()->setattrx(relpath, stx, mask,
                                        cmount->default_perms, flags);
 }
@@ -898,6 +903,8 @@ extern "C" int ceph_fstatx(struct ceph_mount_info *cmount, int fd, struct ceph_s
 {
   if (!cmount->is_mounted())
     return -ENOTCONN;
+  if (flags & ~CEPH_REQ_FLAG_MASK)
+    return -EINVAL;
   return cmount->get_client()->fstatx(fd, stx, cmount->default_perms,
                                      want, flags);
 }
@@ -1408,6 +1415,8 @@ extern "C" int ceph_ll_lookup(struct ceph_mount_info *cmount,
                              struct ceph_statx *stx, unsigned want,
                              unsigned flags, const UserPerm *perms)
 {
+  if (flags & ~CEPH_REQ_FLAG_MASK)
+    return -EINVAL;
   return (cmount->get_client())->ll_lookupx(parent, name, out, stx, want,
                                            flags, *perms);
 }
@@ -1427,6 +1436,8 @@ int ceph_ll_walk(struct ceph_mount_info *cmount, const char* name, Inode **i,
                 struct ceph_statx *stx, unsigned int want, unsigned int flags,
                 const UserPerm *perms)
 {
+  if (flags & ~CEPH_REQ_FLAG_MASK)
+    return -EINVAL;
   return(cmount->get_client()->ll_walk(name, i, stx, want, flags, *perms));
 }
 
@@ -1435,6 +1446,8 @@ extern "C" int ceph_ll_getattr(class ceph_mount_info *cmount,
                               unsigned int want, unsigned int flags,
                               const UserPerm *perms)
 {
+  if (flags & ~CEPH_REQ_FLAG_MASK)
+    return -EINVAL;
   return (cmount->get_client()->ll_getattrx(in, stx, want, flags, *perms));
 }
 
@@ -1544,6 +1557,8 @@ extern "C" int ceph_ll_create(class ceph_mount_info *cmount,
                              struct ceph_statx *stx, unsigned want,
                              unsigned lflags, const UserPerm *perms)
 {
+  if (lflags & ~CEPH_REQ_FLAG_MASK)
+    return -EINVAL;
   return (cmount->get_client())->ll_createx(parent, name, mode, oflags, outp,
                                            fhp, stx, want, lflags, *perms);
 }
@@ -1554,6 +1569,8 @@ extern "C" int ceph_ll_mknod(class ceph_mount_info *cmount, Inode *parent,
                             unsigned want, unsigned flags,
                             const UserPerm *perms)
 {
+  if (flags & ~CEPH_REQ_FLAG_MASK)
+    return -EINVAL;
   return (cmount->get_client())->ll_mknodx(parent, name, mode, rdev,
                                           out, stx, want, flags, *perms);
 }
@@ -1563,6 +1580,8 @@ extern "C" int ceph_ll_mkdir(class ceph_mount_info *cmount, Inode *parent,
                             struct ceph_statx *stx, unsigned want,
                             unsigned flags, const UserPerm *perms)
 {
+  if (flags & ~CEPH_REQ_FLAG_MASK)
+    return -EINVAL;
   return cmount->get_client()->ll_mkdirx(parent, name, mode, out, stx, want,
                                         flags, *perms);
 }
@@ -1624,6 +1643,8 @@ extern "C" int ceph_ll_symlink(class ceph_mount_info *cmount,
                               struct ceph_statx *stx, unsigned want,
                               unsigned flags, const UserPerm *perms)
 {
+  if (flags & ~CEPH_REQ_FLAG_MASK)
+    return -EINVAL;
   return (cmount->get_client()->ll_symlinkx(in, name, value, out, stx, want,
                                            flags, *perms));
 }