From 28988655b0ff4ab68251f28e58719ba82e8d1035 Mon Sep 17 00:00:00 2001 From: Jeff Layton Date: Fri, 18 Nov 2016 13:59:49 -0500 Subject: [PATCH] libcephfs: vet the CEPH_REQ_* flags in the C wrappers 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 --- src/include/cephfs/ceph_statx.h | 10 +++++++++- src/libcephfs.cc | 23 ++++++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/include/cephfs/ceph_statx.h b/src/include/cephfs/ceph_statx.h index 73c8a957fed29..17f598146a05e 100644 --- a/src/include/cephfs/ceph_statx.h +++ b/src/include/cephfs/ceph_statx.h @@ -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 diff --git a/src/libcephfs.cc b/src/libcephfs.cc index 288f6a7c80e69..5199855797da2 100644 --- a/src/libcephfs.cc +++ b/src/libcephfs.cc @@ -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(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)); } -- 2.39.5