From nobody Mon Feb 9 03:11:04 2026 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (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 52C8E33A714 for ; Fri, 19 Dec 2025 18:06:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766167602; cv=none; b=bovMx+xQugehjM+QV6KVpRo4PbhuLOFeqc6W/Wng+kIUHCjBl7ob3oZ+yezsjeAfBI621TdemMYtDBB8xZa6UYmWJU+aucq0zsQmp/n7nRVE35+nZVYq1OMuA4xREbT96xsxrN3O5ZqHsz29wu4zKqqZ8REC8PF7PFqTMOY84ao= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766167602; c=relaxed/simple; bh=RmCnd6gkVlTZlugAcfM3670Kr8ZwNknI/MToBJWnUBw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M1UNlkOBq7XUIMJcJKiIIsQRYKLPf4uZUCW9h7B3+r1SINgc42RGKnCryyWFrxvCqKRUBs/oVIPSZ71RC3LSOHYDzRXFYH4HFYxZJsJ6840PL2IvihYpbLs2RVXIN8BvIUf9KuvFBaV6qKkYv0TOfGRxdWHQKSaNZ1zdYW59dtk= 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=ZpFy2ifd; arc=none smtp.client-ip=209.85.210.171 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="ZpFy2ifd" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-7aab061e7cbso2927618b3a.1 for ; Fri, 19 Dec 2025 10:06:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766167599; x=1766772399; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dW3bXX4vP+WteeSK3ew02UmI9wiau0xdWqe/ZXK117U=; b=ZpFy2ifd83Eym1irHxEJi4ORn+/+ueWx6zfrtGVXsyJSXnWiLyzx5s6ZBNpjGaYfUh 18PCM7+6dS6lvHTk0gDH3006xXlVQLATp1Ans4pIqlCwq+MUH3V8QyEiZo0Kv/+nbGPH OCARGNx0VvgQmSYklJqRXS0+cHtRmXOYQrYs82eMCQKnD5fTqhCEBTye9FsIlwQVch4Z xisz+XVeWXURb3jUnXYV1ENYYN6gfXwxPuV2VH5wf2OakfphEDd2Q9d2y8ipPIZh4FxG C773FlBc65H03OiChnCeob0crVbVael65dZr7kfiyJM9XDhKtyqy1QgAY+zq43o0Jo2W KmwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766167599; x=1766772399; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=dW3bXX4vP+WteeSK3ew02UmI9wiau0xdWqe/ZXK117U=; b=bVc3YdPX5/Xy4jlKFEOZaYh+x6Cv/WCN1m3abUWrpgPSVRfMF/LWmo9xKNMGnfXF48 L0EckSWY+gblVwREK59znf0oYfvSsAbo6SsfiOT+w6ZFuglL/iqUi9+KEZZxTB8e4V++ EMggK9MXN96A7FAC0OswWYKQMZ5hMjuJ16GAXQn17aC+FaemeSPidTNxacbkTaCfoWKg WEsYfjf+g8hVxyHmCUBMymhpOPodilUW+Wfl7U9HnIZE8YOr/01vJmyPDPxlitIZ0l2G vwUoKJ/KG3G5bcXo25uHW+5N+NZTtkpEZMh3EtlaL7y1K2dkMk26hg541YkbjYI+E8pU pveg== X-Forwarded-Encrypted: i=1; AJvYcCXhPb7EkhPLUyjiHiwpY87ZSrPlVkce35pYuRXxQkMLYDFXR1NSnFZHUF6wNdjs5R0frskEgZvz/O+1hRI=@vger.kernel.org X-Gm-Message-State: AOJu0YxiC72aT1pyDSfsz6oNlRdNF5yuM80XCmwDa+enn+llxAxivkq4 daiHe2mMwF6ZwZKjjQ5MWgnTM89Bb5jc9IvyDzS+7JZONdsQU4Jyr0Od X-Gm-Gg: AY/fxX6fukSrdnXSSdg7rIrhaWUrFWdcYpHX3U5hJN2yHhEgdmxJM9u33eqgkQGNCd7 mB5HbHRqGirXTekBGMA/GSmeb32auhaxEaMwjJEGbTHPay0XBVLxLUtJaWpbbyUyqor9H9ZuTHL JvLX5ygDy0oabMe7Wm2gbRHUdQoRurwi61tJDtE9n5iudyXFDupy/RyNfUnTLe4UwIuDeiAs8Jn kAzifuXbm+GXwA/aKCtTiZFf0RXfGtpzIAgi7d4XlvSMZ5PLlS25oUg8tUPyXGgp5PuvVcJg2wH hjgdGkbk8Vvl+dCe9BN00gdhXChC5SNW9NrTb27ZLWTcKGtlW4kETnRDW/giD6WI6DgPHrE7kia 8gFrKqVhvev8E0jAbia7+NMYb1Vmu3ebI5eT6OZljSeHDRP3fM81+xGAT4Sa3yvZAg3q90h6ZzT EPiY6kvL6YHW44LjA9B8Ko89zoRcTrJPkkoi7KtkehEw8EQJMqYdcuXcahZxjyHbA1fEYfX+s= X-Google-Smtp-Source: AGHT+IGe/PQZJEf5gTpe3Qj3z8NAvg1R45BbPbrsdavVKhN2FFhW7JZT5OmWh7zVxEj1sac9wjAXyA== X-Received: by 2002:a05:6a20:3d06:b0:35f:c643:105e with SMTP id adf61e73a8af0-376a81dc6e1mr3504223637.34.1766167598563; Fri, 19 Dec 2025 10:06:38 -0800 (PST) Received: from carrot.devel.local (i114-180-53-102.s42.a014.ap.plala.or.jp. [114.180.53.102]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c1e7961c130sm2688468a12.3.2025.12.19.10.06.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Dec 2025 10:06:37 -0800 (PST) From: Ryusuke Konishi To: Viacheslav Dubeyko Cc: linux-nilfs , LKML Subject: [PATCH 1/3] nilfs2: Fix potential block overflow that cause system hang Date: Sat, 20 Dec 2025 03:04:25 +0900 Message-ID: <20251219180631.27554-2-konishi.ryusuke@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251219180631.27554-1-konishi.ryusuke@gmail.com> References: <20251219180631.27554-1-konishi.ryusuke@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Edward Adam Davis When a user executes the FITRIM command, an underflow can occur when calculating nblocks if end_block is too small. Since nblocks is of type sector_t, which is u64, a negative nblocks value will become a very large positive integer. This ultimately leads to the block layer function __blkdev_issue_discard() taking an excessively long time to process the bio chain, and the ns_segctor_sem lock remains held for a long period. This prevents other tasks from acquiring the ns_segctor_sem lock, resulting in the hang reported by syzbot in [1]. If the ending block is too small, typically if it is smaller than 4KiB range, depending on the usage of the segment 0, it may be possible to attempt a discard request beyond the device size causing the hang. Exiting successfully and assign the discarded size (0 in this case) to range->len. Although the start and len values in the user input range are too small, a conservative strategy is adopted here to safely ignore them, which is equivalent to a no-op; it will not perform any trimming and will not throw an error. [1] task:segctord state:D stack:28968 pid:6093 tgid:6093 ppid:2 task_flags:0x2= 00040 flags:0x00080000 Call Trace: rwbase_write_lock+0x3dd/0x750 kernel/locking/rwbase_rt.c:272 nilfs_transaction_lock+0x253/0x4c0 fs/nilfs2/segment.c:357 nilfs_segctor_thread_construct fs/nilfs2/segment.c:2569 [inline] nilfs_segctor_thread+0x6ec/0xe00 fs/nilfs2/segment.c:2684 [ryusuke: corrected part of the commit message about the consequences] Fixes: 82e11e857be3 ("nilfs2: add nilfs_sufile_trim_fs to trim clean segs") Reported-by: syzbot+7eedce5eb281acd832f0@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=3D7eedce5eb281acd832f0 Signed-off-by: Edward Adam Davis Signed-off-by: Ryusuke Konishi Cc: stable@vger.kernel.org --- fs/nilfs2/sufile.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/nilfs2/sufile.c b/fs/nilfs2/sufile.c index 83f93337c01b..eceedca02697 100644 --- a/fs/nilfs2/sufile.c +++ b/fs/nilfs2/sufile.c @@ -1093,6 +1093,9 @@ int nilfs_sufile_trim_fs(struct inode *sufile, struct= fstrim_range *range) else end_block =3D start_block + len - 1; =20 + if (end_block < nilfs->ns_first_data_block) + goto out; + segnum =3D nilfs_get_segnum_of_block(nilfs, start_block); segnum_end =3D nilfs_get_segnum_of_block(nilfs, end_block); =20 @@ -1191,6 +1194,7 @@ int nilfs_sufile_trim_fs(struct inode *sufile, struct= fstrim_range *range) out_sem: up_read(&NILFS_MDT(sufile)->mi_sem); =20 +out: range->len =3D ndiscarded << nilfs->ns_blocksize_bits; return ret; } --=20 2.43.0