From owner-svn-src-head@freebsd.org Sat Oct 24 16:17:08 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id D182144DD8F; Sat, 24 Oct 2020 16:17:08 +0000 (UTC) (envelope-from freqlabs@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 "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4CJR7m5BhQz3Vpy; Sat, 24 Oct 2020 16:17:08 +0000 (UTC) (envelope-from freqlabs@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 7B7371B2AB; Sat, 24 Oct 2020 16:17:08 +0000 (UTC) (envelope-from freqlabs@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 09OGH8rt094678; Sat, 24 Oct 2020 16:17:08 GMT (envelope-from freqlabs@FreeBSD.org) Received: (from freqlabs@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 09OGH8ZN094676; Sat, 24 Oct 2020 16:17:08 GMT (envelope-from freqlabs@FreeBSD.org) Message-Id: <202010241617.09OGH8ZN094676@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: freqlabs set sender to freqlabs@FreeBSD.org using -f From: Ryan Moeller Date: Sat, 24 Oct 2020 16:17:08 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r367009 - in head: sbin/sysctl sys/kern X-SVN-Group: head X-SVN-Commit-Author: freqlabs X-SVN-Commit-Paths: in head: sbin/sysctl sys/kern X-SVN-Commit-Revision: 367009 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 24 Oct 2020 16:17:08 -0000 Author: freqlabs Date: Sat Oct 24 16:17:07 2020 New Revision: 367009 URL: https://svnweb.freebsd.org/changeset/base/367009 Log: sysctl+kern_sysctl: Honor SKIP for descendant nodes Ensure we also skip descendants of SKIP nodes when iterating through children of an explicitly specified node. Reported by: np Reviewed by: np MFC after: 1 week Sponsored by: iXsystems, Inc. Differential Revision: https://reviews.freebsd.org/D26833 Modified: head/sbin/sysctl/sysctl.c head/sys/kern/kern_sysctl.c Modified: head/sbin/sysctl/sysctl.c ============================================================================== --- head/sbin/sysctl/sysctl.c Sat Oct 24 16:11:46 2020 (r367008) +++ head/sbin/sysctl/sysctl.c Sat Oct 24 16:17:07 2020 (r367009) @@ -952,6 +952,7 @@ oidfmt(int *oid, int len, char *fmt, u_int *kind) static int show_var(int *oid, int nlen, bool honor_skip) { + static int skip_len = 0, skip_oid[CTL_MAXNAME]; u_char buf[BUFSIZ], *val, *oval, *p; char name[BUFSIZ], fmt[BUFSIZ]; const char *sep, *sep1, *prntype; @@ -1021,9 +1022,21 @@ show_var(int *oid, int nlen, bool honor_skip) return (0); } + /* keep track of encountered skip nodes, ignoring descendants */ + if (skip_len == 0 && (kind & CTLFLAG_SKIP) != 0) { + /* Save this oid so we can skip descendants. */ + skip_len = nlen * sizeof(int); + memcpy(skip_oid, oid, skip_len); + } + /* bail before fetching the value if we're honoring skip */ - if (honor_skip && (kind & CTLFLAG_SKIP) != 0) - return (1); + if (honor_skip) { + if (0 < skip_len && skip_len <= nlen * (int)sizeof(int) && + memcmp(skip_oid, oid, skip_len) == 0) + return (1); + /* Not a skip node or descendant of a skip node. */ + skip_len = 0; + } /* don't fetch opaques that we don't know how to print */ if (ctltype == CTLTYPE_OPAQUE) { Modified: head/sys/kern/kern_sysctl.c ============================================================================== --- head/sys/kern/kern_sysctl.c Sat Oct 24 16:11:46 2020 (r367008) +++ head/sys/kern/kern_sysctl.c Sat Oct 24 16:17:07 2020 (r367009) @@ -1126,9 +1126,13 @@ sysctl_sysctl_next_ls(struct sysctl_oid_list *lsp, int * We have reached a node with a full name match and are * looking for the next oid in its children. * + * For CTL_SYSCTL_NEXTNOSKIP we are done. + * * For CTL_SYSCTL_NEXT we skip CTLTYPE_NODE (unless it * has a handler) and move on to the children. */ + if (!honor_skip) + return (0); if ((oidp->oid_kind & CTLTYPE) != CTLTYPE_NODE) return (0); if (oidp->oid_handler) @@ -1163,9 +1167,13 @@ sysctl_sysctl_next_ls(struct sysctl_oid_list *lsp, int /* * We have reached the next oid. * + * For CTL_SYSCTL_NEXTNOSKIP we are done. + * * For CTL_SYSCTL_NEXT we skip CTLTYPE_NODE (unless it * has a handler) and move on to the children. */ + if (!honor_skip) + return (0); if ((oidp->oid_kind & CTLTYPE) != CTLTYPE_NODE) return (0); if (oidp->oid_handler)