#733 Memory leak of library handle in proxy
Closed: Fixed None Opened 13 years ago by sgallagh.

   90int sssm_proxy_id_init(struct be_ctx *bectx,
   91                       struct bet_ops **ops, void **pvt_data)
   92{
   93    struct proxy_id_ctx *ctx;
   94    char *libname;
   95    char *libpath;
   96    void *handle;
   97    int ret;
   98
   99    ctx = talloc_zero(bectx, struct proxy_id_ctx);
  100    if (!ctx) {
  101        return ENOMEM;
  102    }
  103    ctx->be = bectx;
  104
  105    ret = confdb_get_int(bectx->cdb, ctx, bectx->conf_path,
  106                         CONFDB_DOMAIN_ENTRY_CACHE_TIMEOUT, 600,
  107                         &ctx->entry_cache_timeout);
  108    if (ret != EOK) goto done;
  109
  110    ret = confdb_get_string(bectx->cdb, ctx, bectx->conf_path,
  111                            CONFDB_PROXY_LIBNAME, NULL, &libname);
  112    if (ret != EOK) goto done;
  113    if (libname == NULL) {
  114        ret = ENOENT;
  115        goto done;
  116    }
  117
  118    libpath = talloc_asprintf(ctx, "libnss_%s.so.2", libname);
  119    if (!libpath) {
  120        ret = ENOMEM;
  121        goto done;
  122    }
  123
Calling allocation function "dlopen".
Assigning: "handle" = storage returned from "dlopen(libpath, 2)".
  124    handle = dlopen(libpath, RTLD_NOW);
At conditional (1): "!handle" taking the false branch.
  125    if (!handle) {
  126        DEBUG(0, ("Unable to load %s module with path, error: %s\n",
  127                  libpath, dlerror()));
  128        ret = ELIBACC;
  129        goto done;
  130    }
  131
Variable "handle" is not freed or pointed-to in function "proxy_dlsym". [show details]
  132    ctx->ops.getpwnam_r = proxy_dlsym(handle, "_nss_%s_getpwnam_r", libname);
At conditional (2): "!ctx->ops.getpwnam_r" taking the true branch.
  133    if (!ctx->ops.getpwnam_r) {
At conditional (3): "0 <= debug_level" taking the true branch.
At conditional (4): "debug_timestamps" taking the true branch.
  134        DEBUG(0, ("Failed to load NSS fns, error: %s\n", dlerror()));
  135        ret = ELIBBAD;
  136        goto done;
  137    }
  138
Variable "handle" is not freed or pointed-to in function "proxy_dlsym". [show details]
  139    ctx->ops.getpwuid_r = proxy_dlsym(handle, "_nss_%s_getpwuid_r", libname);
  140    if (!ctx->ops.getpwuid_r) {
  141        DEBUG(0, ("Failed to load NSS fns, error: %s\n", dlerror()));
  142        ret = ELIBBAD;
  143        goto done;
  144    }
  145
Variable "handle" is not freed or pointed-to in function "proxy_dlsym". [show details]
  146    ctx->ops.setpwent = proxy_dlsym(handle, "_nss_%s_setpwent", libname);
  147    if (!ctx->ops.setpwent) {
  148        DEBUG(0, ("Failed to load NSS fns, error: %s\n", dlerror()));
  149        ret = ELIBBAD;
  150        goto done;
  151    }
  152
Variable "handle" is not freed or pointed-to in function "proxy_dlsym". [show details]
  153    ctx->ops.getpwent_r = proxy_dlsym(handle, "_nss_%s_getpwent_r", libname);
  154    if (!ctx->ops.getpwent_r) {
  155        DEBUG(0, ("Failed to load NSS fns, error: %s\n", dlerror()));
  156        ret = ELIBBAD;
  157        goto done;
  158    }
  159
Variable "handle" is not freed or pointed-to in function "proxy_dlsym". [show details]
  160    ctx->ops.endpwent = proxy_dlsym(handle, "_nss_%s_endpwent", libname);
  161    if (!ctx->ops.endpwent) {
  162        DEBUG(0, ("Failed to load NSS fns, error: %s\n", dlerror()));
  163        ret = ELIBBAD;
  164        goto done;
  165    }
  166
Variable "handle" is not freed or pointed-to in function "proxy_dlsym". [show details]
  167    ctx->ops.getgrnam_r = proxy_dlsym(handle, "_nss_%s_getgrnam_r", libname);
  168    if (!ctx->ops.getgrnam_r) {
  169        DEBUG(0, ("Failed to load NSS fns, error: %s\n", dlerror()));
  170        ret = ELIBBAD;
  171        goto done;
  172    }
  173
Variable "handle" is not freed or pointed-to in function "proxy_dlsym". [show details]
  174    ctx->ops.getgrgid_r = proxy_dlsym(handle, "_nss_%s_getgrgid_r", libname);
  175    if (!ctx->ops.getgrgid_r) {
  176        DEBUG(0, ("Failed to load NSS fns, error: %s\n", dlerror()));
  177        ret = ELIBBAD;
  178        goto done;
  179    }
  180
Variable "handle" is not freed or pointed-to in function "proxy_dlsym". [show details]
  181    ctx->ops.setgrent = proxy_dlsym(handle, "_nss_%s_setgrent", libname);
  182    if (!ctx->ops.setgrent) {
  183        DEBUG(0, ("Failed to load NSS fns, error: %s\n", dlerror()));
  184        ret = ELIBBAD;
  185        goto done;
  186    }
  187
Variable "handle" is not freed or pointed-to in function "proxy_dlsym". [show details]
  188    ctx->ops.getgrent_r = proxy_dlsym(handle, "_nss_%s_getgrent_r", libname);
  189    if (!ctx->ops.getgrent_r) {
  190        DEBUG(0, ("Failed to load NSS fns, error: %s\n", dlerror()));
  191        ret = ELIBBAD;
  192        goto done;
  193    }
  194
Variable "handle" is not freed or pointed-to in function "proxy_dlsym". [show details]
  195    ctx->ops.endgrent = proxy_dlsym(handle, "_nss_%s_endgrent", libname);
  196    if (!ctx->ops.endgrent) {
  197        DEBUG(0, ("Failed to load NSS fns, error: %s\n", dlerror()));
  198        ret = ELIBBAD;
  199        goto done;
  200    }
  201
Variable "handle" is not freed or pointed-to in function "proxy_dlsym". [show details]
  202    ctx->ops.initgroups_dyn = proxy_dlsym(handle, "_nss_%s_initgroups_dyn",
  203                                                  libname);
  204    if (!ctx->ops.initgroups_dyn) {
  205        DEBUG(1, ("The '%s' library does not provides the "
  206                  "_nss_XXX_initgroups_dyn function!\n"
  207                  "initgroups will be slow as it will require "
  208                  "full groups enumeration!\n", libname));
  209    }
  210
Variable "handle" is not freed or pointed-to in function "proxy_dlsym". [show details]
  211    ctx->ops.setnetgrent = proxy_dlsym(handle, "_nss_%s_setnetgrent", libname);
  212    if (!ctx->ops.setnetgrent) {
  213        DEBUG(0, ("Failed to load _nss_%s_setnetgrent, error: %s. "
  214                  "The library does not support netgroups.\n", libname,
  215                                                               dlerror()));
  216    }
  217
Variable "handle" is not freed or pointed-to in function "proxy_dlsym". [show details]
  218    ctx->ops.getnetgrent_r = proxy_dlsym(handle, "_nss_%s_getnetgrent_r",
  219                                         libname);
  220    if (!ctx->ops.getgrent_r) {
  221        DEBUG(0, ("Failed to load _nss_%s_getnetgrent_r, error: %s. "
  222                  "The library does not support netgroups.\n", libname,
  223                                                               dlerror()));
  224    }
  225
Variable "handle" is not freed or pointed-to in function "proxy_dlsym". [show details]
  226    ctx->ops.endnetgrent = proxy_dlsym(handle, "_nss_%s_endnetgrent", libname);
  227    if (!ctx->ops.endnetgrent) {
  228        DEBUG(0, ("Failed to load _nss_%s_endnetgrent, error: %s. "
  229                  "The library does not support netgroups.\n", libname,
  230                                                               dlerror()));
  231    }
  232
  233    *ops = &proxy_id_ops;
  234    *pvt_data = ctx;
  235    ret = EOK;
  236
  237done:
At conditional (5): "ret != 0" taking the true branch.
  238    if (ret != EOK) {
  239        talloc_free(ctx);
  240    }
Variable "handle" going out of scope leaks the storage it points to.
  241    return ret;
  242}

We should just add handle to the proxy_id_ctx and add a destructor to call dlclose() on it if proxy_id_ctx is freed.


Fixed by e4c0aa4

milestone: SSSD 1.5.1 => SSSD 1.5.0
resolution: => fixed
status: new => closed

Fields changed

rhbz: => 0

Metadata Update from @sgallagh:
- Issue assigned to sbose
- Issue set to the milestone: SSSD 1.5.0

7 years ago

SSSD is moving from Pagure to Github. This means that new issues and pull requests
will be accepted only in SSSD's github repository.

This issue has been cloned to Github and is available here:
- https://github.com/SSSD/sssd/issues/1775

If you want to receive further updates on the issue, please navigate to the github issue
and click on subscribe button.

Thank you for understanding. We apologize for all inconvenience.

Login to comment on this ticket.

Metadata