From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9B660C982DC for ; Fri, 18 Sep 2026 10:05:14 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4hmSsD0Wskz3bYG; Fri, 18 Sep 2026 20:04:32 +1000 (AEST) Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip=113.46.200.223 ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1789725870; cv=none; b=emUeP01A0hzRR/ymTUPSIKmi2cKILx9uuOB8jkmA4LGpw1UxvSwgygdmlJjIStGZylPzd//Lyve5ww/1OnxxZEr9AJ06kGniDo54p4GsCIi49Lt1wNcd/6JUimt6OLsvuh96YlA0PZ9UkAHB6VICbJdHmKF4/EZT19KoT9YgFXj3UgW6Hcbj0pIhBruHFVTFQI4vWNfAu7BpwNH4iKRYOj5/D78dOylDWLcfOzdAQ+kS6EdWAG9lOiv0tiS/w1wLiscXH3iIUFRKWxA+ZA4O6jP1SVQoQVjU1j2+9UaLvi+lKq6C44HuphyoQ2F46cjQAmkkkcTfOmevxFiGfV6f4A== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1789725870; c=relaxed/relaxed; bh=20ZJiQbk77XpGyt2zLlFzhTV8L6cgd0AT+Mg72ZNP+o=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=I4YNCKrttgJlHBV/oRhyMjQqL4uH5i29ig8spEFUXwVW4PNIPIhrY0EmGTXszG92hawZs8mQsqUOLz4uWPFSdSIKsNjuHUHuO+wDca8COqkIMQiLkgdKFxt/TUG815utx9QJNp6xvNwbkmr2HCfTgtJ3CtwImtqGkYZYfOCDAEzsN1cjfnEIz2+DhTKljkIvNa+5QZmqs/ci9YowX1oFyP6s/XGJTPgWnZmGz3gegA4MH6MgqXzq6GOQYrYau8iV+0rG5+rs3k1MgHZFtyKZtLvD514IdrLNdJOkc2rSQ8xe0ctkdAt+W6wfs8GkXM1MTxb07+1iVYjOLpq8J0+KBQ== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; dkim=pass (1024-bit key; unprotected) header.d=huawei.com header.i=@huawei.com header.a=rsa-sha256 header.s=dkim header.b=h20MzYgr; dkim-atps=neutral; spf=pass (client-ip=113.46.200.223; helo=canpmsgout08.his.huawei.com; envelope-from=ruanjinjie@huawei.com; receiver=lists.ozlabs.org) smtp.mailfrom=huawei.com Authentication-Results: lists.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=huawei.com header.i=@huawei.com header.a=rsa-sha256 header.s=dkim header.b=h20MzYgr; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=huawei.com (client-ip=113.46.200.223; helo=canpmsgout08.his.huawei.com; envelope-from=ruanjinjie@huawei.com; receiver=lists.ozlabs.org) Received: from canpmsgout08.his.huawei.com (canpmsgout08.his.huawei.com [113.46.200.223]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4hmSs53r6Gz30PJ for ; Fri, 18 Sep 2026 20:04:24 +1000 (AEST) dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=20ZJiQbk77XpGyt2zLlFzhTV8L6cgd0AT+Mg72ZNP+o=; b=h20MzYgrtfLEEV4IsF22m8M0aeU+9fIDiLpJWraCVTgEvlTBvhYu0irkyY7dZ8KlR25j3eFDX uDHiuEi34Vyc2FyCL6c39JSfjX+M3Cz00j/vkUz1PTc66H//7kIYPJQEJrTEE3IZKzXvZCqcFXg laCNtc/NvKopW2lnm4CTtD4= Received: from mail.maildlp.com (unknown [172.19.162.92]) by canpmsgout08.his.huawei.com (SkyGuard) with ESMTPS id 4hmScJ5pDBzmVWf; Fri, 18 Sep 2026 17:53:20 +0800 (CST) Received: from kwepemk200008.china.huawei.com (unknown [7.202.194.74]) by mail.maildlp.com (Postfix) with ESMTPS id DC0BB40586; Fri, 18 Sep 2026 18:04:20 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemk200008.china.huawei.com (7.202.194.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.45; Fri, 18 Sep 2026 18:04:19 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v5 08/17] LoongArch: kexec_file: Fix a modified_cmdline leak Date: Fri, 18 Sep 2026 18:04:33 +0800 Message-ID: <20260918100442.3841135-9-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260918100442.3841135-1-ruanjinjie@huawei.com> References: <20260918100442.3841135-1-ruanjinjie@huawei.com> X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Owner: List-Post: List-Archive: , List-Subscribe: , , List-Unsubscribe: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.90.53.73] X-ClientProxiedBy: kwepems100001.china.huawei.com (7.221.188.238) To kwepemk200008.china.huawei.com (7.202.194.74) load_other_segments() allocates modified_cmdline and stores it in image->arch.cmdline_ptr. machine_kexec_prepare() then copies it to KEXEC_CMDLINE_ADDR and overwrites the pointer, so the heap buffer is leaked on every successful kexec_file_load(). Free the buffer after the copy. Cc: Huacai Chen Cc: WANG Xuerui Cc: Kexin Liu Cc: Youling Tang Cc: Qiang Ma Cc: Tianyang Zhang Cc: George Guo Cc: stable@vger.kernel.org Fixes: d162feec6b6e ("LoongArch: Add preparatory infrastructure for kexec_file") Signed-off-by: Jinjie Ruan --- arch/loongarch/kernel/machine_kexec.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/loongarch/kernel/machine_kexec.c b/arch/loongarch/kernel/machine_kexec.c index 1883cae93bc3..19ccc91b6f2a 100644 --- a/arch/loongarch/kernel/machine_kexec.c +++ b/arch/loongarch/kernel/machine_kexec.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -56,6 +57,7 @@ int machine_kexec_prepare(struct kimage *kimage) */ memcpy((void *)KEXEC_CMDLINE_ADDR, (void *)kimage->arch.cmdline_ptr, strlen((char *)kimage->arch.cmdline_ptr) + 1); + kfree((void *)kimage->arch.cmdline_ptr); kimage->arch.cmdline_ptr = (unsigned long)KEXEC_CMDLINE_ADDR; } else { /* Find the command line */ -- 2.34.1