From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f172.google.com (mail-qt1-f172.google.com [209.85.160.172]) (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 015C52D9797 for ; Fri, 10 Jul 2026 02:30:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783650647; cv=none; b=HUNcCNG0YPpaNwfItOc1mTKgjyAgtpL0caprdalQI5SvfUKJ9xHGSUxNaS+LuWUcLZx5TcE/xrbbpBSBZkjSue396g588FeMCgbPZD3EN9MRF23Ss5PWUUVurpr1BzSe/OFefF3ZwO+IEAgifd8aU8j6QUzZCzrsXKVB9V4dhzI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783650647; c=relaxed/simple; bh=Yvvy/QQ94TY+l92hdWZeQlQ2bYCfQMAopwHUB0S4pok=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=e4zZXkpjL7qpMJCRGEeDrKD4PH8HQQqnQJ2zRnrxC1sKtSJdfQw69Pi7lbLqcuwXqW4lg7ErmEzDVqk3O5234+12DXK04OqNctvAlrCfQYXUW7+pTzryldxf9GlIcaaxFUpjrTvL5LtMn3YFBdmXSefR50Bo/72G8lkZk4T1TYc= 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=BoqzbScs; arc=none smtp.client-ip=209.85.160.172 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="BoqzbScs" Received: by mail-qt1-f172.google.com with SMTP id d75a77b69052e-51c2a818fc4so2635521cf.2 for ; Thu, 09 Jul 2026 19:30:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783650645; x=1784255445; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=MmyA50XS4r2q2+to0CnCcs4o3TfllBec+8WuJlT9k1I=; b=BoqzbScsXYQ5R5ZT6kX23+/rdZ1FVffdFSxsdrf8W6kfYyu7pXItPSAA4RZapcTXAT LqPSZQ366//7kJv1Ghikrnj6Y/63xHAyMFCWnd6jm+lGlsxi4OaCcREeWRIAnStwf93q Niwkjkyoc7oB5Xf8QXvBDbgT3UOph4LtuBPFoLYwMmvqKj9+YTV+whyYTGRBzubTczYe BqU3Fws+lBwIcKrsz7A0Ipr+69qqZWWLhsYyhObNvoLCx5T2+/KvGgbTTcg1Fem29qUd De+or/QieFII34lvKnc/cIQWEt5GTpsg2yBelWNWyl/12TcnM6GEXtuAOnpTlqCqNBFD K9dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783650645; x=1784255445; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=MmyA50XS4r2q2+to0CnCcs4o3TfllBec+8WuJlT9k1I=; b=fSpQmRZTZXIzZBd1Ro7U8dRIbiDtAUTt+uO+X/0zdG6E010b2zX58Fsht53H9MFy/c LBuPPqI7cvEvsuEyWJ4cj7D/CZznnPOpGYdHd8OydrCGJCDTlzOEmywpblpQLlxWxsRV 06Ciex2lBuMa7Huvoze9FBCBDFK2mSzwQZ+6EuoHck9QeWAzjDqBFd+gKWEWFbQoJ6Xw yasG87zfx4FxI8aTtrKhiiNkxGWPSPIxuTQ2/qyaIqMRMNX6/JWbkG2B1ZCiHAGRmW5+ dZzV53YsZN5D1Ts3EF6ZzG236Fgx9HmNy3faTmNzO2kPuaXpKvzyEMijiq94CQg/6lls 92ng== X-Forwarded-Encrypted: i=1; AHgh+RplWMwHPmujrhGtmN5K4jXkaFNMwyB9n9aK0fG3ZMRVtYTTesoCsrm+Z4lV4uleuGuY1Fz3zfToi2yZmOY=@vger.kernel.org X-Gm-Message-State: AOJu0YyaOSOHrS6Np2bAHLSH5CYkGNG+8TKD4yPC4Wz7xQt8eJhOo4tb bcwvTD4STqQBGokG6JFf6z/ZdBHX+TG6xDON90Xzwn2fJahvfeM7yxeO X-Gm-Gg: AfdE7cnAgUDtrA9ZmAOppIMEhvkTcHnGTihua2HTHPjJN/NcWFoJlphMLoHz9Rq+Zee hTDBleiZd+JciJwg0KKdrEy+ig8bGZzTQb2Y/m9il8wa1EiO8goKi+8VVNx1W9OxJSAaBTkpAxT h+eGYTSkYd1lPvjcnDO9nzATN1l96iSIsK5hjLmaKQinkl1xrN+FEKPMj+eiy4cRxjrFoZuIJSB PeOvP97/btIUCVb2e9CuqJ26P/jYpWFpFkrAUtQmZaqOb2ehzDo0G8TD7pGKzkKNm4pJGCf5uVG byuJDYj1cLUGrxwLpDpwJn7P2UzS23Zxdgz6LD95J8DhKQgEmV4qO2TnRJuWRsrJqmrIExIVYlr L1yaylU7sQwBFAaUyKxIFKkBIs/iChy/AukhclPwpeFAMHh7r7nRA6GJeTEZewd9O7Bkyx9xc5S wnL8uLmzek+SeaH7o5EkuQ5uURayJm6jKD6xlF8tWB5l+b9pHSGQ1g84W/Fi7bm4/alET/2Pooq 1FFfZuSZOI7Mk8qmT4QOXer+3TnjYYS X-Received: by 2002:ac8:7dcb:0:b0:51c:7b12:600b with SMTP id d75a77b69052e-51c8b58e364mr116647591cf.87.1783650644940; Thu, 09 Jul 2026 19:30:44 -0700 (PDT) Received: from server0.tail6e7dd.ts.net (c-68-48-65-54.hsd1.mi.comcast.net. [68.48.65.54]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-51caace31a4sm7251381cf.12.2026.07.09.19.30.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jul 2026 19:30:44 -0700 (PDT) From: Michael Bommarito To: Gao Xiang , Chao Yu Cc: Yue Hu , Jeffle Xu , Sandeep Dhavale , Hongbo Li , Chunhai Guo , linux-erofs@lists.ozlabs.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH] erofs: cap LZMA stream pool size Date: Thu, 9 Jul 2026 22:30:36 -0400 Message-ID: <20260710023036.3745254-1-michael.bommarito@gmail.com> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 7bit fs/erofs/decompressor_lzma.c sizes the module-global MicroLZMA stream pool from num_possible_cpus() or lzma_streams, then z_erofs_load_lzma_config() preallocates one image-supplied dictionary per stream, accepting dictionaries up to 8 MiB. On high-CPU systems, a small EROFS image can pin hundreds of MiB of vmalloc-backed decoder state until the erofs module is unloaded. Impact: an attacker-supplied EROFS image mounted by the system can pin up to 8 MiB times the LZMA stream count of kernel vmalloc memory. Cap the LZMA stream pool at 16 streams. That keeps the worst-case preallocated dictionary pool at 128 MiB while preserving the existing per-image dictionary limit. Fixes: 622ceaddb764 ("erofs: lzma compression support") Cc: stable@vger.kernel.org Assisted-by: Codex:gpt-5-5-xhigh Signed-off-by: Michael Bommarito --- fs/erofs/decompressor_lzma.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fs/erofs/decompressor_lzma.c b/fs/erofs/decompressor_lzma.c index f6692d0f2f04d..7bda4b73c2e41 100644 --- a/fs/erofs/decompressor_lzma.c +++ b/fs/erofs/decompressor_lzma.c @@ -8,6 +8,13 @@ struct z_erofs_lzma { u8 bounce[PAGE_SIZE]; }; +/* + * One MicroLZMA decoder can pin an 8 MiB dictionary. Bound the + * module-global stream pool so an image cannot multiply that by large CPU + * counts. + */ +#define Z_EROFS_LZMA_MAX_STREAMS 16 + /* considering the LZMA performance, no need to use a lockless list for now */ static DEFINE_SPINLOCK(z_erofs_lzma_lock); static unsigned int z_erofs_lzma_max_dictsize; @@ -52,6 +59,8 @@ static int __init z_erofs_lzma_init(void) /* by default, use # of possible CPUs instead */ if (!z_erofs_lzma_nstrms) z_erofs_lzma_nstrms = num_possible_cpus(); + z_erofs_lzma_nstrms = min_t(unsigned int, z_erofs_lzma_nstrms, + Z_EROFS_LZMA_MAX_STREAMS); for (i = 0; i < z_erofs_lzma_nstrms; ++i) { struct z_erofs_lzma *strm = kzalloc_obj(*strm); -- 2.53.0