Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp11632737rwl; Tue, 3 Jan 2023 02:17:17 -0800 (PST) X-Google-Smtp-Source: AMrXdXtvB5hYBQIvQOCxT0gp4J9j9Q9gqx/0KyqCRj/SDt9gwbgV2tgcJN17wpyCNzr6CBjkjKaY X-Received: by 2002:a17:907:d410:b0:7a7:9a38:d284 with SMTP id vi16-20020a170907d41000b007a79a38d284mr30280594ejc.19.1672741037428; Tue, 03 Jan 2023 02:17:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672741037; cv=none; d=google.com; s=arc-20160816; b=jl/ABYswZz2CZdRWbl0doEEunGMXbS8H2a/5KTlzeCnRAhW/sqEJ564yW8isvqZoyU 1p2Ms5vsrjHzpTmv/24D1t/RvAhUsQVH4g23B9Auw2eQvWbxApqqvCuroaMdVfn2bsDk MkobjdOGjIZg++M5281AQcTFYrJ1Qoxy0mtqY25R0qDsgfKC413SB6/92R9qZh9b3H+B Fqo9EalS/GoufeK1joMMaqfXAlgOnmGKQBY+6lgnBB2IfWFWggjnOXgoBg++wBTCQs67 91nYQCn+NZG1FozvttJG3ho+sMJUeIHHTjZPHAc5kXFpnF5gJEUh0g4ZXSSzU2G5Gje9 o45A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:sender:dkim-signature; bh=dg4Iem/pwcu+hGrCWyFWcE0w0rA2DwqUcHLBcyuPeUc=; b=IDSKkUARCouRAqPJLrec0RUVHIvFVUfc5hJicxr8n4cqR3HJMPzTbQbIMvxqChrjTv joqBkl0ecnWv/ydcrqxdiROF1iiWbLlXiJuEYY0Fe2fj2uFgx5yzF8FnMJJbvc1wLJ8S kas83uIbK0e/wfSz7d3jnD3deFkeSsY40e5W6AH+nz5iiXk6AIYuu5aj3xxJ9ZzPtiQu DyTJRyQpOBYXwrULLfxy3YR5CdCQowKuLq8Fydp5BcDFKPAQI9rzjSp+tZ8iIVfxmR9U qu47R1y51RjXtSIvsagtYHJAImumc7W4Fgeqn8nWugNu+Q+u3Z8E7wudKRzDEs9kaBu9 1A1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=mjSbDBWx; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id la26-20020a170907781a00b007adeb7f8e5bsi21092990ejc.913.2023.01.03.02.17.03; Tue, 03 Jan 2023 02:17:17 -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=@gmail.com header.s=20210112 header.b=mjSbDBWx; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237323AbjACKPY (ORCPT + 61 others); Tue, 3 Jan 2023 05:15:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237194AbjACKPR (ORCPT ); Tue, 3 Jan 2023 05:15:17 -0500 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41C6AEE32; Tue, 3 Jan 2023 02:15:16 -0800 (PST) Received: by mail-ed1-x52e.google.com with SMTP id z11so27296602ede.1; Tue, 03 Jan 2023 02:15:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:from:to:cc:subject:date:message-id :reply-to; bh=dg4Iem/pwcu+hGrCWyFWcE0w0rA2DwqUcHLBcyuPeUc=; b=mjSbDBWx33CYMdnRAunBxjnUpsQB8NQEfdMQgMgMOMnsSL2cUgoBYVoV1sYAg2p0Zp 50bdUMAQBKLBJKw+RQJGTYGVqDzPzYZoE6hNmGb1i5zXPIqLNykLk0p2pGnXFlik/t2C grRyHKq4PBadLvD2l5ItwXVsIA7HCKuk/+WfMEbq9F2aNiw017v28VGfTtFG/2AijMda veJ+wuzLKcZk3E2ifzeaHUw7UfbUh+7nT4Zs3CJDmhcZ4JEJ4e2YINxHe0YL51HMrGSZ OByncrEr9GdapTEhGBNp8zuujYcX/U+gUYtkegXnSM1hjbSRkh4T4NVSekJxNWP8fRt8 fBhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dg4Iem/pwcu+hGrCWyFWcE0w0rA2DwqUcHLBcyuPeUc=; b=IUlLfedL7C0J+Ub8kXU3zO2fRgUn51mRDPChP+ECmuIkiCYJnfUb69vWNmVjszanCK HQqK2ofNJeKXRqsEsYvG5Au3HcXbHU75o8s+fojAhf6VTb4rXpiYliShoFrE1SsgiSeK wCWUEf8gBsHcCpDagaJjUHVo1I+XSwBEx8Rf0hrSg7vtRUZj1QbCl7iay0tQ79izaAP3 aH6mQ69fHJMt5P54EZTJ0xxQu7kBsJoH9157qdHyjDpsnsB/Ak1ZCYRZAt5e388uam4I aMt1goYnU5AAu7ePiRCJhluPCYkSVDqhBHtczfBuVN3S0a1BWoa8MKTEr4VFyvQxTmTO iViQ== X-Gm-Message-State: AFqh2ko/c/nbVsUakQ4teEIXZmYFNEEgLmOBql+KVFcq/aLKNp7KUKYG bWkg0TvyZn9qWh9ADUU2amAWDN3Dlag= X-Received: by 2002:a05:6402:d5c:b0:461:68e4:15cc with SMTP id ec28-20020a0564020d5c00b0046168e415ccmr34746439edb.9.1672740914735; Tue, 03 Jan 2023 02:15:14 -0800 (PST) Received: from gmail.com (1F2EF380.nat.pool.telekom.hu. [31.46.243.128]) by smtp.gmail.com with ESMTPSA id r7-20020a170906280700b007b27aefc578sm13853448ejc.126.2023.01.03.02.15.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Jan 2023 02:15:14 -0800 (PST) Sender: Ingo Molnar Date: Tue, 3 Jan 2023 11:15:12 +0100 From: Ingo Molnar To: Vlastimil Babka Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Takashi Iwai , x86@kernel.org, "H. Peter Anvin" , patches@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Baoquan He , Dave Young , stable@vger.kernel.org Subject: Re: [PATCH] x86/kexec: fix double vfree of image->elf_headers Message-ID: References: <20230102103917.20987-1-vbabka@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no 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 * Vlastimil Babka wrote: > On 1/2/23 11:39, Vlastimil Babka wrote: > > An investigation of a "Trying to vfree() nonexistent vm area" bug > > occurring in arch_kimage_file_post_load_cleanup() doing a > > vfree(image->elf_headers) in our 5.14-based kernel yielded the following > > double vfree() scenario, also present in mainline: > > > > SYSCALL_DEFINE5(kexec_file_load) > > kimage_file_alloc_init() > > kimage_file_prepare_segments() > > arch_kexec_kernel_image_probe() > > kexec_image_load_default() > > kexec_bzImage64_ops.load() > > bzImage64_load() > > crash_load_segments() > > prepare_elf_headers(image, &kbuf.buffer, &kbuf.bufsz); > > image->elf_headers = kbuf.buffer; > > ret = kexec_add_buffer(&kbuf); > > if (ret) vfree((void *)image->elf_headers); // first vfree() > > if (ret) kimage_file_post_load_cleanup() > > vfree(image->elf_headers); // second vfree() > > > > AFAICS the scenario is possible since v5.19 commit b3e34a47f989 > > ("x86/kexec: fix memory leak of elf header buffer") that was marked for > > stable and also was backported to our kernel. > > > > Fix the problem by setting the pointer to NULL after the first vfree(). > > Also set elf_headers_sz to 0, as kimage_file_post_load_cleanup() does. > > > > Fixes: b3e34a47f989 ("x86/kexec: fix memory leak of elf header buffer") > > Signed-off-by: Vlastimil Babka > > Cc: Baoquan He > > Cc: Dave Young > > Cc: > > Takashi told me he sent a slightly different fix already in November: > https://lore.kernel.org/all/20221122115122.13937-1-tiwai@suse.de/ > > Seems it wasn't picked up? You might pick his then, as Baoquan acked it, and > it's removing code, not adding it. Thanks, indeed we missed that fix - Boris picked up that version in tip:x86/urgent, via: d00dd2f2645d ("x86/kexec: Fix double-free of elf header buffer") Ingo