Bug 245712 - iflib: ift_mtx_name is too small
Summary: iflib: ift_mtx_name is too small
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: Mark Johnston
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-04-17 21:27 UTC by ghuckriede
Modified: 2020-05-07 14:50 UTC (History)
2 users (show)

See Also:
koobs: mfc-stable12?
koobs: mfc-stable11-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description ghuckriede 2020-04-17 21:27:53 UTC
Overview:

'ift_mtx_name' https://svnweb.freebsd.org/base/head/sys/net/iflib.c?annotate=359436#l362 has size of 16 bytes

When it is initialized https://svnweb.freebsd.org/base/head/sys/net/iflib.c?annotate=359436#l5522 the format string "%s:TX(%d):callout" already uses 14 of those bytes (including the NULL terminator).  This leaves 2 bytes for the 'nameunit' string and the 'ift_id' number, which clearly is not enough.

I see 2 possible fixes:
1. Increase the 'ift_mtx_name' array size ('nameunit' is not really a fixed size, so how much?).
2. Change 'ift_mtx_name' to a pointer and alloc an appropriately sized string, and free it on destroy.

Actual Results:
'ift_mtx_name' is truncated even in the best case (i.e. 2 character interface name).
e.g. "em0:TX(0):callo"


Expected Results:
No truncation.

Build Date & Hardware:
# uname -a
FreeBSD FreeBSD_head_ghuckriede 13.0-CURRENT FreeBSD 13.0-CURRENT #2 r360017: Fri Apr 17 11:16:38 EDT 2020
ghuckriede@FreeBSD_head_ghuckriede:/usr/obj/usr/src/amd64.amd64/sys/GENERIC  amd64

Additional Builds and Platforms:
na

Additional Information:
na
Comment 1 Mark Johnston freebsd_committer freebsd_triage 2020-04-30 15:34:48 UTC
I think we could simply extend the array to 32 bytes.  The mutex name is grouped with other rarely-accessed fields at the end of the structure, and we will not waste a significant amount of memory relative to the total size of the structure.
Comment 2 commit-hook freebsd_committer freebsd_triage 2020-04-30 15:39:20 UTC
A commit references this bug:

Author: markj
Date: Thu Apr 30 15:39:04 UTC 2020
New revision: 360498
URL: https://svnweb.freebsd.org/changeset/base/360498

Log:
  Increase the iflib txq callout mutex name length to 32 bytes.

  With a length of 16, the name ("<if name>:TX(<qid>):callout") typically
  gets truncated.

  PR:		245712
  Reported by:	ghuckriede@blackberry.com
  MFC after:	1 week

Changes:
  head/sys/net/iflib.c
Comment 3 commit-hook freebsd_committer freebsd_triage 2020-05-07 14:50:19 UTC
A commit references this bug:

Author: markj
Date: Thu May  7 14:49:18 UTC 2020
New revision: 360781
URL: https://svnweb.freebsd.org/changeset/base/360781

Log:
  MFC r360498:
  Increase the iflib txq callout mutex name length to 32 bytes.

  PR:	245712

Changes:
_U  stable/12/
  stable/12/sys/net/iflib.c