From nobody Sat May 11 14:16:28 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Vc78r6PGVz5KCVx; Sat, 11 May 2024 14:16:28 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (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 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Vc78r5swhz4t79; Sat, 11 May 2024 14:16:28 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1715436988; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=IBCWj8vUZWBO+CE3T93yUzuuKPxbsOyyINk6aV0IlUo=; b=DnYrJz2P4PDCvZWJinnuLojEknmrUiTApWpjOlaTgUPckJzlDx33ItTxjyL5ePHApFdVaM K48jqR9va4F1ECRm3Ppr8NRSbUrfmiOOtW+HTjYmew52sWRH5F9XQH9U+zQMkeu3rS2MIs T8DZzfbkPHj+GNBkVC6EAHl0V+GVEllyJbM0ZgPuskKwQ0z8UJKLIi2HbznBy/UteI62YP +3gPQOaRbFJrF1Z/Ybpo1mIfN3k0Mxrs+KWTOVDgOrhWsaudTpLZXrI4RpVbi2/GGgmmiJ lMkfDPlcvOGVzfMveWWqEahamKh1taitR4EA6CrCTelG6llXrxVe/JYezq8shg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1715436988; a=rsa-sha256; cv=none; b=qwMzudNWAk7WPoJbo7t19SItne7Ty5Mseyfu+pH9eRDz0tgaF4YL6g0THtP3mvtaxd0RYX PDjXNarK2MK1z/+brDDi7UsWxL7UFWq5De252lmeboOO7Gb6avo3qwo5OpTPCKVgYcQQzW LX1pcE8FvvQUCQH6euFwjFDsZxtuRj1O/J6wpLXTopBoPblBj0raC8viI/I+VY5v7qGcwl DoG/nlgqhLU8BNx86+9nsxkvEb7+nKvYeNvrfu3onhukeGR+gE8otYNwQHLPkp7WSu8+KD rqWKGnf0wl6w2Pk1G5dCQgMiKbWKw+ZpWG+jZ87aS8kwLXtqLS+/NfdLgLOu5g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1715436988; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=IBCWj8vUZWBO+CE3T93yUzuuKPxbsOyyINk6aV0IlUo=; b=ZZYtxM1wrCpYtrnjBJYRTnGIjlWWnl7cgnJ3Wf9xhgKabJ4Mt++FHZbqWCHBjEfDlukkSk PuV+ukgNgim+8hiZUkgq6b2oxCKdr+3uvFIR0HcPdeGFukI6sIfoaKorKolZ3aXqSMt+rF uz0HiAZnd2GR4Bs1qhmYVY7UjyWaPTxd537xuADnbQ4/tazKdXiYg4gHl+aii/fv6uppvP MtLmcQAgwv3rm5B3FsgXyS04kgJlOukaLSBBPcUIhFhBH6VGr4qJGXlipICGI+8sVQf3ly Nj4ujyNHGkTgI98e/bXZRQ3tLK70vqcYvsS5VANo+dLzRFf8bKAa32KGka5Nww== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Vc78r503BzNV5; Sat, 11 May 2024 14:16:28 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 44BEGSKt004304; Sat, 11 May 2024 14:16:28 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 44BEGSvQ004301; Sat, 11 May 2024 14:16:28 GMT (envelope-from git) Date: Sat, 11 May 2024 14:16:28 GMT Message-Id: <202405111416.44BEGSvQ004301@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 24268f262b41 - stable/14 - sysctl: Make sysctl_ctx_free() a bit safer List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 24268f262b41cd82ed492b4b0776214e549a56e7 Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=24268f262b41cd82ed492b4b0776214e549a56e7 commit 24268f262b41cd82ed492b4b0776214e549a56e7 Author: Mark Johnston AuthorDate: 2024-05-01 11:57:56 +0000 Commit: Mark Johnston CommitDate: 2024-05-11 14:15:21 +0000 sysctl: Make sysctl_ctx_free() a bit safer Clear the list before returning so that sysctl_ctx_free() can be called more than once on the same list without side effects. This simplifies error handling in drivers; previously, drivers would have to be careful to call sysctl_ctx_free() at most once to avoid a use-after-free. While here, use TAILQ_FOREACH_SAFE in the loop which unregisters OIDs. Reviewed by: thj, emaste MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D45041 (cherry picked from commit d5eae57088f5eec5df49fea8e8623521f596db68) --- sys/kern/kern_sysctl.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c index 814579a80f5a..53b61c08713f 100644 --- a/sys/kern/kern_sysctl.c +++ b/sys/kern/kern_sysctl.c @@ -634,17 +634,15 @@ sysctl_ctx_free(struct sysctl_ctx_list *clist) return(EBUSY); } /* Now really delete the entries */ - e = TAILQ_FIRST(clist); - while (e != NULL) { - e1 = TAILQ_NEXT(e, link); + TAILQ_FOREACH_SAFE(e, clist, link, e1) { error = sysctl_remove_oid_locked(e->entry, 1, 0); if (error) panic("sysctl_remove_oid: corrupt tree, entry: %s", e->entry->oid_name); free(e, M_SYSCTLOID); - e = e1; } SYSCTL_WUNLOCK(); + TAILQ_INIT(clist); return (error); }