From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) (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 822AB40DFA3 for ; Tue, 19 May 2026 09:41:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779183704; cv=none; b=Pcuh3cYHBig2LLzZG2ldrnHP06VZGnJJv81Vb7iJAH0BGk7027KeQssK4OUNL3CCEqAWWZUWh4j5rcNACbFof7X+sXSANhBqjZCGT3yF3kjkroU1hhKcZkb+8C7c5Kcvrn2FQbm4e7khA+IUcM+RKFFUAzEJFuF+ZM4+yo+JAy0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779183704; c=relaxed/simple; bh=HWfUxPfYscSIW9k1qDbIOfe/mSljB1Gv/XVXTVAhy6o=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=onoFqSzM6Zcasb+Bt884qZBR4ulmn/s2YfcjTB6YhXEdfg1DBUeryoMYx+lOOTpV1WbovEv6ce+CmURDpn9rGR/7Mm2Dxw78wXoTMYT6+eI3/WLwMgH6zU3lm5rmOxcs+cLLNU6IHp9wg7GFTf6sTw69x+wIPvLc3wjpZV9yo6w= 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=M3zoIwam; arc=none smtp.client-ip=209.85.216.45 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="M3zoIwam" Received: by mail-pj1-f45.google.com with SMTP id 98e67ed59e1d1-367cbac9cb1so3133576a91.3 for ; Tue, 19 May 2026 02:41:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779183696; x=1779788496; 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=RkcnvoW7fcNh19SzTtFYiuusZgm3lpkLEpTJ1iXQXd0=; b=M3zoIwamjrbSv1cDvRPG6nvwoXGXb2u3yd0Pg48u7KfAUvDZV3VuBk4Rek+7PO6+AO +DuNy42zYACYnCtSHrYY1pwlrRzA2NVmh0akHDNwxcSgztohUO3inCYi2jBdQ2KAi1Dc tV3Ae1IH0mSh3gJt+W8vkJ3tbe64jQe62w4Lcckpf5tPKTCOgnpu2RGJoOjqZOZXlCx1 4VagmnZQEPo1nSacyvTzrWaKf5fkiyr+fFJ4WKVzwznahEfBAzGfcYxLbum6gLY5toJz 4nDF0CsRUokyUbXenKxyqsgclD74xyA/YMbp8ujQG0XKpqYEKmFrOhJ31r2OGObRg0ZG AU/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779183696; x=1779788496; 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=RkcnvoW7fcNh19SzTtFYiuusZgm3lpkLEpTJ1iXQXd0=; b=WrSR1v11hJz7QzQoHRtulck3bjaGoffSWZPHBtKzEAS26NWAu6yFpy9WbLjuNNSLz5 Q56VdFQVA3rTdp2QxPcDYYyYFsFQlRWRrGYytThlSgYO+w6Q200s+eYl1+/UDKAvkmVe Nsedx2d94uZucw64N6hBa7BgpZY6Xu1dxuojd7JJHS9aTerGhrI8L7YyAip5ut8wMQeb KSUqCu8eyKSp9r7jMDyQrxYi+SiZVMvXq8GrdJiS33tpwJvLFtQA3yzdyZAi697Xp8Hj 4Y2OTDMFUsewj51bt2tlSKZbUZciYdLIfcAkOyBlm6L+03TibbZ90+KtgDQIrhBwafG4 bDKA== X-Forwarded-Encrypted: i=1; AFNElJ/savRoQodjzS9C2Vl/jIKDD/CpephpyFxkzm0GS7tgIzCyKgBIOPiboQWTq95M37ETMdPULmg7jgab53w=@vger.kernel.org X-Gm-Message-State: AOJu0Yx93Bvn+Htn4j/JUOi35HtpgpKC1MgcztTaw9+uQaJor+rMk23H df2vIXIQPJ5vCdqcMskhUk/UXMQqNhlUh/i6Ig1C7Q1Cge4N30tyygelX8VygA== X-Gm-Gg: Acq92OEaeSgPNwPZNSRARw/KhsZFxXkVQyxQfKwxRTp9pcvhi4TBp5hDWyo9WglbcyE 36dmVstVDmtZlR1iaMTB9pKyOLqIl8gkXTEG0pmBOudtEixw0Zylk6pd1N/pi1mp43WJDKlWIM2 oabx+MqjndUwBC9npZaEIUThQUcjT3/DXP0K9MOsVjqINVxTLQhWxwLIDF/1A2Tr+WdCD5Kug0j 7Xohe8qU8fJb/NZiAQjXMyNl0fDy+xY0pLLO+gUsUdouCoUFzzFYOHcCaVXCnTvWOlJ/2ziSeWH 3W4uIbRffpU0GMHI2/tCmrR/CNMm0xw6eoTxrkFOW7kfuPUUXRx6+jVukXxmRpx04I28mNnO93Z 87uAO5Svv5Fy4JbVxt8KU4L5R+llDjxrKb/u+281/b6KOcPXMG/iSIZaMDMAKLOp6Md9Fcf+kqZ YEeb0ou2ZHO8oLfIMm7tTS81Z8eMs8u8eFt9VKmshS30zqS4zZ X-Received: by 2002:a17:90b:260b:b0:368:ed92:6f3 with SMTP id 98e67ed59e1d1-36951b89773mr20374375a91.18.1779183696382; Tue, 19 May 2026 02:41:36 -0700 (PDT) Received: from csl-conti-dell7858.ntu.edu.sg ([155.69.195.57]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-36951059f4dsm13101437a91.0.2026.05.19.02.41.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 May 2026 02:41:35 -0700 (PDT) From: Maoyi Xie To: Matthew Sakai Cc: dm-devel@lists.linux.dev, linux-kernel@vger.kernel.org Subject: dm-vdo: iterator after loop end in mark_slab_journal_dirty? Date: Tue, 19 May 2026 17:41:32 +0800 Message-Id: <20260519094132.1964544-1-maoyixie.tju@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Hi all, While reading drivers/md/dm-vdo/slab-depot.c I noticed something that looks like a past the end iterator pattern. I would appreciate it if you could take a look and let me know whether this is a real issue, and whether it is worth fixing. The site is mark_slab_journal_dirty() (linux-7.1-rc1, around line 156): list_for_each_entry_reverse(dirty_journal, dirty_list, dirty_entry) { if (dirty_journal->recovery_lock <= journal->recovery_lock) break; } list_move_tail(&journal->dirty_entry, dirty_journal->dirty_entry.next); When the loop walks all entries without break (the new journal's recovery_lock is smaller than every existing entry), dirty_journal is past the end. dirty_journal->dirty_entry then aliases dirty_list (the list head) via container_of offset cancellation. So dirty_journal->dirty_entry.next is head->next, the first real entry. list_move_tail then inserts journal just before the first entry, i.e. at the front of the list. That is the intended behaviour for a sorted insertion where the new entry has the smallest recovery_lock. The dereference of the past the end iterator is undefined per C11. Jakob Koschel cleaned up many such sites in 2022, for example commits 99d8ae4ec8a (tracing: Remove usage of list iterator variable after the loop), 2966a9918df (clockevents: Use dedicated list iterator variable) and dc1acd5c946 (dlm: replace usage of found with dedicated list iterator variable). This site was not covered. A candidate fix would track an explicit insertion target. Declare `struct list_head *insert_after = dirty_list` before the loop. Overwrite it to `&dirty_journal->dirty_entry` only when the loop breaks early. The final list_move_tail then reads `insert_after->next`. On break that points to the entry right after the insertion position. On fall-through it points to `head->next`, the first real entry. The behaviour is unchanged in all cases, including an empty list and a list with one entry. If this is intentional or already known, please disregard. Otherwise, I am happy to send a [PATCH] or to leave the fix to you. Thank you for your time, and sorry for the noise if this is not actually worth fixing or has already been spotted. Thanks, Maoyi Xie https://maoyixie.com/