From: Oleg Nesterov <oleg@redhat.com>
To: Lucas De Marchi <lucas.demarchi@profusion.mobi>
Cc: linux-kernel@vger.kernel.org, David Howells <dhowells@redhat.com>,
James Morris <james.l.morris@oracle.com>,
Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH] usermodehelper: Fix -ENOMEM return logic
Date: Mon, 25 Feb 2013 17:06:42 +0100 [thread overview]
Message-ID: <20130225160642.GA31806@redhat.com> (raw)
In-Reply-To: <1361802350-9299-1-git-send-email-lucas.demarchi@profusion.mobi>
On 02/25, Lucas De Marchi 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.
Yes, this is confusing.
> However call_usermodehelper_exec() may also return -ENOMEM,
Yes, and we can't distinguish this case from info == NULL case,
> 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.
In short: every user of call_usermodehelper_fns(cleanup != NULL)
is buggy. Thanks.
But I am not sure I agree with the patch...
> static void call_usermodehelper_freeinfo(struct subprocess_info *info)
> {
> - if (info->cleanup)
> + if (info->cleanup && info->retval != -ENOMEM)
> (*info->cleanup)(info);
> kfree(info);
> }
This doesn't look very clean/robust. And in general, personally I
dislike the fact that ENOMEM has the special meaning. IOW, I think
we should cleanup this logic, not to complicate it more.
And in fact I do not think this is right, at least in UMH_NO_WAIT
case, shouldn't avoid ->cleanup() if, say, prepare_kernel_cred()
fails in ____call_usermodehelper()...
I think we should extract call_usermodehelper_setup() +
call_usermodehelper_setfns() into the new helper and export it.
And export call_usermodehelper_exec() as well.
call_usermodehelper_setfns() as a separate function makes no sense.
Then we can fix call_modprobe/orderly_poweroff, something like below.
What do you think?
Oleg.
--- x/kernel/kmod.c
+++ x/kernel/kmod.c
@@ -98,8 +98,14 @@ static int call_modprobe(char *module_na
argv[3] = module_name; /* check free_modprobe_argv() */
argv[4] = NULL;
- return call_usermodehelper_fns(modprobe_path, argv, envp,
- wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
+ info = call_usermodehelper_setup(...); // better name, please...
+ if (!info)
+ goto free_modname;
+
+ return call_usermodehelper_exec(info, wait);
+
+free_modname:
+ kfree(module_name);
free_argv:
kfree(argv);
out:
next prev parent reply other threads:[~2013-02-25 16:08 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-25 14:25 [PATCH] usermodehelper: Fix -ENOMEM return logic Lucas De Marchi
2013-02-25 15:05 ` David Howells
2013-02-25 16:51 ` Oleg Nesterov
2013-02-25 16:06 ` Oleg Nesterov [this message]
2013-02-25 17:38 ` Lucas De Marchi
2013-02-25 18:08 ` Oleg Nesterov
2013-03-07 2:05 ` Lucas De Marchi
2013-03-07 19:37 ` Oleg Nesterov
2013-03-07 19:47 ` Lucas De Marchi
2013-03-07 20:07 ` Oleg Nesterov
2013-03-07 21:35 ` Lucas De Marchi
2013-02-25 17:10 ` [PATCH 0/1] usermodehelper: cleanup/fix __orderly_poweroff() && argv_free() Oleg Nesterov
2013-02-25 17:11 ` [PATCH 1/1] " Oleg Nesterov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130225160642.GA31806@redhat.com \
--to=oleg@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=dhowells@redhat.com \
--cc=james.l.morris@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lucas.demarchi@profusion.mobi \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.