Page MenuHomeFreeBSD

fibs: restrict jail_attach(2) if process fibnum >= numfibs in the jail.
ClosedPublic

Authored by melifaro on Feb 11 2023, 3:44 PM.
Tags
None
Referenced Files
F82003766: D38505.id116984.diff
Wed, Apr 24, 9:45 AM
Unknown Object (File)
Tue, Apr 23, 8:54 AM
Unknown Object (File)
Mon, Apr 1, 12:06 AM
Unknown Object (File)
Wed, Mar 27, 9:27 PM
Unknown Object (File)
Jan 27 2024, 9:08 AM
Unknown Object (File)
Dec 20 2023, 5:02 AM
Unknown Object (File)
Nov 22 2023, 8:25 AM
Unknown Object (File)
Oct 15 2023, 5:49 AM
Subscribers

Details

Summary

Currently, process fibnum is not changed in jail_attach(2) and is inherited by the other processes afterwards.
If jail has its own VNET and number of fibs in this VNET is less than in the host system, it can lead to a panic.

This diff checks if the process fibnum is still valid in the new VNET and returns error if that's not true.

Test Plan

Before:

jail -c name=bug persist vnet
sysctl net.fibs=3
setfib 2 jexec bug ping -c 1 1.1.1

PING 1.1.1 (1.1.0.1): 56 data bytes
client_loop: send disconnect: Broken pipe

...
Fatal trap 12: page fault while in kernel mode

After:

jail -c name=bug persist vnet
sysctl net.fibs=3
setfib 2 jexec bug ping -c 1 1.1.1
jexec: jail_attach(1): Operation not permitted

Diff Detail

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

Event Timeline

melifaro edited the test plan for this revision. (Show Details)
melifaro added reviewers: network, olivier.

How is that possible that in your example you got EPERM, but the patch provides EINVAL?

How is that possible that in your example you got EPERM, but the patch provides EINVAL?

I forgot to change variable type from bool to int.

kp added a subscriber: kp.
kp added inline comments.
sys/net/route/route_tables.c
176

I worried about races here, but if I'm reading sysctl_fibs() right we can only ever grow V_rt_numfibs, so that should be fine.

I might spell this

if (td->td_proc->p_fibnum < V_rt_numfibs)
    error = EINVAL;

but that's more a question of preference than a real issue to discuss.

This revision is now accepted and ready to land.Feb 12 2023, 10:17 AM

Fixed the crash here:

setfib 2 jexec bug ping -c 1 1.1.1.1
jexec: jail_attach(1): Invalid argument
sys/net/route/route_tables.c
176

Thank you for the review!

I worried about races here, but if I'm reading sysctl_fibs() right we can only ever grow V_rt_numfibs, so that should be fine.

Yes, it's indeed grow-only. There are quite a lot of things that need to be handled correctly to permit decreasing V_rt_numfibs.

I might spell this

if (td->td_proc->p_fibnum < V_rt_numfibs)
    error = EINVAL;

Yep, that indeed looks more readable.