Version 2.12.13
[lttng-modules.git] / lttng-abi.c
index 0996f2f198532924704266d6014ab98cd1f55318..09b14d6673d6e94ce46fc9c179e8e8b986606d82 100644 (file)
@@ -30,6 +30,7 @@
 #include <linux/uaccess.h>
 #include <linux/slab.h>
 #include <linux/err.h>
+#include <wrapper/compiler_attributes.h>
 #include <wrapper/vmalloc.h>   /* for wrapper_vmalloc_sync_mappings() */
 #include <wrapper/ringbuffer/vfs.h>
 #include <wrapper/ringbuffer/backend.h>
@@ -52,7 +53,7 @@
 
 static struct proc_dir_entry *lttng_proc_dentry;
 
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,6,0))
+#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,6,0))
 static const struct proc_ops lttng_proc_ops;
 #else
 static const struct file_operations lttng_proc_ops;
@@ -398,7 +399,7 @@ long lttng_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
        }
 }
 
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,6,0))
+#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,6,0))
 static const struct proc_ops lttng_proc_ops = {
        .proc_ioctl = lttng_ioctl,
 #ifdef CONFIG_COMPAT
@@ -881,7 +882,8 @@ long lttng_metadata_ring_buffer_ioctl(struct file *filp,
                 */
                return -ENOSYS;
        }
-       case RING_BUFFER_FLUSH_EMPTY:   /* Fall-through. */
+       case RING_BUFFER_FLUSH_EMPTY:
+               lttng_fallthrough;
        case RING_BUFFER_FLUSH:
        {
                struct lttng_metadata_stream *stream = filp->private_data;
@@ -990,7 +992,8 @@ long lttng_metadata_ring_buffer_compat_ioctl(struct file *filp,
                 */
                return -ENOSYS;
        }
-       case RING_BUFFER_FLUSH_EMPTY:   /* Fall-through. */
+       case RING_BUFFER_FLUSH_EMPTY:
+               lttng_fallthrough;
        case RING_BUFFER_FLUSH:
        {
                struct lttng_metadata_stream *stream = filp->private_data;
@@ -1090,8 +1093,12 @@ int lttng_metadata_ring_buffer_release(struct inode *inode, struct file *file)
        struct lttng_metadata_stream *stream = file->private_data;
        struct lib_ring_buffer *buf = stream->priv;
 
+       mutex_lock(&stream->metadata_cache->lock);
+       list_del(&stream->list);
+       mutex_unlock(&stream->metadata_cache->lock);
        kref_put(&stream->metadata_cache->refcount, metadata_cache_destroy);
        module_put(stream->transport->owner);
+       kfree(stream);
        return lib_ring_buffer_release(inode, file, buf);
 }
 
@@ -1243,8 +1250,10 @@ int lttng_abi_open_metadata_stream(struct file *channel_file)
        if (ret < 0)
                goto fd_error;
 
+       mutex_lock(&session->metadata_cache->lock);
        list_add(&metadata_stream->list,
                &session->metadata_cache->metadata_stream);
+       mutex_unlock(&session->metadata_cache->lock);
        return ret;
 
 fd_error:
@@ -1258,6 +1267,51 @@ nomem:
        return ret;
 }
 
+static
+int lttng_abi_validate_event_param(struct lttng_kernel_event *event_param)
+{
+       /* Limit ABI to implemented features. */
+       switch (event_param->instrumentation) {
+       case LTTNG_KERNEL_SYSCALL:
+               switch (event_param->u.syscall.entryexit) {
+               case LTTNG_KERNEL_SYSCALL_ENTRYEXIT:
+                       break;
+               default:
+                       return -EINVAL;
+               }
+               switch (event_param->u.syscall.abi) {
+               case LTTNG_KERNEL_SYSCALL_ABI_ALL:
+                       break;
+               default:
+                       return -EINVAL;
+               }
+               switch (event_param->u.syscall.match) {
+               case LTTNG_SYSCALL_MATCH_NAME:
+                       break;
+               default:
+                       return -EINVAL;
+               }
+               break;
+
+       case LTTNG_KERNEL_TRACEPOINT:
+               lttng_fallthrough;
+       case LTTNG_KERNEL_KPROBE:
+               lttng_fallthrough;
+       case LTTNG_KERNEL_KRETPROBE:
+               lttng_fallthrough;
+       case LTTNG_KERNEL_NOOP:
+               lttng_fallthrough;
+       case LTTNG_KERNEL_UPROBE:
+               break;
+
+       case LTTNG_KERNEL_FUNCTION:
+               lttng_fallthrough;
+       default:
+               return -EINVAL;
+       }
+       return 0;
+}
+
 static
 int lttng_abi_create_event(struct file *channel_file,
                           struct lttng_kernel_event *event_param)
@@ -1299,6 +1353,9 @@ int lttng_abi_create_event(struct file *channel_file,
                ret = -EOVERFLOW;
                goto refcount_error;
        }
+       ret = lttng_abi_validate_event_param(event_param);
+       if (ret)
+               goto event_error;
        if (event_param->instrumentation == LTTNG_KERNEL_TRACEPOINT
                        || event_param->instrumentation == LTTNG_KERNEL_SYSCALL) {
                struct lttng_enabler *enabler;
This page took 0.024859 seconds and 4 git commands to generate.