From nobody Tue Dec 03 20:05:00 2024 X-Original-To: dev-commits-src-main@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 4Y2s7x09sKz5ggFF; Tue, 03 Dec 2024 20:05:01 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Y2s7w4kqfz4lS1; Tue, 3 Dec 2024 20:05:00 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1733256300; 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=lPXSjX3eiVn2DNedCbC4qzZ4wJki68AEs7urQagww3c=; b=kLlcOqEjijt/UKd/dfHrd2t1BNL1j+GcFzr1AjKt2ROSdK/6WofE68ZlXzeY+vxge9+w1/ AsapCYeLTqaxQ3xElNt7LdSBMt71+HvuW0hrUgOYxsqYxoWtD9VMxxb+cDgIV4OQ/bVtPl lLIZi0JRG5aUsgconVFuR7PyuOzf9doKOapRnVptxoX3tH8zwcSC9/5jC7rW1EazHMtmUf 8D7r1nWXFUK/3NSyXZCviw7vnFgMr+PXUL7MUGC2S9rGelW7MW23Ge/jESDCwsORZrjftj i462KA43izbnt43seku+yz+L5DmrGTHg5oX06mRKkCDs/2bANzF5xmw/i2rGsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1733256300; 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=lPXSjX3eiVn2DNedCbC4qzZ4wJki68AEs7urQagww3c=; b=tR28JP70JOblY1ui9ObugfJWbI1jjB1HbJaKrX3m0ACb2Idy37LCpZTnD55reoXVCKcNya dLi3zaasNWgzx+AsNVPyjIQoU0/ln8rdxx6/UDfxsbQMwwjXTI5c+f4hlAyq1IsFVRgqPa qhC7h4yeXn0csYeSkS+8jwmkSfmdvySnm2JQG8/wHH6HKFT27aIFV9k6aT6/Dsh0noQ3gQ 9VbzeP03ODriD/OhGEomYqEUuiUN+6naexE3gvqIHztYlzJ7jn/l6pft+y8S3pAALz8WaV BBxoK68ih9KaEjYT+7XkEtGCtyy4/WzyNfAxpEPyEPeq46iyBgqLumAJ/0Zl0g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1733256300; a=rsa-sha256; cv=none; b=QbmeZVrjf6SAnQS/IYUXENgveUPFfTQjDNwdgvqAGZu2Vt1sslZYx7Ti0l3zdvvk1fOfxk yDC/UCarF76nDFW2iRzFDDbkFKMW+5KMz7Z7cvbMUEbcbqbuwVQKD9olZp6lX0nLljjXVV uylrxOD/Vdh1LwVFHenf3Psp/09SeYP2VgMJip+TjBoXA0aOiXaB2rFWJF3QAXYPsVcvqb 2GfgP2jv4uH5SN4ueqlUKBEMLagSL5WAktKKCGFL94g7kcQb7lsN8tE7qyhhRPD+RWuSJ1 GdvXyNlThOA0MAsq3KzvpX2domJqaTHXggI/kkz4pCFHrntAKtI5Q7vV7J/3Lg== 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 4Y2s7w42Lfzd1H; Tue, 3 Dec 2024 20:05:00 +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 4B3K50B4061804; Tue, 3 Dec 2024 20:05:00 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4B3K50t3061801; Tue, 3 Dec 2024 20:05:00 GMT (envelope-from git) Date: Tue, 3 Dec 2024 20:05:00 GMT Message-Id: <202412032005.4B3K50t3061801@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: 6380058fe5b5 - main - netlink: use correct uint16_t type for attribute type & length List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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: 6380058fe5b5573ce2eb1a077d95ac9328e19334 Auto-Submitted: auto-generated The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=6380058fe5b5573ce2eb1a077d95ac9328e19334 commit 6380058fe5b5573ce2eb1a077d95ac9328e19334 Author: Gleb Smirnoff AuthorDate: 2024-12-03 20:04:30 +0000 Commit: Gleb Smirnoff CommitDate: 2024-12-03 20:04:30 +0000 netlink: use correct uint16_t type for attribute type & length Reviewed by: melifaro Differential Revision: https://reviews.freebsd.org/D47552 --- sys/netlink/netlink_message_writer.c | 8 ++++++-- sys/netlink/netlink_message_writer.h | 38 +++++++++++++++++++----------------- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/sys/netlink/netlink_message_writer.c b/sys/netlink/netlink_message_writer.c index 092e3798f8e7..1aebc4690c2d 100644 --- a/sys/netlink/netlink_message_writer.c +++ b/sys/netlink/netlink_message_writer.c @@ -363,11 +363,15 @@ nlmsg_reserve_data_raw(struct nl_writer *nw, size_t sz) } bool -nlattr_add(struct nl_writer *nw, int attr_type, int attr_len, const void *data) +nlattr_add(struct nl_writer *nw, uint16_t attr_type, uint16_t attr_len, + const void *data) { struct nl_buf *nb = nw->buf; struct nlattr *nla; - u_int required_len; + size_t required_len; + + KASSERT(attr_len <= UINT16_MAX - sizeof(struct nlattr), + ("%s: invalid attribute length %u", __func__, attr_len)); required_len = NLA_ALIGN(attr_len + sizeof(struct nlattr)); if (__predict_false(nb->datalen + required_len > nb->buflen)) { diff --git a/sys/netlink/netlink_message_writer.h b/sys/netlink/netlink_message_writer.h index 9469883feaa7..1655acb53fef 100644 --- a/sys/netlink/netlink_message_writer.h +++ b/sys/netlink/netlink_message_writer.h @@ -214,93 +214,95 @@ _nlmsg_reserve_attr(struct nl_writer *nw, uint16_t nla_type, uint16_t sz) } #define nlmsg_reserve_attr(_ns, _at, _t) ((_t *)_nlmsg_reserve_attr(_ns, _at, NLA_ALIGN(sizeof(_t)))) -bool nlattr_add(struct nl_writer *nw, int attr_type, int attr_len, +bool nlattr_add(struct nl_writer *nw, uint16_t attr_type, uint16_t attr_len, const void *data); static inline bool nlattr_add_raw(struct nl_writer *nw, const struct nlattr *nla_src) { - int attr_len = nla_src->nla_len - sizeof(struct nlattr); + MPASS(nla_src->nla_len >= sizeof(struct nlattr)); - MPASS(attr_len >= 0); - - return (nlattr_add(nw, nla_src->nla_type, attr_len, (const void *)(nla_src + 1))); + return (nlattr_add(nw, nla_src->nla_type, + nla_src->nla_len - sizeof(struct nlattr), + (const void *)(nla_src + 1))); } static inline bool -nlattr_add_bool(struct nl_writer *nw, int attrtype, bool value) +nlattr_add_bool(struct nl_writer *nw, uint16_t attrtype, bool value) { return (nlattr_add(nw, attrtype, sizeof(bool), &value)); } static inline bool -nlattr_add_u8(struct nl_writer *nw, int attrtype, uint8_t value) +nlattr_add_u8(struct nl_writer *nw, uint16_t attrtype, uint8_t value) { return (nlattr_add(nw, attrtype, sizeof(uint8_t), &value)); } static inline bool -nlattr_add_u16(struct nl_writer *nw, int attrtype, uint16_t value) +nlattr_add_u16(struct nl_writer *nw, uint16_t attrtype, uint16_t value) { return (nlattr_add(nw, attrtype, sizeof(uint16_t), &value)); } static inline bool -nlattr_add_u32(struct nl_writer *nw, int attrtype, uint32_t value) +nlattr_add_u32(struct nl_writer *nw, uint16_t attrtype, uint32_t value) { return (nlattr_add(nw, attrtype, sizeof(uint32_t), &value)); } static inline bool -nlattr_add_u64(struct nl_writer *nw, int attrtype, uint64_t value) +nlattr_add_u64(struct nl_writer *nw, uint16_t attrtype, uint64_t value) { return (nlattr_add(nw, attrtype, sizeof(uint64_t), &value)); } static inline bool -nlattr_add_s8(struct nl_writer *nw, int attrtype, int8_t value) +nlattr_add_s8(struct nl_writer *nw, uint16_t attrtype, int8_t value) { return (nlattr_add(nw, attrtype, sizeof(int8_t), &value)); } static inline bool -nlattr_add_s16(struct nl_writer *nw, int attrtype, int16_t value) +nlattr_add_s16(struct nl_writer *nw, uint16_t attrtype, int16_t value) { return (nlattr_add(nw, attrtype, sizeof(int16_t), &value)); } static inline bool -nlattr_add_s32(struct nl_writer *nw, int attrtype, int32_t value) +nlattr_add_s32(struct nl_writer *nw, uint16_t attrtype, int32_t value) { return (nlattr_add(nw, attrtype, sizeof(int32_t), &value)); } static inline bool -nlattr_add_s64(struct nl_writer *nw, int attrtype, int64_t value) +nlattr_add_s64(struct nl_writer *nw, uint16_t attrtype, int64_t value) { return (nlattr_add(nw, attrtype, sizeof(int64_t), &value)); } static inline bool -nlattr_add_flag(struct nl_writer *nw, int attrtype) +nlattr_add_flag(struct nl_writer *nw, uint16_t attrtype) { return (nlattr_add(nw, attrtype, 0, NULL)); } static inline bool -nlattr_add_string(struct nl_writer *nw, int attrtype, const char *str) +nlattr_add_string(struct nl_writer *nw, uint16_t attrtype, const char *str) { return (nlattr_add(nw, attrtype, strlen(str) + 1, str)); } static inline bool -nlattr_add_in_addr(struct nl_writer *nw, int attrtype, const struct in_addr *in) +nlattr_add_in_addr(struct nl_writer *nw, uint16_t attrtype, + const struct in_addr *in) { return (nlattr_add(nw, attrtype, sizeof(*in), in)); } static inline bool -nlattr_add_in6_addr(struct nl_writer *nw, int attrtype, const struct in6_addr *in6) +nlattr_add_in6_addr(struct nl_writer *nw, uint16_t attrtype, + const struct in6_addr *in6) { return (nlattr_add(nw, attrtype, sizeof(*in6), in6)); }