Re: [PATCH] usermodehelper: Fix -ENOMEM return logic

From: David Howells
Date: Mon Feb 25 2013 - 10:05:24 EST

Lucas De Marchi <lucas.demarchi@xxxxxxxxxxxxxx> wrote:

> Callers of call_usermodehelper_fns() should check the return value and
> free themselves the data passed if the return is -ENOMEM. This is
> because the subprocess_info is allocated in this function, and if the
> allocation fail, the cleanup function cannot be called.
> However call_usermodehelper_exec() may also return -ENOMEM, in which
> case the cleanup function is called. This means that if the caller
> checked the return code, it was risking running the cleanup twice (like
> kernel/sys.c:orderly_poweroff()) and if not, a leak could happen.
> This patch fixes both call_usermodehelper_fns() to never call the
> cleanup function in case retval == -ENOMEM and also the callers to
> actually check the return value of this function.

I suspect it's probably better to always call the cleanup function from
call_usermodehelper_fns() rather than have the cleanup done by the caller in
some circumstances and not others - would it make sense to change the cleanup
function to take the pointer to the caller data rather than to take the
subprocess_info struct?

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at