Bug 289134 - ifconfig -j -g not executed in Jail
Summary: ifconfig -j -g not executed in Jail
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 16.0-CURRENT
Hardware: Any Any
: --- Affects Many People
Assignee: Dag-Erling Smørgrav
URL: https://reviews.freebsd.org/D52501
Keywords:
Depends on:
Blocks:
 
Reported: 2025-08-27 18:04 UTC by Niclas Wagner
Modified: 2025-09-22 17:45 UTC (History)
3 users (show)

See Also:
des: mfc-stable15+
des: mfc-stable14+
des: mfc-stable13-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Niclas Wagner 2025-08-27 18:04:36 UTC
When using the -j flag on ifconfig with the -g flag,
the execution happens on the host not in the jail.

Expected behavior:

ifconfig -j 1 -g epair -> List the epair inside the vnet jail

Observed behavior:

ifconfig -j 1 -g epair -> Lists all epairs on the host

root@srv01:~ # ifconfig -j 1 -g epair
epair254a
epair222a
epair21a
epair20a
epair253a
epair120a

root@srv01:~ # ifconfig -g epair
epair254a
epair222a
epair21a
epair20a
epair253a
epair120a

Work around:

root@srv01:~ # jexec 1 ifconfig -g epair 
epair254b

Some hint whats going on:

root@srv01:~ # truss ifconfig -j 1 -g epair 2>&1 | grep jail
open("/lib/libjail.so.1",O_RDONLY|O_CLOEXEC|O_VERIFY,04) = 3 (0x3)

root@srv01:~ # truss jexec 1 ifconfig -g epair 2>&1 | grep jail
open("/lib/libjail.so.1",O_RDONLY|O_CLOEXEC|O_VERIFY,04) = 3 (0x3)
jail_get(0x5bd7ef5b6938,0x4,0x0)		 = 1 (0x1)
jail_attach(0x1)				 = 0 (0x0)
open("/lib/libjail.so.1",O_RDONLY|O_CLOEXEC|O_VERIFY,04) = 3 (0x3)
Comment 1 commit-hook freebsd_committer freebsd_triage 2025-09-15 17:58:18 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=18fd1443d205aed6be22966125a4820f77571948

commit 18fd1443d205aed6be22966125a4820f77571948
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2025-09-15 17:56:33 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2025-09-15 17:56:33 +0000

    ifconfig: Enter jail as soon as possible

    Some options (in particular, -g) are processed immediately upon being
    parsed.  This will produce the wrong result in combination with -j since
    we only attach to the jail after we're done parsing arguments.  Solve
    this by attaching to the jail immediately when -j is encountered.  The
    downside is that e.g. `ifconfig -j foo -j bar` would previously attach
    to jail “bar”, whereas now it will attempt to attach to jail “foo”, and
    if successful, attempt to attach to jail “bar” within jail “foo”.  This
    may be considered a feature.

    PR:             289134
    MFC after:      1 week
    Reviewed by:    zlei
    Differential Revision:  https://reviews.freebsd.org/D52501

 sbin/ifconfig/ifconfig.8 | 42 +++++++++++++++++++++---------------------
 sbin/ifconfig/ifconfig.c | 22 ++++++++--------------
 sbin/ifconfig/ifconfig.h |  1 -
 3 files changed, 29 insertions(+), 36 deletions(-)
Comment 2 commit-hook freebsd_committer freebsd_triage 2025-09-22 12:09:12 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=e1401a283d101acd94d14d769a0a2d80c34a65dc

commit e1401a283d101acd94d14d769a0a2d80c34a65dc
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2025-09-15 17:56:33 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2025-09-22 10:29:54 +0000

    ifconfig: Enter jail as soon as possible

    Some options (in particular, -g) are processed immediately upon being
    parsed.  This will produce the wrong result in combination with -j since
    we only attach to the jail after we're done parsing arguments.  Solve
    this by attaching to the jail immediately when -j is encountered.  The
    downside is that e.g. `ifconfig -j foo -j bar` would previously attach
    to jail “bar”, whereas now it will attempt to attach to jail “foo”, and
    if successful, attempt to attach to jail “bar” within jail “foo”.  This
    may be considered a feature.

    PR:             289134
    MFC after:      1 week
    Reviewed by:    zlei
    Differential Revision:  https://reviews.freebsd.org/D52501

    (cherry picked from commit 18fd1443d205aed6be22966125a4820f77571948)

 sbin/ifconfig/ifconfig.8 | 42 +++++++++++++++++++++---------------------
 sbin/ifconfig/ifconfig.c | 22 ++++++++--------------
 sbin/ifconfig/ifconfig.h |  1 -
 3 files changed, 29 insertions(+), 36 deletions(-)
Comment 3 commit-hook freebsd_committer freebsd_triage 2025-09-22 12:09:13 UTC
A commit in branch stable/15 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=6d3de817987ac7c3b0dc661feec954ecb0a53861

commit 6d3de817987ac7c3b0dc661feec954ecb0a53861
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2025-09-15 17:56:33 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2025-09-22 10:26:59 +0000

    ifconfig: Enter jail as soon as possible

    Some options (in particular, -g) are processed immediately upon being
    parsed.  This will produce the wrong result in combination with -j since
    we only attach to the jail after we're done parsing arguments.  Solve
    this by attaching to the jail immediately when -j is encountered.  The
    downside is that e.g. `ifconfig -j foo -j bar` would previously attach
    to jail “bar”, whereas now it will attempt to attach to jail “foo”, and
    if successful, attempt to attach to jail “bar” within jail “foo”.  This
    may be considered a feature.

    PR:             289134
    MFC after:      1 week
    Reviewed by:    zlei
    Differential Revision:  https://reviews.freebsd.org/D52501

    (cherry picked from commit 18fd1443d205aed6be22966125a4820f77571948)

 sbin/ifconfig/ifconfig.8 | 42 +++++++++++++++++++++---------------------
 sbin/ifconfig/ifconfig.c | 22 ++++++++--------------
 sbin/ifconfig/ifconfig.h |  1 -
 3 files changed, 29 insertions(+), 36 deletions(-)