From mboxrd@z Thu Jan 1 00:00:00 1970 From: Cyrill Gorcunov Subject: [PATCH] kvm tool: Make kvm structure to carry name copy Date: Fri, 3 Feb 2012 23:57:15 +0400 Message-ID: <20120203195715.GF3314@moon> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii To: Pekka Enberg , Sasha Levin , Asias He , Ingo Molnar , KVM-ML Return-path: Received: from mail-bk0-f46.google.com ([209.85.214.46]:62925 "EHLO mail-bk0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753359Ab2BCT5U (ORCPT ); Fri, 3 Feb 2012 14:57:20 -0500 Received: by bkcjm19 with SMTP id jm19so3362812bkc.19 for ; Fri, 03 Feb 2012 11:57:18 -0800 (PST) Content-Disposition: inline Sender: kvm-owner@vger.kernel.org List-ID: If guest name is used (which is default case) the kvm might end up carrying the pointer to name which is allocated on stack. kvm_cmd_run_init (on stack) default_name kvm__init(..., default_name) kvm->name = default_name So I think better to allow kvm to carry own copy of guest name. 64 symbols should be more than enough. Signed-off-by: Cyrill Gorcunov --- I hope I didn't miss anything? tools/kvm/kvm.c | 2 +- tools/kvm/powerpc/include/kvm/kvm-arch.h | 2 +- tools/kvm/x86/include/kvm/kvm-arch.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) Index: linux-2.6.git/tools/kvm/kvm.c =================================================================== --- linux-2.6.git.orig/tools/kvm/kvm.c +++ linux-2.6.git/tools/kvm/kvm.c @@ -384,7 +384,7 @@ struct kvm *kvm__init(const char *kvm_de kvm__arch_init(kvm, hugetlbfs_path, ram_size); - kvm->name = name; + strncpy(kvm->name, name, sizeof(kvm->name)); kvm_ipc__start(kvm__create_socket(kvm)); kvm_ipc__register_handler(KVM_IPC_PID, kvm__pid); Index: linux-2.6.git/tools/kvm/powerpc/include/kvm/kvm-arch.h =================================================================== --- linux-2.6.git.orig/tools/kvm/powerpc/include/kvm/kvm-arch.h +++ linux-2.6.git/tools/kvm/powerpc/include/kvm/kvm-arch.h @@ -64,7 +64,7 @@ struct kvm { unsigned long fdt_gra; unsigned long initrd_gra; unsigned long initrd_size; - const char *name; + char name[64]; int vm_state; }; Index: linux-2.6.git/tools/kvm/x86/include/kvm/kvm-arch.h =================================================================== --- linux-2.6.git.orig/tools/kvm/x86/include/kvm/kvm-arch.h +++ linux-2.6.git/tools/kvm/x86/include/kvm/kvm-arch.h @@ -48,7 +48,7 @@ struct kvm { struct disk_image **disks; int nr_disks; - const char *name; + char name[64]; int vm_state; };