libceph: add an ONSTACK initializer for oids
authorIlya Dryomov <idryomov@gmail.com>
Tue, 26 Jul 2016 13:22:35 +0000 (15:22 +0200)
committerIlya Dryomov <idryomov@gmail.com>
Thu, 28 Jul 2016 00:55:35 +0000 (02:55 +0200)
An on-stack oid in ceph_ioctl_get_dataloc() is not initialized,
resulting in a WARN and a NULL pointer dereference later on.  We will
have more of these on-stack in the future, so fix it with a convenience
macro.

Fixes: d30291b985d1 ("libceph: variable-sized ceph_object_id")
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
fs/ceph/ioctl.c
include/linux/ceph/osdmap.h

index be6b1657b1af2aa98eb70d614c45b2e2c556b009..0946f2d4a81fa2f338e754ae1e5acc324b720162 100644 (file)
@@ -183,7 +183,7 @@ static long ceph_ioctl_get_dataloc(struct file *file, void __user *arg)
        struct ceph_osd_client *osdc =
                &ceph_sb_to_client(inode->i_sb)->client->osdc;
        struct ceph_object_locator oloc;
-       struct ceph_object_id oid;
+       CEPH_DEFINE_OID_ONSTACK(oid);
        u64 len = 1, olen;
        u64 tmp;
        struct ceph_pg pgid;
index 9ccf4dbe55f81722c6507fdcd76ab92417525438..21d7f048959f1baad8dbc8ea6b56244f16b2e968 100644 (file)
@@ -115,6 +115,11 @@ static inline void ceph_oid_init(struct ceph_object_id *oid)
        oid->name_len = 0;
 }
 
+#define CEPH_OID_INIT_ONSTACK(oid)                                     \
+    ({ ceph_oid_init(&oid); oid; })
+#define CEPH_DEFINE_OID_ONSTACK(oid)                                   \
+       struct ceph_object_id oid = CEPH_OID_INIT_ONSTACK(oid)
+
 static inline bool ceph_oid_empty(const struct ceph_object_id *oid)
 {
        return oid->name == oid->inline_name && !oid->name_len;