Page MenuHomeFreeBSD

mbuf_tags: use explicitly sized type for 'type' parameter
ClosedPublic

Authored by royger on Dec 28 2021, 8:56 AM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, May 8, 8:56 PM
Unknown Object (File)
Apr 1 2024, 4:05 AM
Unknown Object (File)
Feb 10 2024, 9:31 AM
Unknown Object (File)
Jan 25 2024, 5:19 AM
Unknown Object (File)
Jan 12 2024, 3:09 PM
Unknown Object (File)
Dec 20 2023, 6:36 AM
Unknown Object (File)
Nov 26 2023, 1:43 AM
Unknown Object (File)
Oct 12 2023, 9:07 AM
Subscribers

Details

Summary

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 u_int16_t in order to
match the size of its internal storage and make it obvious to the
caller the actual size of the parameter.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

kp added a subscriber: kp.

Presumably you've done a make universe with this?

Sensible change anyway, we should avoid leaving landmines like that around where innocent people (or me!) could step on them.

share/man/man9/mbuf_tags.9
23

Don't forget to bump this when you commit.

sys/kern/uipc_mbuf2.c
317

We probably should try to be consistent about u_int vs. uint use.
Sadly the declaration in the header is already inconsistent with this. Perhaps that should be fixed at the same time as this.

Thanks! Will run the universe build if there are no further comments.

sys/kern/uipc_mbuf2.c
317

My preference would be to use uint, I don't mind fixing the lines I have to modify anyway if that's OK.

donner added a subscriber: donner.

Good catch

This revision is now accepted and ready to land.Dec 28 2021, 5:36 PM