Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp729392imm; Thu, 13 Sep 2018 06:56:57 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbVAIHXOEUQxl/0wM0cD8PWf7IzsRXkfHkGVacHa9Zkp7H+dwbzAamS8GSm4xDDkvAvHQg+ X-Received: by 2002:a17:902:d706:: with SMTP id w6-v6mr7533943ply.158.1536847017628; Thu, 13 Sep 2018 06:56:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536847017; cv=none; d=google.com; s=arc-20160816; b=dQiShJXVHk7yeeDSVeo+AvD5oFa+amOI9G9cOrzhiO5Ge15bcDEggGWdZLi8i3q++l tONxVaA0fD18WgA3LDFYhiqTlE6A/S8+2UZEOZCAvLvQDOtFjsop3rzVT/4ND/XlwekX YMoHk1McWN2E41um1yHwaKk/C3NPo5xvUUKuSd2mgLrcgHkzDyuRtHM4KK4uqO0OMJgk +jgTQ+xGtJ/TFXUp1H5ZlpubGR7S/YrPRQV3MiI8unf2EjxF7DzhlwJXCKZSHDxFBXZV eroEtYePq/t2HrG2eMGEZthvAo5J6mfRBqQhnUwkH/+ebotzbZeUMx03mmfL/ZOUHwxD D7Mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=gqtlBhUZ3nbLVc//S8Yd80Neg9/WA+gCTA3oog/Fw2M=; b=KN4lJBQxLVBtcDFvi1KOHA+YXyMF44ESwl42kwN2Ylh+X422D1JExE9vg/2PVCgFTZ 3wYAQxVWNqatVnbsoyaNBXJnm4AWW5NU55z3DsmjmGMRH2QcVk1Mnc3R3qrPlycZVWiB JaA6JcJW7aqhbAVosUfODr8v/PQ+B7jmVTKufv7CeA/iSNCFN/5oz+ytBuIJ5dS292r/ +Xgt7ass0E7Sc4QcTFzn9uzmviZyMhJDM9OJwgKixzFKBrHXfJa5SEsLOp1hUpnI0VOF U7LJWQ9eSkNMSDQdbu7YBwKl3xGJUOGpsSR0zRRml9mxJ6F+EO1+jsFKQFYtq3/bqPBu eN/A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a95-v6si4214877pla.514.2018.09.13.06.56.42; Thu, 13 Sep 2018 06:56:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731139AbeIMTE6 (ORCPT + 99 others); Thu, 13 Sep 2018 15:04:58 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:33970 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727783AbeIMTE6 (ORCPT ); Thu, 13 Sep 2018 15:04:58 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 7CF6BCE7; Thu, 13 Sep 2018 13:55:21 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Philipp Rudo , Heiko Carstens , Sasha Levin Subject: [PATCH 4.18 070/197] s390/kdump: Fix memleak in nt_vmcoreinfo Date: Thu, 13 Sep 2018 15:30:19 +0200 Message-Id: <20180913131844.322845048@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180913131841.568116777@linuxfoundation.org> References: <20180913131841.568116777@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Philipp Rudo [ Upstream commit 2d2e7075b87181ed0c675e4936e20bdadba02e1f ] The vmcoreinfo of a crashed system is potentially fragmented. Thus the crash kernel has an intermediate step where the vmcoreinfo is copied into a temporary, continuous buffer in the crash kernel memory. This temporary buffer is never freed. Free it now to prevent the memleak. While at it replace all occurrences of "VMCOREINFO" by its corresponding macro to prevent potential renaming issues. Signed-off-by: Philipp Rudo Acked-by: Heiko Carstens Signed-off-by: Heiko Carstens Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- arch/s390/kernel/crash_dump.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) --- a/arch/s390/kernel/crash_dump.c +++ b/arch/s390/kernel/crash_dump.c @@ -404,11 +404,13 @@ static void *get_vmcoreinfo_old(unsigned if (copy_oldmem_kernel(nt_name, addr + sizeof(note), sizeof(nt_name) - 1)) return NULL; - if (strcmp(nt_name, "VMCOREINFO") != 0) + if (strcmp(nt_name, VMCOREINFO_NOTE_NAME) != 0) return NULL; vmcoreinfo = kzalloc_panic(note.n_descsz); - if (copy_oldmem_kernel(vmcoreinfo, addr + 24, note.n_descsz)) + if (copy_oldmem_kernel(vmcoreinfo, addr + 24, note.n_descsz)) { + kfree(vmcoreinfo); return NULL; + } *size = note.n_descsz; return vmcoreinfo; } @@ -418,15 +420,20 @@ static void *get_vmcoreinfo_old(unsigned */ static void *nt_vmcoreinfo(void *ptr) { + const char *name = VMCOREINFO_NOTE_NAME; unsigned long size; void *vmcoreinfo; vmcoreinfo = os_info_old_entry(OS_INFO_VMCOREINFO, &size); - if (!vmcoreinfo) - vmcoreinfo = get_vmcoreinfo_old(&size); + if (vmcoreinfo) + return nt_init_name(ptr, 0, vmcoreinfo, size, name); + + vmcoreinfo = get_vmcoreinfo_old(&size); if (!vmcoreinfo) return ptr; - return nt_init_name(ptr, 0, vmcoreinfo, size, "VMCOREINFO"); + ptr = nt_init_name(ptr, 0, vmcoreinfo, size, name); + kfree(vmcoreinfo); + return ptr; } /*