From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=195.135.223.130 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796145187; b=0puHJYOcFWRPyEip2wvra0SpaDlGyoa8SkymWoD1LCJ7ih960FZ72c5adx+6qLMBY9sY E7D1sJ5E9SymVB1DEw6yZqf38KqkWInB9XevidOOIEziuK2SZlX6Hgkl3GMyxDTmfwctY HDAyz5sBCbCPgZDT0fxrnOF3lylTMlU1YU67ZnOfenl5M6T09qmFDraFXqaxbh3t4TION SXvNgKJEbzw6JehNNqqzXLJ5OUCsqkxavGbgrG7233bsNfuNj+/m5IEfIe0UlAzJ44pQR +GLf/N2FpAzy6GqGMzequvRdp+vj4bRPqGiYI+3YY463X2wvuOKjGGs/X1TiB8M2liQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796145187; h=DMARC-Filter:Received:DKIM-Signature:DKIM-Signature:Received: Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:X-Spamd-Result: X-Spam-Score:X-Spam-Level:X-Spam-Flag; bh=6rDoD09Aj+9/D7kyanphjoQksVuAzPpQnZyGBF+Pq94=; b=0FMIhJSvghDM+W+Wp/xIFMEZb64OSRQU0TmqKRUFvHLxZTwZvOZq0P72B7/JKyQOBJK8 enXu/cQxPXJjYoTHskPEjGICDfx5I2gGDg+uawuMi0sSHARej0TPEHHnNawH+HfH+HWQc GpbPdIGMTPmQUNaAPMgTP5PdkRqDbAM8Mr9MCRjNHckWTN5fN2sU9QeIsJ7p4eRIRckZP Rg8jIf4Y+CGdysRaq4ctWlQxv+WG1+GMTZuznNkrKn1oUZgN5X/0hjP9FGZ9wSCQT1u9k ZWuy7NDtjsaPQiDByH55oa18IkdgrWZmk/Vh6mOlTVH32FexFgap04uiILCQeJLOtLg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=susede1 header.b=DQ2f45Rg; dkim=pass header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=susede1 header.b=DQ2f45Rg; arc=none smtp.remote-ip=195.135.223.130 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2E3EC606A320; Tue, 1 Dec 2026 17:13:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2E3EC606A320 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=susede1 header.b=DQ2f45Rg; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=susede1 header.b=DQ2f45Rg Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 5F5162229C; Tue, 1 Dec 2026 17:13:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1796145185; 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: in-reply-to:in-reply-to:references:references; bh=6rDoD09Aj+9/D7kyanphjoQksVuAzPpQnZyGBF+Pq94=; b=DQ2f45RgO/1Z4yvwTNuG/OydFIS4ZfppKOzEbpXH9rOTsrZCqkdRi6IPk5hlY0j3xSYOKb tMPXRv62Ls8TNKf6RO+PYCydvtjb1DUA+J0aUrHpV+i0YbAjTOG4wn9+zUMcKyrLTu2xJg 5GNwFKZGyLckkW3YQVMP8H/sGrysM7s= Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1796145185; 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: in-reply-to:in-reply-to:references:references; bh=6rDoD09Aj+9/D7kyanphjoQksVuAzPpQnZyGBF+Pq94=; b=DQ2f45RgO/1Z4yvwTNuG/OydFIS4ZfppKOzEbpXH9rOTsrZCqkdRi6IPk5hlY0j3xSYOKb tMPXRv62Ls8TNKf6RO+PYCydvtjb1DUA+J0aUrHpV+i0YbAjTOG4wn9+zUMcKyrLTu2xJg 5GNwFKZGyLckkW3YQVMP8H/sGrysM7s= Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 1733F133F6; Tue, 1 Dec 2026 17:13:05 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id wiEgNCAAD2vpKQAAD6G6ig (envelope-from ); Tue, 01 Dec 2026 17:13:05 +0000 From: Daniel Vacek To: ebiggers@kernel.org, linux-fscrypt@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Daniel Vacek Subject: Re: [PATCH] fscrypt: Avoid dynamic allocation in fscrypt_get_devices() Date: Tue, 1 Dec 2026 18:13:02 +0100 Message-ID: <20261201171303.84339-1-neelx@suse.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260720174558.GC1865@quark> References: <20260720174558.GC1865@quark> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spamd-Result: default: False [-11.80 / 50.00]; SUSE_INTERNAL_BYPASS(-9.00)[]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.995]; MIME_GOOD(-0.10)[text/plain]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo]; FROM_HAS_DN(0.00)[]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; RCPT_COUNT_FIVE(0.00)[5]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: -11.80 X-Spam-Level: X-Spam-Flag: NO > When a blk_crypto_key starts being used or is evicted, fs/crypto/ calls > fscrypt_get_devices() to get the filesystem's list of block devices, > then iterates over them and calls blk_crypto_config_supported(), > blk_crypto_start_using_key(), or blk_crypto_evict_key() on each one. > > Currently, the block device pointers are placed in a dynamically > allocated array. This dynamic allocation is problematic because: > > - It can fail, especially at the fscrypt_destroy_inline_crypt_key() call > site when it's invoked for inode eviction under direct reclaim. > > - fscrypt_destroy_inline_crypt_key() doesn't handle the failure. It > just zeroizes and frees the blk_crypto_key without calling > blk_crypto_evict_key(). That causes a use-after-free. > > For now, let's fix this in the straightforward and easily-backportable > way by switching to an on-stack array. Currently the fscrypt > multi-device functionality is used only by f2fs, which has a hardcoded > limit of 8 block devices. An on-stack array works fine for that. > > (Of course, this solution won't scale up to large number of block > devices. For that we'd need a different solution, like moving the block > device iteration into the filesystem. Or in the case of btrfs, which > will only support blk-crypto-fallback, we should make it just call > blk-crypto-fallback directly, so the block devices won't be needed.) For btrfs this could be a limitation for some setups. I'll be happy to make the change to the filesystem iteration. It looks quite straightforward. The reason is I'm actually working on a redesign which will enable btrfs to use the true inline encryption. Hopefully, it should simplify and unify things a bit. --nX