Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp5761975rwb; Tue, 22 Nov 2022 04:44:59 -0800 (PST) X-Google-Smtp-Source: AA0mqf4BJ6W0F+IJImu8y7j/ylBwxaw9gz0qH7b7UD8Q3uRzT554wlIDYIxUofqQJ+eSq73pkKNS X-Received: by 2002:a17:902:d650:b0:189:f86:ecb with SMTP id y16-20020a170902d65000b001890f860ecbmr14609526plh.45.1669121099376; Tue, 22 Nov 2022 04:44:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669121099; cv=none; d=google.com; s=arc-20160816; b=CshulEMO7ErP92WeGqIQkLcbdw5YcGAYgLLojKc9tn0iH50Xyt/lZTNNEJim5wqV/s 3zLWhWN9+hrHHp6kw4cX3zPvwm7gG2gHsut+RskOblyeGJqfrfBI0yRDEluz4W6fc3ac 7AZhvnKqNMFeKJloUgr8iSk2kMMqNhxrRHraqcWbnv60moTSs7pwkbtAX1sMykx23WUg muyKBp6+4v8skhd7dhxTXbDcLXb7GuPEKn0qHHg1Bw+PMa/EEALiEN0EDuvlyLuIz37g Bd0BQ6pxiKhzxdS8saYzS9eil0Ll4yxK9KTkpe3iMMEt41G2lAmOdBsR538JxCVTLVKc mxZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature:dkim-signature; bh=pizNmII+kH90P+wFkDN3Lxn3VPpzAwqATNwsGxqqK60=; b=TCncaBo6c+AFzJsgYg3qt34AFFlrbLvjuCeVj4Pfu7cIFuBfD/+4mp4+dRE2s3pLgL 29q/HjtNULugFCxR+CkXh1SKdA2HmIKb6ob1a8LLJvF5/Co+s8cyNwIsVRsZLX9XEMZ6 u9eFzmEhztZU8fxXY35ZIweqV9UI/PNBwrh4jmoinbN7dzAgy+ERl+rRnvccxmg2q/vg Jt1AFEwgqIjapr+J5nVnWq4Fb844VlwREbDta5Th7poA4S8L4MjDvsSZ3qbSJ5+6FcN6 vc4/+Fr7lqYdR7RXdpYLi0j6nh/T+gvgwIHPBRMnGIQ45fj+zHxA/BeRWrrpbGaYHNye 9pNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=XmiMVJbI; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; 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=NONE dis=NONE) header.from=suse.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m21-20020a170902e41500b0017f9db0233fsi11506511ple.448.2022.11.22.04.44.47; Tue, 22 Nov 2022 04:44:59 -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=@suse.de header.s=susede2_rsa header.b=XmiMVJbI; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; 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=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233407AbiKVLv3 (ORCPT + 90 others); Tue, 22 Nov 2022 06:51:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232465AbiKVLv1 (ORCPT ); Tue, 22 Nov 2022 06:51:27 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21D4D178A4 for ; Tue, 22 Nov 2022 03:51:27 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 0C41C1F86B; Tue, 22 Nov 2022 11:51:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1669117885; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=pizNmII+kH90P+wFkDN3Lxn3VPpzAwqATNwsGxqqK60=; b=XmiMVJbIHB7sx62hDnd/0pdiGvcygkdqeYqiGgXH0Zc0SF57nqZdyw9CavqXcxSqJ4xfhG U7243p+Ce6aUOzTIJUmN8pZKGI9PcuqgsrDvRPJBz5f4RzIpOjEvJjx8faLYfC/uUg9wT4 5tL+jWQUkZsuVrPsRwqU2fE8ioGXOxk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1669117885; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=pizNmII+kH90P+wFkDN3Lxn3VPpzAwqATNwsGxqqK60=; b=TgUyRD1O+BUA8QsRUaves7GWLZEQQIziOiEA6Syxj4CU2s2wHksssPiSoHxodOIEYGse42 1S56pgfAPrwJolBA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id CDDE013AA1; Tue, 22 Nov 2022 11:51:24 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ecJ2Mby3fGOQEgAAMHmgww (envelope-from ); Tue, 22 Nov 2022 11:51:24 +0000 From: Takashi Iwai To: x86@kernel.org Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Baoquan He , Andrew Morton , linux-kernel@vger.kernel.org Subject: [PATCH] x86/kexec: Fix double-free of elf header buffer Date: Tue, 22 Nov 2022 12:51:22 +0100 Message-Id: <20221122115122.13937-1-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 The recent fix for memory leaks forgot to clear the error path that already does vfree() for the elf headers. This may 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 --- 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 9730c88530fc..305514431f26 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); -- 2.35.3