From nobody Mon Jan 13 21:28:57 2025 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 4YX53s4Psyz5kqwT; Mon, 13 Jan 2025 21:28:57 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YX53s2WLlz3jpr; Mon, 13 Jan 2025 21:28:57 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1736803737; 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=bm8f++XJ3GCJMC+axkzuRyw8CG9fcIIBig4UjDSnti0=; b=QW05vmg1UIQIV2fn1CezJ4QRH4FB49fTTJbHzUAMFc6A/41O54L64j+H1esAyFt05sgc2d d7ZpYEXpPw6mFjXzcUu55Jvpp4Z2nCAIQyFcmHlvu0DfbYJVhkv7ZZzc8ixqzRWgInohGN DU4HYBtr2Lj1pWTmHQqZYIeh/USp5huJnwyup/onZxZzsgaCENs1Fhnk1DbHjPFBMS/TXV X0Gap22ZinIICTGa/7X3seLqv3zJcLsBIjs1eBcR7+XiQubqwsDPhHog1n9oQY9pVDod3U ycPYV7AQD6l5Vx6NAsTLPUWWlJQHPL/BpZh2zjHDNIYXj4a50mcBiL1q9CWQJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1736803737; 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=bm8f++XJ3GCJMC+axkzuRyw8CG9fcIIBig4UjDSnti0=; b=f9aNtXp4LmDe3ZZVQp3SYBTmArvlb/hIWmJj+mJ5yNuyWXJ0p+K2ETG5IY07kUa7QKUSZH C7V3ln3o7ss1Eh5awZya6UFPQGIwJPQG73730oNzAiJH0mA9XRuEzqZ2H6iZHMwMg++tmX jVbY6PFq6oG+d7zYNR9I4cf6X+toHrK55oFLb6t0CiL/wcf8L2lP30EFnHcdB8zbYJPpN7 nXJVho0/o3CIf/+FFEa3awCePT2y99hjKnSfvPxXrADcwEiGn1S33hi1MsIEJlC5PWzDDe R4Ca5YK3UhAltNX9cOS54tT0VkX3ra0lnOgL5hRF25V8MRn+C0cYwmBMSpBaAA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1736803737; a=rsa-sha256; cv=none; b=fJFQszY69r/5PdEoqTf345SazwLESds6eCkdqZrPADhYGumqrj9fh5NYOOB8NPBoCHORRj lRqBmRkCdK8aUORQUbYoQg9nhqlvRwfptJoaT5mjzBSi1GHZfET9U4B2Y7cmgMjdHl1Pqo hyElhg0tbWBtL94sQQIvstAcg23iHVLQm6ssSYPNVy+gpbIsT5/MGPSQKnu1VJ0jHVXlB8 XVECrSBwXLGRP+HCt+MBqUg3yzpSyOFdNYNzZKjkjDME/oRHlDZD0dUFsOtl8XsbKiZq9G WykiQEGQGZpuqOKih1mWyrV9Lchhc4V/phVeLmlLIsRQouQ43mhKJxpCST53NA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4YX53s26fWzndt; Mon, 13 Jan 2025 21:28:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 50DLSvMP066634; Mon, 13 Jan 2025 21:28:57 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 50DLSv5Z066631; Mon, 13 Jan 2025 21:28:57 GMT (envelope-from git) Date: Mon, 13 Jan 2025 21:28:57 GMT Message-Id: <202501132128.50DLSv5Z066631@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: 6ed3486980c9 - main - netlink: avoid underflow of groups bitset index 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: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 6ed3486980c95bfa2cbc0b19739e93e8c0df9f67 Auto-Submitted: auto-generated The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=6ed3486980c95bfa2cbc0b19739e93e8c0df9f67 commit 6ed3486980c95bfa2cbc0b19739e93e8c0df9f67 Author: Gleb Smirnoff AuthorDate: 2025-01-13 21:27:32 +0000 Commit: Gleb Smirnoff CommitDate: 2025-01-13 21:27:53 +0000 netlink: avoid underflow of groups bitset index The subtraction is absolutely unnecessary and created an underflow with 926d2eadcb67. I don't see why it was useful before 926d2eadcb67 and even before edf5608bfef3. The bitset addresses bits from zero to NLP_MAX_GROUPS-1. Note that check of user supplied argument for NETLINK_ADD_MEMBERSHIP and NETLINK_DROP_MEMBERSHIP socket options is already correct !(optval >= NLP_MAX_GROUPS). Fixes: 926d2eadcb671dd26431a1082d4c49c3d5ad7f22 --- sys/netlink/netlink_domain.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/sys/netlink/netlink_domain.c b/sys/netlink/netlink_domain.c index 45d427f43166..00eb2923eddf 100644 --- a/sys/netlink/netlink_domain.c +++ b/sys/netlink/netlink_domain.c @@ -138,8 +138,7 @@ nl_port_lookup(uint32_t port_id) static void nl_add_group_locked(struct nlpcb *nlp, unsigned int group_id) { - MPASS(group_id <= NLP_MAX_GROUPS); - --group_id; + MPASS(group_id < NLP_MAX_GROUPS); /* TODO: add family handler callback */ if (!nlp_unconstrained_vnet(nlp)) @@ -151,8 +150,7 @@ nl_add_group_locked(struct nlpcb *nlp, unsigned int group_id) static void nl_del_group_locked(struct nlpcb *nlp, unsigned int group_id) { - MPASS(group_id <= NLP_MAX_GROUPS); - --group_id; + MPASS(group_id < NLP_MAX_GROUPS); BIT_CLR(NLP_MAX_GROUPS, group_id, &nlp->nl_groups); } @@ -160,8 +158,7 @@ nl_del_group_locked(struct nlpcb *nlp, unsigned int group_id) static bool nl_isset_group_locked(struct nlpcb *nlp, unsigned int group_id) { - MPASS(group_id <= NLP_MAX_GROUPS); - --group_id; + MPASS(group_id < NLP_MAX_GROUPS); return (BIT_ISSET(NLP_MAX_GROUPS, group_id, &nlp->nl_groups)); }