From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8454637E2E4 for ; Sat, 2 May 2026 00:00:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777680007; cv=none; b=aQuliFZIU8lEV+W3k2WxNRnMmt6FaHudCxiPfb7QqMIeE/BE8sQ4/yjX98GgGMcTrOfkPYrk1z73k3rYBSQdMSBMNkipuNB1qmjHH8ztOpn6WsYrQFaLuiwdzorWb0zYL2rmEXk90Jbi4em6gcDajUh8bccMuOADMIircIM+Y7I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777680007; c=relaxed/simple; bh=plF6X9o4F3co/ajQd71ZJkW+9fqzrvmmBg+CaBUKCWA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=XtKkYbEvVElvAIh52hwxeuQeA1sCil/yHSDf4PNUmupTc3qgt+Ka78RQGrNiONk8ytziAb8Cu4Edpu7vDGCgpPRWVCSBy+aBTyb33okyEbw6zEkkNc/IwA61o6OY1kBfZqyJn3unJMIBx977oSpvRCXeEE/uekn1gNAQWjz/Rso= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=UbGHyovq; arc=none smtp.client-ip=209.85.210.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UbGHyovq" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-82f8bf96b46so1083376b3a.2 for ; Fri, 01 May 2026 17:00:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777680006; x=1778284806; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=jZbQqiA/fecMgvSQZW2ffEuq3Qf9g5f25sCTnXGKHio=; b=UbGHyovqK8epCG2Dk5airsPEOPK3umhQGKisl3dgp5zGD8xMuTZLjaLFIVC/mORGtZ lFcsw2A+1iHajToSInzvQgY4d5c5BxBZzt1D7QrMlEGcoQjAzZXDAehNsQ/XSZ0hgyGZ tsWvqx7fYk4+6dODmmPcKkh9KirYj2TkDa9/tZd1H+iA8XevVuE6UXKdoEri0irKD5nt qWzJ8cKxZyAnFk8LmxAfakwb96jeEmk3/0faqF13V5xZzFIBfq3NAUdQLGjkiI6lFApd qLvbdpXYohxqqrR524Qnk+TihE7Jif2zHZ7OgkVGgeKlYZ1ipbXl5sclq/FXZtdFIANO cCUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777680006; x=1778284806; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jZbQqiA/fecMgvSQZW2ffEuq3Qf9g5f25sCTnXGKHio=; b=aknJckMNt7CzXn52RWaDhhqNM73OaGeUGY5wFIM1OC5xmgsvVlmg67u+Af5xLu4oWB 7hRZs+jfwvKvU0GHOsGKFNXsj8NcA5+xXyOyWY76ML3gCRp4zyJt2LGpJfg6jWDuMQR3 wgYRdjbcbJef7RGzAJ1ogwhLK3BdALpMHP9biI8JJwKWmmXqEbtNoa2ZGeh17Y6HxTQm LXj4SmN+GobPzigD4O3h/flUgAWl1BrG6zGMRLO/CQx4cfhynC6qEC578b1oMWQGVI36 S2zuSREyTvOPSFXboa00X9DiBgZwcE2KfWzOaeS0JfsUWxkEqKkqA1AlM6CYt8u6iAHs ky4A== X-Forwarded-Encrypted: i=1; AFNElJ/q/AAq0Ady+hAqPuh2jIqYyitXy/QK3Mk+QsmMJDYJkySXfsQABW6ov7bEp3H31UtE1Z0EzrvwTRrFYbI=@vger.kernel.org X-Gm-Message-State: AOJu0YzyRYT8sal/j/UgTs3Yf0pB6o6gc7LxALx8Ksk6ZTuMvIGXRgvk jBaVXIY36H+9wSPxX6ZpI0FHHXlii2HpK9v0ZSeLhF7nUTUQwHAp3c1r X-Gm-Gg: AeBDieuBv5MTVB46cu+uGjNCzrZCRybi+Z+q6Vgf60dtpFiGumMFP9Qo7gkiiqFQ1P6 150AqYvf1TUk8X7r94YY4EghJUhGLaDk30w1EddwilkK33eJMQzrIVcjoljM23C609ZVHYoLzXM cge+t8rhb8rcmYVUhED8ps8otn6tHsYiBQDYoe3LSD0RD3HDDrFRTzMjUpsh77FByqmg9nTgD9r n2DmrkD1RQHo9OOs5sDCxeN/M6kS+CNDfvfL4G5VVCpT7e2BzSWsKGQzXj8XV7nSbsFMao1u4nU /yMCx05yysA9ri3S3IB0RR9iJRs0s8qEnqv2AuQ+oj7mKWSqbPgnZcY7df0zbtAs1v6+DO+a5de tPzk24fLTcq9f6O86oCH5+NfO4/NZKil2ZgfcHtzcjfzjJjr7sbPF0UHcXH0YVTJzXfMYraRGfx ujzAU4PqT682sGvC6Eiq6ZEQWh0Xfq6A== X-Received: by 2002:a05:6a00:1bc9:b0:82f:4386:7989 with SMTP id d2e1a72fcca58-8352d20264bmr1064459b3a.24.1777680005486; Fri, 01 May 2026 17:00:05 -0700 (PDT) Received: from localhost ([121.237.249.41]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8351587db67sm3674725b3a.13.2026.05.01.17.00.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 May 2026 17:00:04 -0700 (PDT) Date: Sat, 2 May 2026 07:49:48 +0800 From: Coiby Xu To: Sourabh Jain Cc: kexec@lists.infradead.org, stable@vger.kernel.org, Andrew Morton , Baoquan He , Vivek Goyal , Dave Young , open list Subject: Re: [PATCH] crash_dump: Fix potential double free and UAF of keys_header Message-ID: References: <20260403100126.1468200-1-coxu@redhat.com> <972b9a73-d066-4a38-8a4b-fe7d1ba2944b@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Tue, Apr 07, 2026 at 08:44:39AM +0800, Coiby Xu wrote: >On Fri, Apr 03, 2026 at 07:48:29PM +0530, Sourabh Jain wrote: >>Hello Coiby, > >Hi Sourabh, > >> >>On 03/04/26 15:31, Coiby Xu wrote: >>>If kexec_add_buffer fails, keys_header will be freed. And depending on >>>/sys/kernel/config/crash_dm_crypt_key/reuse, it will lead to the >>>following two problems if the kexec_file_load syscall is called again, >>> 1. Double free of keys_header if reuse=false >>> 2. UAF of keys_header if reuse=true >>> >>>Address these problems by setting keys_header to NULL after freeing >>>kbuf.buffer and re-building keys_header when necessary respectively. >>> >>>Fixes: 479e58549b0f ("crash_dump: store dm crypt keys in kdump reserved memory") >>>Fixes: 9ebfa8dcaea7 ("crash_dump: reuse saved dm crypt keys for CPU/memory hot-plugging") >>>Cc: stable@vger.kernel.org >>>Cc: Andrew Morton >>>Reported-by: Sourabh Jain >>>Signed-off-by: Coiby Xu >>>--- >>> kernel/crash_dump_dm_crypt.c | 3 ++- >>> 1 file changed, 2 insertions(+), 1 deletion(-) >>> >>>diff --git a/kernel/crash_dump_dm_crypt.c b/kernel/crash_dump_dm_crypt.c >>>index a20d4097744a..92eebef27156 100644 >>>--- a/kernel/crash_dump_dm_crypt.c >>>+++ b/kernel/crash_dump_dm_crypt.c >>>@@ -417,7 +417,7 @@ int crash_load_dm_crypt_keys(struct kimage *image) >>> return -ENOENT; >>> } >>>- if (!is_dm_key_reused) { >>>+ if (!is_dm_key_reused || !keys_header) { >>> image->dm_crypt_keys_addr = 0; >>> r = build_keys_header(); >>> if (r) >>>@@ -433,6 +433,7 @@ int crash_load_dm_crypt_keys(struct kimage *image) >>> r = kexec_add_buffer(&kbuf); >>> if (r) { >>> kvfree((void *)kbuf.buffer); >>>+ keys_header = NULL; >>> return r; >>> } >>> image->dm_crypt_keys_addr = kbuf.mem; >>> >>>base-commit: d8a9a4b11a137909e306e50346148fc5c3b63f9d >> >>Sashiko raised seven concerns on this patch. Most of them are >>not directly related to the changes introduced here, but I >>think they can be addressed along with this fix. >> >>https://sashiko.dev/#/patchset/20260403100126.1468200-1-coxu%40redhat.com > >Thanks for pointing me to the Sashiko's code review and also sharing >your meticulous analysis! > >> >> [...] >> >>4. get_keys_from_kdump_reserved_memory() may run into issues >>   if kexec_crash_image->dm_crypt_keys_addr is larger than a >>   page size during memcpy. Because kmap_local_page only maps >>   one page. >> >>How about moving this in a loop and do map and copy page by page? > >Yeah, looping over the pages should be a robust solution. After failing to reproduce the predicted issue, I realized there is no need for looping page by page because kexec_add_buffer will try to find a continuous physical memory region. So I dropped this idea in v2. But thanks for helping me learning something new:) -- Best regards, Coiby