From nobody Wed Dec 29 08:25:25 2021 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 F09251912266; Wed, 29 Dec 2021 08:25:25 +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 4JP4GY52mSz4bcP; Wed, 29 Dec 2021 08:25:25 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 8CEFE2192B; Wed, 29 Dec 2021 08:25:25 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1BT8PPV2013903; Wed, 29 Dec 2021 08:25:25 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1BT8PPxc013902; Wed, 29 Dec 2021 08:25:25 GMT (envelope-from git) Date: Wed, 29 Dec 2021 08:25:25 GMT Message-Id: <202112290825.1BT8PPxc013902@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: =?utf-8?Q?Roger Pau Monn=C3=A9?= Subject: git: 60e749da3c8b - main - mbuf_tags: use explicitly sized type for 'type' parameter 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: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: royger X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 60e749da3c8b9b42cb7b044bea0b380daf1e70e9 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1640766325; 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=naz3QAR0lBEprRw58UwFtZTIv1/S8A9tjYsi/eBzCk4=; b=Ix5vLA40n+tUEzVmCVRxzgZSUraHRWPBZc+v7D/g3vnKFaE8NwNk27n7mybTCo4o4VPCRf CF1lrFFwd2iteSHrHAqe5T8pHrB1/xn46ugGDIMM3xJGk2yGdaFCZ1sGSaUT0nh1ZSiIPc JK1y9lHhWURUFXTVRoEnBgWWf753ae5iHmURQkKj1Z4cdoxpBXA6iTVYm6+FvH8QIRJygd 8Qtmj6qoS138E+9foZdJkSEOX1SLUQSnrwmiJu9pdLrBCTbNgsFAHbq3u/URM3ly7aIKY7 CQtVMuMgy/98/VRwFRHsDArV4DhRhwIYX/nZCrhQO9DVXSjk+UIabKRGr6bzZw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1640766325; a=rsa-sha256; cv=none; b=NuGmie5YNSDQV8dUb11vqLhaPb7RIXRI5HrvMI85oDNDxW7xZe+t8kr7t0tmLuGIDTC790 0fNFWhxW6QAXEOH+QXaUAg+hXMfFTOvFaWTTxzaY5o4TPg5LKWFSTGkVOEyDKKN4TyWZfh 3D5q0qc2ivjOZxtusC0DeGpL0muxfhP1OPzQ5vqkuzd2kr2NKg5DoyF08duIP85aZqX10i 3fKx0q85RHl4Z0hUOgWuJ5nxbo/clajRkP3+DFiGhmRnpXVvfFQd8rR1CnXXpib6gNYJ8V EDhKt83LtiZm597AjtLU670jWKJmxOuGYvJuOIe0LNTYxchW4NlKi7m3z49gdQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by royger: URL: https://cgit.FreeBSD.org/src/commit/?id=60e749da3c8b9b42cb7b044bea0b380daf1e70e9 commit 60e749da3c8b9b42cb7b044bea0b380daf1e70e9 Author: Roger Pau Monné AuthorDate: 2021-12-28 08:13:57 +0000 Commit: Roger Pau Monné CommitDate: 2021-12-29 08:23:52 +0000 mbuf_tags: use explicitly sized type for 'type' parameter Functions manipulating mbuf tags are using an int type for passing the 'type' parameter, but the internal tag storage is using a 16bit integer to store it. This leads to the following code: t = m_tag_alloc(...,0xffffffff,...,...); m_tag_prepend(m, t); r = m_tag_locate(m ,...,0xffffffff, NULL); Returning r == NULL because m_tag_locate doesn't truncate the type parameter when doing the match. This is unexpected because the type of the 'type' parameter is int, and the caller doesn't need to know about the internal truncations. Fix this by making the 'type' parameter of type uint16_t in order to match the size of its internal storage and make it obvious to the caller the actual size of the parameter. While there also use uint uniformly replacing the existing u_int instances. Reviewed by: kp, donner, glebius Differential revision: https://reviews.freebsd.org/D33680 --- share/man/man9/mbuf_tags.9 | 10 +++++----- sys/kern/uipc_mbuf2.c | 4 ++-- sys/sys/mbuf.h | 11 ++++++----- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/share/man/man9/mbuf_tags.9 b/share/man/man9/mbuf_tags.9 index 66be8377b100..9f3e8c064054 100644 --- a/share/man/man9/mbuf_tags.9 +++ b/share/man/man9/mbuf_tags.9 @@ -20,7 +20,7 @@ .\" .\" $FreeBSD$ .\" -.Dd January 12, 2008 +.Dd December 28, 2021 .Dt MBUF_TAGS 9 .Os .Sh NAME @@ -29,7 +29,7 @@ .Sh SYNOPSIS .In sys/mbuf.h .Ft "struct m_tag *" -.Fn m_tag_alloc "uint32_t cookie" "int type" "int len" "int wait" +.Fn m_tag_alloc "uint32_t cookie" "uint16_t type" "int len" "int wait" .Ft "struct m_tag *" .Fn m_tag_copy "struct m_tag *t" "int how" .Ft int @@ -41,17 +41,17 @@ .Ft void .Fn m_tag_delete_nonpersistent "struct mbuf *m" .Ft "struct m_tag *" -.Fn m_tag_find "struct mbuf *m" "int type" "struct m_tag *start" +.Fn m_tag_find "struct mbuf *m" "uint16_t type" "struct m_tag *start" .Ft "struct m_tag *" .Fn m_tag_first "struct mbuf *m" .Ft void .Fn m_tag_free "struct m_tag *t" .Ft "struct m_tag *" -.Fn m_tag_get "int type" "int len" "int wait" +.Fn m_tag_get "uint16_t type" "int len" "int wait" .Ft void .Fn m_tag_init "struct mbuf *m" .Ft struct m_tag * -.Fn m_tag_locate "struct mbuf *m" "uint32_t cookie" "int type" "struct m_tag *t" +.Fn m_tag_locate "struct mbuf *m" "uint32_t cookie" "uint16_t type" "struct m_tag *t" .Ft "struct m_tag *" .Fn m_tag_next "struct mbuf *m" "struct m_tag *t" .Ft void diff --git a/sys/kern/uipc_mbuf2.c b/sys/kern/uipc_mbuf2.c index 40aa45d3cfb4..571751e7fd51 100644 --- a/sys/kern/uipc_mbuf2.c +++ b/sys/kern/uipc_mbuf2.c @@ -314,7 +314,7 @@ m_tag_free_default(struct m_tag *t) /* Get a packet tag structure along with specified data following. */ struct m_tag * -m_tag_alloc(uint32_t cookie, int type, int len, int wait) +m_tag_alloc(uint32_t cookie, uint16_t type, int len, int wait) { struct m_tag *t; @@ -376,7 +376,7 @@ m_tag_delete_nonpersistent(struct mbuf *m) /* Find a tag, starting from a given position. */ struct m_tag * -m_tag_locate(struct mbuf *m, uint32_t cookie, int type, struct m_tag *t) +m_tag_locate(struct mbuf *m, uint32_t cookie, uint16_t type, struct m_tag *t) { struct m_tag *p; diff --git a/sys/sys/mbuf.h b/sys/sys/mbuf.h index 07a75bd5b47b..cea2c3820143 100644 --- a/sys/sys/mbuf.h +++ b/sys/sys/mbuf.h @@ -1369,11 +1369,12 @@ extern bool mb_use_ext_pgs; /* Use ext_pgs for sendfile */ /* Specific cookies and tags. */ /* Packet tag routines. */ -struct m_tag *m_tag_alloc(u_int32_t, int, int, int); +struct m_tag *m_tag_alloc(uint32_t, uint16_t, int, int); void m_tag_delete(struct mbuf *, struct m_tag *); void m_tag_delete_chain(struct mbuf *, struct m_tag *); void m_tag_free_default(struct m_tag *); -struct m_tag *m_tag_locate(struct mbuf *, u_int32_t, int, struct m_tag *); +struct m_tag *m_tag_locate(struct mbuf *, uint32_t, uint16_t, + struct m_tag *); struct m_tag *m_tag_copy(struct m_tag *, int); int m_tag_copy_chain(struct mbuf *, const struct mbuf *, int); void m_tag_delete_nonpersistent(struct mbuf *); @@ -1395,7 +1396,7 @@ m_tag_init(struct mbuf *m) * XXX probably should be called m_tag_init, but that was already taken. */ static __inline void -m_tag_setup(struct m_tag *t, u_int32_t cookie, int type, int len) +m_tag_setup(struct m_tag *t, uint32_t cookie, uint16_t type, int len) { t->m_tag_id = type; @@ -1457,13 +1458,13 @@ m_tag_unlink(struct mbuf *m, struct m_tag *t) #define MTAG_ABI_COMPAT 0 /* compatibility ABI */ static __inline struct m_tag * -m_tag_get(int type, int length, int wait) +m_tag_get(uint16_t type, int length, int wait) { return (m_tag_alloc(MTAG_ABI_COMPAT, type, length, wait)); } static __inline struct m_tag * -m_tag_find(struct mbuf *m, int type, struct m_tag *start) +m_tag_find(struct mbuf *m, uint16_t type, struct m_tag *start) { return (SLIST_EMPTY(&m->m_pkthdr.tags) ? (struct m_tag *)NULL : m_tag_locate(m, MTAG_ABI_COMPAT, type, start));