From nobody Thu Apr 2 01:10:08 2026 Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) (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 92A2E2FD1C2 for ; Tue, 31 Mar 2026 00:46:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774917984; cv=none; b=pVths4qwpjvulhfXxSHnUN0VqssUvVzfaRWNLGaWr7dU6vGLSaUPaj+oehZKUgqofAng43wZ1n20I5+DGreKSf3hBGAbYPG93zJTZ16vU00aB9y0+iySM4cMZ9zAfYOnvJ8IYKMJOz4T5Cutt/rFPAwJNoWr9+O6OdqAWqTTmn8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774917984; c=relaxed/simple; bh=szY4mNjBwA4sXA35aXtFtA1syL8zW/DsCNugR40jNoM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=IUiLFPt10/LYeEI4p2ilXNBd7wPGVnvEfnXUa1qwpaduYZ9LfLuddPKewfMwkKByuvzS+UDO5YUmxztlZ8SuR3CcEoNpc8U7fCx+EWbkw2VKSjndcW0Eji3dLjG+leFugF4hNVj5esAsENpoVasTnwUMvvv/tfLLuQH9fOO0BWo= 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=ryMpQalb; arc=none smtp.client-ip=209.85.215.169 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="ryMpQalb" Received: by mail-pg1-f169.google.com with SMTP id 41be03b00d2f7-c76b070f109so170481a12.0 for ; Mon, 30 Mar 2026 17:46:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774917983; x=1775522783; 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; bh=LECHvJZc33MhPE+YpDHyc2MU3obeNqRtjSr6EjmaShM=; b=ryMpQalb/x2MBB8GNRBxdcZ7ac4hfMf2vYsp0dHrvlDktpvsXXygW09nJZ6E5B9aG3 RTVGPdHQkCPjxYbpTILEAXoN879Nh4NqTrgi5L9Ynmwu9KlcMEX3PzsHjosQez74Pq/9 mAUzXMVblVsMg/tSTPIXclfsieLGzskX+aH7irG5mhCFcYfbhzuCxfaMigjoAvwMdtyD WcMucRab+LF3k1Tz7AR4jQqxCfbmlyCtQ9JerXWBBAQm17dmI1RXHtjxMvGcguByqoY2 WvBQOhNsEeW2mvmApEVVCEDr/YEtOqGtkapcry8pHU6eiieKmEUAk8s6OU/GpHDmbVtQ 4HHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774917983; x=1775522783; 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; bh=LECHvJZc33MhPE+YpDHyc2MU3obeNqRtjSr6EjmaShM=; b=pnFULEaRuMS2G323kF5QhUVfTbKD2f2DNeq6K9+eyX/fSSgDvNOmxEDbodbl4nEqPw sslYHhJBE59l73ZE1YKW+dsmBYuUhPkkv0kvOUJysw3EayH3x2Gj0TgKP9MqHpLVQzOl 9IjNVnmw3Z2RYlAyUZWXo7MQ2TQDt5brj43U9wOJTDIbmAI8j4J7oylAiLII3fJK+WS3 rRUKchtul4OhUTesN6qu3C5L8tvf8GUvkee+lWiJBB7VUrNE5rNEBrfj3g/HcKE0Svas GVAgd9uPsHjo/oMjRgJJNy9adseOW9LJVh3rUNFv9UQ9d0jhMjemfvcr0M8Kjho2QRfi wO5w== X-Forwarded-Encrypted: i=1; AJvYcCWxsya0OZHMiu2R5vDwDeuWBQ8+cp0/bnFJh0E+8R0rfjY/tI79lSxmk/0S6U4dBFfj6jFqO3RLefWnv1Y=@vger.kernel.org X-Gm-Message-State: AOJu0YwhWNPxpNGudFHgUf4Q34KjWInzUxiN+ZYAYIV25RB1fJbGmS4l WTBussBNZEOJD+qHNV3kfV2q6Wl/UqJf82HFqVDdzwCJHLnAGB9pDmHbGkPETrar X-Gm-Gg: ATEYQzyhbLRkfKzdKVjbreo1C2aSYjT5+riONWkwFUNs6aHqdLM6BsXhcuvcTzG30EU wU4GryfryiznoZOdI0bJKmm9ej8D3rGqmGKFH7ZWF3FrtpVr7pcb841kaT5GgeUPPULIlf+Nm90 OYVf07pc6HEjzFkNbKjx9C0MDbFNhQahQhkw8HlHvlvEr7rmFzHzilvTj2TQx+6ROzWWyWupH39 O2bkbYPgF5Sz/5P+sVYgoIqk74Mhcpkbkk3ZZdiIef1Z1n5G25YN1rJE13Kau66ycuqJRuttQQk UWICCJph5BLKst5wjjstq3ssyc4KNdWxCp82P/j9n/N6AeEKfd2t2OAWcNxH4gGBb3IE1wNp7KO asaJZy8CuYHFyKcUdYIDVItPrs991PfR0DN1jmT4oZLYO7UlZBhpY3Q8belQ5C/hmsfSOyPJP5F cIo3tThsI+/rP6y1Qz+Zg5prA/R0ru2J595n4kezQI2ishD7ixLEDkeKPt8q4RJ0Jcglq1t975j UWes8+wyTPKK9F2mQ== X-Received: by 2002:a05:6a20:e292:b0:39b:9644:6e93 with SMTP id adf61e73a8af0-39c8787d577mr15747879637.6.1774917982785; Mon, 30 Mar 2026 17:46:22 -0700 (PDT) Received: from deepanshu-kernel-hacker.. ([2405:201:682f:389d:913e:67a2:7555:d878]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c769179e31asm7240696a12.17.2026.03.30.17.46.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Mar 2026 17:46:22 -0700 (PDT) From: Deepanshu Kartikey To: konishi.ryusuke@gmail.com, slava@dubeyko.com Cc: akpm@linux-foundation.org, sato.koji@lab.ntt.co.jp, linux-nilfs@vger.kernel.org, linux-kernel@vger.kernel.org, junjie.cao@linux.dev, Deepanshu Kartikey , syzbot+98a040252119df0506f8@syzkaller.appspotmail.com, Deepanshu Kartikey Subject: [PATCH v2] nilfs2: reject zero bd_oblocknr in nilfs_ioctl_mark_blocks_dirty() Date: Tue, 31 Mar 2026 06:16:13 +0530 Message-ID: <20260331004614.385712-1-kartikey406@gmail.com> X-Mailer: git-send-email 2.43.0 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" nilfs_ioctl_mark_blocks_dirty() uses bd_oblocknr to detect dead blocks by comparing it with the current block number bd_blocknr. If they differ, the block is considered dead and skipped. However, bd_oblocknr should never be 0 since block 0 stores the primary superblock and is never a valid GC target block. A corrupted ioctl request with bd_oblocknr set to 0 causes the comparison to incorrectly match when the lookup returns -ENOENT and sets bd_blocknr to 0, bypassing the dead block check and calling nilfs_bmap_mark() on a non-existent block. This causes nilfs_btree_do_lookup() to return -ENOENT, triggering the WARN_ON(ret =3D=3D -ENOENT). Fix this by rejecting ioctl requests with bd_oblocknr set to 0 at the beginning of each iteration. Changes in v2: - Instead of adding a continue statement after setting bd_blocknr to 0, reject the ioctl request with -EINVAL when bd_oblocknr is 0, as block 0 stores the primary superblock and is never a valid GC target block. (Suggested by Ryusuke Konishi) Fixes: 7942b919f732 ("nilfs2: ioctl operations") Reported-by: syzbot+98a040252119df0506f8@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=3D98a040252119df0506f8 Suggested-by: Ryusuke Konishi Signed-off-by: Deepanshu Kartikey --- fs/nilfs2/ioctl.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fs/nilfs2/ioctl.c b/fs/nilfs2/ioctl.c index e17b8da66491..d25ba27b5203 100644 --- a/fs/nilfs2/ioctl.c +++ b/fs/nilfs2/ioctl.c @@ -736,6 +736,12 @@ static int nilfs_ioctl_mark_blocks_dirty(struct the_ni= lfs *nilfs, int ret, i; =20 for (i =3D 0; i < nmembs; i++) { + /* bd_oblocknr must never be 0 as block 0 + * stores the primary superblock and is + * never a valid GC target block + */ + if (unlikely(!bdescs[i].bd_oblocknr)) + return -EINVAL; /* XXX: use macro or inline func to check liveness */ ret =3D nilfs_bmap_lookup_at_level(bmap, bdescs[i].bd_offset, --=20 2.43.0