]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Don't allocate xlat function memory directly in the context we were passed
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sun, 12 May 2024 16:51:30 +0000 (10:51 -0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sun, 12 May 2024 17:13:38 +0000 (11:13 -0600)
This memory can be mprotected, and when the xlat functions get balanced in the rbtree we get a SEGV

src/lib/unlang/xlat_func.c

index 569fce16227232f5206e113de408970a04828f47..91a1f4a396b60a1063f8947fdcfc9b1f3598c384 100644 (file)
@@ -239,13 +239,21 @@ xlat_t *xlat_func_register(TALLOC_CTX *ctx, char const *name, xlat_func_t func,
        /*
         *      Doesn't exist.  Create it.
         */
-       MEM(c = talloc(ctx, xlat_t));
+       MEM(c = talloc(NULL, xlat_t));
        *c = (xlat_t){
                .name = talloc_typed_strdup(c, name),
                .func = func,
                .return_type = return_type,
                .input_type = XLAT_INPUT_UNPROCESSED    /* set default - will be overridden if args are registered */
        };
+
+       /*
+        *      Don't allocate directly in the parent ctx, it might be mprotected
+        *      later, and that'll cause segfaults if any of the xlat_t are still
+        *      protected when we start shuffling the contents of the rbtree.
+        */
+       if (ctx) talloc_link_ctx(c, ctx);
+
        talloc_set_destructor(c, _xlat_func_talloc_free);
        DEBUG3("%s: %s", __FUNCTION__, c->name);