From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) (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 B0EC5387375 for ; Thu, 6 Aug 2026 05:25:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785993911; cv=none; b=rFlBgGjJmZoknl2bbbsNPQVBu5VY0UPnmikdGoA0l2ZgC46ivqaB5aqBJ8Cq0ig0MnsQRVce1p1QXadZoh74ZeYuxo1vkSK7hqd206u62/Z417LH0j6Smi0Y1LGnwuCp8QgUHvlwAYUi11uUxWWHm3ix9qLjyBeZJLyF3tgZY9w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785993911; c=relaxed/simple; bh=Q4asbQYkwjm21JM4IuUSztFqXnfJ/QMuKk/Ym7cdz8E=; h=From:Date:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=uhNkOX55/2ou21YrXad2h1/BoKKyAeg06M2VDO7CfBfEJN+54M3UmEvT/SaC+WsdudzQmjFwUacGm0qd/arfRnc/FgMdSOd7Nfe9DY8jov63RQkydW4R9I3IRCbLN6jWEmZHRT2nCNJukX7Tk7RUbz4G8z8SDQC1hNkBMsQqslE= 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=bykFUEcN; arc=none smtp.client-ip=209.85.210.175 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="bykFUEcN" Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-8486672f03cso2198338b3a.0 for ; Wed, 05 Aug 2026 22:25:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785993909; x=1786598709; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:date:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=CvIeePQsxZu1lvyuPmffHvVuX4dHxWUDRkiO5wuokgc=; b=bykFUEcNSPgyVqBMUBtNgbCiMMcLstOJ7ZCTs7ur0pKXLGe6Scfcbk2u+sV/VW3brl +uludw+7mtDPWPUEfYy2qxPu66JksPrnB0UORKpn36wSpkXy8+pjNtGBU1Vl7hwpkkGQ i1C5f0hufecPzVwtb9t8195Byxcy5JwlbRVBS6rzoQyh7rtlYk/9sIJ7z3d33TTnRNfd RBHpeLn980/5MUYHip+CknSmIjKWz/fP/x2iqMWjz3h7Tk1OFLP/rVM1ZwEWTKSVk6sx 7f2fvcKesXjwgUWXYCNYm1mA4uWLrf3rh5FvHmTHmr38mW+Kg4JY738KUxOSYpMShbS0 PwPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785993909; x=1786598709; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=CvIeePQsxZu1lvyuPmffHvVuX4dHxWUDRkiO5wuokgc=; b=HGuOyP6dUsMcZpgWlyX5xa/6Read7gl8j3tAi8mPyJv0ePcX4PcxXClX4Wyx+U8fQG cv42j6dNN2U5uaABnlw6sHPz78NFhrd+Ddh6ABafCFFLhLRVMlTGfyfBIun6MBG7eiAq 3anepdwJaNE9lnG5kLpi6MHLbOs9NNPLUbX4Q4/XYqW7V5bRNwWEvm6aeZtsprdDH1yb 4IRQtRKT8hUjXcDZzdZiDHwB7T8XuSoGDBwrTRlopKj2YI2GKALqUhNdwC/aD+NigTXj AanKrTyxUD5slw7JyrYv2DiMwdG0ah9oWhVZo3IkgPadls9HEdCmGR410SGdHqY1AeTO BxIg== X-Forwarded-Encrypted: i=1; AHgh+RpUtQ81saKSjoLd800qgeYJ2GGbGSLwnuGIINHCuMyt9Ono4MPIJHmkJ/18p6fEcDqp7qsesRLRiv18sKw=@vger.kernel.org X-Gm-Message-State: AOJu0Yz9sokhAkxOue46fkiECuwb7WxAg0XMQLjDUUKdOQp6w18oRh/e tDwhWvoDVlWcuKsm1XX+FDXR/Pb+OzySBNyYYyG7QSl861g5ZL2IqXjy X-Gm-Gg: AR+sD10l4+X/dTYiQ7oLl2CerKtkpb+OZBPb1OBuxQoZfx/q/7BlPXq1UqPFzK9Wr9m GUcQBxUL+r0YH2myRQ1qDKg/UsrWi8Qwf5NdwfP8RSzS3V3G9ifF6iiDI0B8zW06FDCOIJwAq6n 6FSzrqre5j+ipiUsY95ciYSrSDtc9XWgT8bR5Tq0PV28tbfjmNCaZWk3VdMF/a1FXQz8aeSmwsd NaJkWLJlUMsfulkb9xe87WplBaaHHfoTHouTUGACoCD+Mg8BQ66VlUhtJ+5y06fVP5bEVOc505M FIVhrv8vUvWSA1T7sIJi7VZw/Oef69tWMAlhqa/AfkZzrQ4uxeHQ5ZSo+rygw/JTyP6+m/xgAkd 1XJ5N3zbv19luKiWjVFFg2hXvJMIOB0lZ/4mTCXkmhQkmDYIR8wt8tutRA/G/E61EPSm5QLM88Y /6UoJpIugujsKVy6Nn6GyJnVck5EP1+DHLLxQCCqaqFl15/DrURJAe X-Received: by 2002:a05:6a00:300e:b0:84c:4bf4:10c3 with SMTP id d2e1a72fcca58-84f2e0cc682mr14367528b3a.38.1785993908992; Wed, 05 Aug 2026 22:25:08 -0700 (PDT) Received: from localhost ([2a09:bac5:55f3:25d7::3c5:8]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84f456b7368sm562220b3a.37.2026.08.05.22.25.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Aug 2026 22:25:08 -0700 (PDT) From: Coiby Xu X-Google-Original-From: Coiby Xu Date: Thu, 6 Aug 2026 13:20:58 +0800 To: Sourabh Jain Cc: kexec@lists.infradead.org, Andrew Morton , Baoquan He , Dave Young , Pratyush Yadav , Mike Rapoport , Pasha Tatashin , Coiby Xu , open list Subject: Re: [PATCH v3 03/10] crash_dump: Disallow writing to dm-crypt configfs during kexec_file_load syscall Message-ID: References: <20260729033654.311541-1-coiby.xu@gmail.com> <20260729033654.311541-4-coiby.xu@gmail.com> <3010bbe1-844f-4513-9941-f4e92e581769@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=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <3010bbe1-844f-4513-9941-f4e92e581769@linux.ibm.com> On Wed, Aug 05, 2026 at 04:00:51PM +0530, Sourabh Jain wrote: > > >On 29/07/26 09:06, Coiby Xu wrote: >>If writing to the configfs group happens concurrently during >>kexec_file_load syscall, it may lead to the following issues, >> - buffer overflow if dm-crypt keys are added after allocation >> - stale total_keys if dm-crypt keys are removed during iteration >> - keys_header will not be freed if config/crash_dm_crypt_key/reuse is >> set true >> >>So hold config_keys_subsys.su_mutex for the entire sequence during the >>kexec_file_load syscall to ensure a consistent snapshot. >> >>Fixes: 479e58549b0f ("crash_dump: store dm crypt keys in kdump reserved memory") >>Suggested-by: Sourabh Jain >>Signed-off-by: Coiby Xu >>--- >> kernel/crash_dump_dm_crypt.c | 23 +++++++++++++++++++++-- >> 1 file changed, 21 insertions(+), 2 deletions(-) >> >>diff --git a/kernel/crash_dump_dm_crypt.c b/kernel/crash_dump_dm_crypt.c >>index 4335b6cb1fc4..d2e66c6fe6f3 100644 >>--- a/kernel/crash_dump_dm_crypt.c >>+++ b/kernel/crash_dump_dm_crypt.c >>@@ -293,6 +293,7 @@ static ssize_t config_keys_reuse_show(struct config_item *item, char *page) >> static ssize_t config_keys_reuse_store(struct config_item *item, >> const char *page, size_t count) >> { >>+ struct mutex *lock; >> bool val; >> int r; >>@@ -302,8 +303,12 @@ static ssize_t config_keys_reuse_store(struct config_item *item, >> return -EINVAL; >> } >>+ lock = &to_config_group(item)->cg_subsys->su_mutex; >>+ mutex_lock(lock); > >Is this lock only protecting against races between key reuse and >kexec_file_load(), The lock here is to protect against races between key reuse and kexec_file_load. >or does it also handle the case where a new key is added during key reuse or >kexec_file_load() is running? For the cases where a key is added/deleted, configfs will automatically take care of them because it will acquire mutex lock automatically. > >If it is only intended to protect key reuse versus kexec_file_load(), >why can't we use >the kexec lock instead? > >The reason I'm asking is that, in upcoming patches, the key reuse path >accesses >kexec_crash_image properties and the crash reserved region directly. >Doing so >without taking the kexec lock (using kexec_trylock()) could lead to >race conditions. After comparing the kexec lock approach with the configfs mutex lock approach, I think the latter is a simpler solution because 1. the kexec lock is non-blocking and we have to repeatedly try until the lock get acquired. So it means user space has to make changes as well. 2. configfs already acquires the mutex lock automatically for creating/deleting configfs items. So if we use configfs mutex lock, it means one less place to use the lock. In config_keys_reuse_store, kexec_crash_image will be checked before accessing its properties and the crash reserved region. Can you elaborate on what the race conditions are? Will acquiring the lock before accessing kexec_crash_image properties and the crash reserved region help protect against these races? In theory, the kexec lock can be a more robust approach. But considering only root can write to the crash dm-crypt keys configfs and load kdump image, I'm not sure it's necessary to adopt a bit more complex solution. > >- Sourabh Jain >>+ >>+ r = -EINVAL; >> if (kstrtobool(page, &val) || !val) >>- return -EINVAL; >>+ goto unlock; > >The jump above skips setting count, causing the function to return >count instead of -EINVAL. >Is this really intended? Thanks for catching this issue! In the end of the function, r instead of count should be returned. > >> if (is_dm_key_reused) { >> pr_info("Already got dm-crypt keys, please continue with kexec_file_load syscall\n"); >>@@ -311,11 +316,15 @@ static ssize_t config_keys_reuse_store(struct config_item *item, >> r = get_keys_from_kdump_reserved_memory(); >> if (r) { >> pr_warn("Failed to get dm-crypt keys from reserved memory\n"); >>- return r; >>+ goto unlock; >> } >> is_dm_key_reused = true; >> } >>+ r = count; >>+ >>+unlock: >>+ mutex_unlock(lock); >> return count; >> } >>@@ -421,6 +430,8 @@ static int build_keys_header(void) >> return 0; >> } >>+static bool mutex_acquired; >>+ >> int crash_load_dm_crypt_keys(struct kimage *image) >> { >> struct kexec_buf kbuf = { >>@@ -432,6 +443,9 @@ int crash_load_dm_crypt_keys(struct kimage *image) >> }; >> int r = 0; >>+ mutex_lock(&config_keys_subsys.su_mutex); >>+ mutex_acquired = true; >>+ >> if (key_count <= 0) { >> kexec_dprintk("No dm-crypt keys\n"); >> return 0; >>@@ -481,6 +495,11 @@ void kexec_file_post_load_cleanup_dm_crypt(struct kimage *image) >> kfree_sensitive(keys_header); >> keys_header = NULL; >> } >>+ >>+ if (mutex_acquired) { >>+ mutex_unlock(&config_keys_subsys.su_mutex); >>+ mutex_acquired = false; >>+ } >> } >> static int __init configfs_dmcrypt_keys_init(void) > -- Best regards, Coiby