From patchwork Mon Jan 2 18:04:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 38175 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp4262380wrt; Mon, 2 Jan 2023 10:05:52 -0800 (PST) X-Google-Smtp-Source: AMrXdXvQqgaIMAdLWcVYD9s06LrZ32eso6iQfRLD7Ug9DmAhF2OW+ZCqK9azTlhAk0jbWGJhTgKt X-Received: by 2002:a05:6a00:2295:b0:581:5523:574d with SMTP id f21-20020a056a00229500b005815523574dmr6354856pfe.0.1672682751868; Mon, 02 Jan 2023 10:05:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672682751; cv=none; d=google.com; s=arc-20160816; b=mTCzk0vRcOsA+oR0dDb5JWwExDltelUdX4SJcvcaFZiVR/4q7v3iCXqF+CE5+pLBba Eg+IPxQ/GFbhL+DJNJ7SuZoAuERjYppkREOTXiK6VdGh5/1HOYlV5jevZRbWZWDtChJf Dc+8lSIYug6kt7d6IVSxhTes18lFcOOHNQcL8lMJJ8cQTKxHPioAGXp9RaohPQ9mEPVb 7SCvjtn9txPgZMuslnaTsgM6GGbKcPWsgxgK+Zb9FDL4lrCZifGDIaHQ4XbCAgHjm3OH GPE5JtpJ7w/GvGKYTyKHifffeAVhhEpyVp6Rj1cOD/ZmEsRUvUqWi7Xy8qiVQ/4RKkro e8Bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=dgKCXWkN7D8Vg195mJtIF+wUSL0imvOrcDn3Mz+6ocs=; b=xJ2qPUTIKg/ArEXuO43lTtI3X8LLknL6Po+2EfItT991Yxk9pQCtODXPZYvJjC5Y4B X5PX3qVKiMoRdqnlgq5Y7y7JEVWzlQ1zFD3k9XUe3olX/JIe9xHuafTNq2USJrWCJfaK vnj3eUOHlJK44mxCpkykgCGDKOVKbt5UN0pgH/3GAS5lXtJ85m8Va5GTK0KXeHAPZeqd YbijIMePKZNIHM892DoX05MpY2FwGthupeu5PEC5XTMthAMW6uvA9MbZA2bPhuCVGwdJ 7Ve+LmLfAhdNbHnzxnOHEjAqrMRzfeA/jHT22IGx7mIa1k+qa/sSCFYOMpTS6Hn6Tpdx acKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=XTwnaTJi; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p26-20020a056a000a1a00b005768619bd8esi32323364pfh.177.2023.01.02.10.05.39; Mon, 02 Jan 2023 10:05:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=XTwnaTJi; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236467AbjABSEs (ORCPT + 99 others); Mon, 2 Jan 2023 13:04:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236454AbjABSEc (ORCPT ); Mon, 2 Jan 2023 13:04:32 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08AA4BF71; Mon, 2 Jan 2023 10:04:18 -0800 (PST) Date: Mon, 02 Jan 2023 18:04:15 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1672682656; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dgKCXWkN7D8Vg195mJtIF+wUSL0imvOrcDn3Mz+6ocs=; b=XTwnaTJijdkAETCDOlgxzeUpPCLlUVoBrj9LKH8JSswCopF5mmPDTB2csg7Oh3DnnDOaiW k6U2JWU0i7Ow5hkobVWJKArPElSXzpMVgKbpXhmAUOZbLhklyg7RiIVO6YEh8UPt1fxTjQ pulpwNAdziO/N6ba3U2WBubxxD6EephJr0ZxDFmu9A6sDnf4Bptxn57Z7pK1/bt+ATtS4j CgN1NwxpB39B2N1UKZBcZh73ujshmb7xDBVLD3oH1ZrnB9On1KQ4UeVsXUI52IwMXC+T8a LQtvr7TDXPAhutQDhCsrtUsDfHJWBD4LlzvPKhw9hnXr/ElK4wOtN3bMTI5FgQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1672682656; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dgKCXWkN7D8Vg195mJtIF+wUSL0imvOrcDn3Mz+6ocs=; b=36BKUqqbDT2mfBN84y+MMIO3vC/TFvwzm5Ix81tRFdzfiRtH40hbtBuaozbrsn9FPNRsBk yvj1jOskWh6iX+BA== From: "tip-bot2 for Takashi Iwai" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/urgent] x86/kexec: Fix double-free of elf header buffer Cc: Takashi Iwai , "Borislav Petkov (AMD)" , Baoquan He , Vlastimil Babka , , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20221122115122.13937-1-tiwai@suse.de> References: <20221122115122.13937-1-tiwai@suse.de> MIME-Version: 1.0 Message-ID: <167268265568.4906.5498168349735742588.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750198103793349046?= X-GMAIL-MSGID: =?utf-8?q?1753934989284650952?= The following commit has been merged into the x86/urgent branch of tip: Commit-ID: d00dd2f2645dca04cf399d8fc692f3f69b6dd996 Gitweb: https://git.kernel.org/tip/d00dd2f2645dca04cf399d8fc692f3f69b6dd996 Author: Takashi Iwai AuthorDate: Tue, 22 Nov 2022 12:51:22 +01:00 Committer: Borislav Petkov (AMD) CommitterDate: Mon, 02 Jan 2023 18:56:21 +01:00 x86/kexec: Fix double-free of elf header buffer After b3e34a47f989 ("x86/kexec: fix memory leak of elf header buffer"), freeing image->elf_headers in the error path of crash_load_segments() is not needed because kimage_file_post_load_cleanup() will take care of that later. And not clearing it could result in a double-free. Drop the superfluous vfree() call at the error path of crash_load_segments(). Fixes: b3e34a47f989 ("x86/kexec: fix memory leak of elf header buffer") Signed-off-by: Takashi Iwai Signed-off-by: Borislav Petkov (AMD) Acked-by: Baoquan He Acked-by: Vlastimil Babka Cc: Link: https://lore.kernel.org/r/20221122115122.13937-1-tiwai@suse.de --- arch/x86/kernel/crash.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c index 9730c88..3055144 100644 --- a/arch/x86/kernel/crash.c +++ b/arch/x86/kernel/crash.c @@ -401,10 +401,8 @@ int crash_load_segments(struct kimage *image) kbuf.buf_align = ELF_CORE_HEADER_ALIGN; kbuf.mem = KEXEC_BUF_MEM_UNKNOWN; ret = kexec_add_buffer(&kbuf); - if (ret) { - vfree((void *)image->elf_headers); + if (ret) return ret; - } image->elf_load_addr = kbuf.mem; pr_debug("Loaded ELF headers at 0x%lx bufsz=0x%lx memsz=0x%lx\n", image->elf_load_addr, kbuf.bufsz, kbuf.memsz);