Re: [PATCH] kernel/nsproxy.c: Fix memory leak of create_new_namespaces().

From: wzt wzt
Date: Tue Oct 18 2011 - 03:19:59 EST


Sorry for the wrong patch, thanks Feng to point it out.

On Tue, Oct 18, 2011 at 2:26 PM, Xiaotian Feng <xtfeng@xxxxxxxxx> wrote:
>
>
> On Tue, Oct 18, 2011 at 2:07 PM, wzt <wzt.wzt@xxxxxxxxx> wrote:
>>
>> copy_pid_ns() has allocted some memory via create_pid_namespace(), if
>> copy_net_ns()
>> failed via create_new_namespaces(), it will cause memory leak. The
>> copy_utsname()
>> have the same problem.
>>
>> Signed-off-by: Zhitong Wang <zhitong.wangzt@xxxxxxxxxxxxxxx>
>>
>> ---
>> Âkernel/nsproxy.c | Â Â8 ++++++--
>> Â1 files changed, 6 insertions(+), 2 deletions(-)
>>
>> diff --git a/kernel/nsproxy.c b/kernel/nsproxy.c
>> index 9aeab4b..fdcec31 100644
>> --- a/kernel/nsproxy.c
>> +++ b/kernel/nsproxy.c
>> @@ -99,14 +99,18 @@ static struct nsproxy *create_new_namespaces(unsigned
>> long flags,
>> Â Â Â Âreturn new_nsp;
>>
>> Âout_net:
>> - Â Â Â if (new_nsp->pid_ns)
>> + Â Â Â if (new_nsp->pid_ns) {
>> Â Â Â Â Â Â Â Âput_pid_ns(new_nsp->pid_ns);
>> + Â Â Â Â Â Â Â free_pid_ns(&new_nsp->pid_ns->kref);
>
> It is freed in put_pid_ns() if the last user is gone. Please check the
> implementation of put_pid_ns().
>
>>
>> + Â Â Â }
>> Âout_pid:
>> Â Â Â Âif (new_nsp->ipc_ns)
>> Â Â Â Â Â Â Â Âput_ipc_ns(new_nsp->ipc_ns);
>> Âout_ipc:
>> - Â Â Â if (new_nsp->uts_ns)
>> + Â Â Â if (new_nsp->uts_ns) {
>> Â Â Â Â Â Â Â Âput_uts_ns(new_nsp->uts_ns);
>> + Â Â Â Â Â Â Â free_uts_ns(&new_nsp->pid_ns->kref);
>
> Âsame
>>
>> + Â Â Â }
>> Âout_uts:
>> Â Â Â Âif (new_nsp->mnt_ns)
>> Â Â Â Â Â Â Â Âput_mnt_ns(new_nsp->mnt_ns);
>> --
>> 1.7.4.1
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>> the body of a message to majordomo@xxxxxxxxxxxxxxx
>> More majordomo info at Âhttp://vger.kernel.org/majordomo-info.html
>> Please read the FAQ at Âhttp://www.tux.org/lkml/
>
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/