Discussion:
[CFT] capsicum patches for rtsol(8) and rtsold(8)
Add Reply
Mark Johnston
2018-10-15 19:42:45 UTC
Reply
Permalink
Hi,

Last week I spent some time Capsicumizing rtsol(8) and rtsold(8). The
code for these programs is relatively straightforward, and seems like an
ideal candidate for sandboxing given that it parses ND6 RAs while
running with privileges (which has led to one SA in the past).

I currently don't run rtsold as my home ISP only gives me an IPv4
address. I did a fair amount of testing on an internal network and used
packet captures to verify everything, but I was hoping that some folks
who actually rely on rtsol(d) would be willing to test the patch before
I try to get it reviewed.

The patch is here:
https://people.freebsd.org/~markj/patches/rtsold_capsicum.diff
and a review and description for the capsicum portions is here, if
anyone is interested:
https://reviews.freebsd.org/D17572

The patch is a superset of the review contents; it contains some
unrelated fixes (for e.g., Coverity bugs) and cleanups.

To test the patch, apply it, rebuild sbin/rtsol and usr.sbin/rtsold,
and restart rtsold. It would be helpful to restart networking at this
point, or simply reboot. If the patch works properly, you shouldn't
notice any changes in behaviour. I'd be particularly interested in
hearing reports from anyone that uses -m or -O, or who depends upon the
processing of the RDNSS and DNSSL RA options.
Bjoern A. Zeeb
2018-10-16 16:06:43 UTC
Reply
Permalink
Post by Mark Johnston
https://people.freebsd.org/~markj/patches/rtsold_capsicum.diff
(0) the git rename doesn’t really work when applying the diff with
FreeBSD’s patch so the mv has to be done manually

(1) the rtsol Makefile also needs cap_syslog and util to link to
otherwise rtsold.c has unresolved symbols

(2) rtsol seem to have worked when manually invoked; /etc/resolv.conf
was created (I had rm’ed it) and the 3 nameserver lines re-appeared;
sorry can’t test the search string here

(3) rtsold crashes:

***@i386-a3-carp:/ # gdb82 /usr/sbin/rtsold /rtsold.core
GNU gdb (GDB) 8.2 [GDB v8.2 for FreeBSD]
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "i386-portbld-freebsd12.0".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /usr/sbin/rtsold...Reading symbols from
/usr/lib/debug//usr/sbin/rtsold.debug...done.
done.
[New LWP 100091]
Core was generated by `/usr/sbin/rtsold -a'.
Program terminated with signal SIGABRT, Aborted.
#0 thr_kill () at thr_kill.S:3
3 thr_kill.S: No such file or directory.
(gdb) where
#0 thr_kill () at thr_kill.S:3
#1 0x281ca3a1 in __raise (s=6) at /usr/src/lib/libc/gen/raise.c:52
#2 0x281ca2e3 in abort () at /usr/src/lib/libc/stdlib/abort.c:67
#3 0x28246a98 in __assert (func=0x28092479 "cap_xfer_nvlist",
file=0x280925a3 "/usr/src/lib/libcasper/libcasper/libcasper.c",
line=304, failedexpr=0x280924d6 "chan != NULL") at
/usr/src/lib/libc/gen/assert.c:51
#4 0x28095a60 in cap_xfer_nvlist (chan=0x0, nvl=0x282940a0) at
/usr/src/lib/libcasper/libcasper/libcasper.c:304
#5 0x2809a1ce in cap_vsyslog (chan=0x0, priority=3, fmt=0xffbfe7cc
"<main> failed to initialize capabilities: %s", ap=0xffbfebec
"\210\266'( \354\277\377 ") at
/usr/src/lib/libcasper/services/cap_syslog/cap_syslog.c:72
#6 0x0804af2f in warnmsg (priority=3, func=0x804f163 "main",
msg=0x804f168 "failed to initialize capabilities: %s") at
/usr/src/usr.sbin/rtsold/rtsold.c:787
#7 0x0804abb3 in main (argc=<optimized out>, argv=<optimized out>) at
/usr/src/usr.sbin/rtsold/rtsold.c:255


/bz
Mark Johnston
2018-10-16 16:53:08 UTC
Reply
Permalink
Post by Bjoern A. Zeeb
Post by Mark Johnston
https://people.freebsd.org/~markj/patches/rtsold_capsicum.diff
(0) the git rename doesn’t really work when applying the diff with
FreeBSD’s patch so the mv has to be done manually
(1) the rtsol Makefile also needs cap_syslog and util to link to
otherwise rtsold.c has unresolved symbols
(2) rtsol seem to have worked when manually invoked; /etc/resolv.conf
was created (I had rm’ed it) and the 3 nameserver lines re-appeared;
sorry can’t test the search string here
Thanks. I made some last-minute changes and forgot to retest, of
course. :(

I uploaded a new patch which should fix all of these issues - could you
give it a try?
Bjoern A. Zeeb
2018-10-16 18:29:49 UTC
Reply
Permalink
Post by Mark Johnston
Post by Bjoern A. Zeeb
Post by Mark Johnston
https://people.freebsd.org/~markj/patches/rtsold_capsicum.diff
(0) the git rename doesn’t really work when applying the diff with
FreeBSD’s patch so the mv has to be done manually
(1) the rtsol Makefile also needs cap_syslog and util to link to
otherwise rtsold.c has unresolved symbols
(2) rtsol seem to have worked when manually invoked;
/etc/resolv.conf
was created (I had rm’ed it) and the 3 nameserver lines
re-appeared;
sorry can’t test the search string here
Thanks. I made some last-minute changes and forgot to retest, of
course. :(
I uploaded a new patch which should fix all of these issues - could you
give it a try?
With the old and new patch:

***@i386-a3-carp:/usr/src/sbin/rtsol # rtsol vtnet0
failed to run script: Invalid argument

Hadn’t noticed that before.


Also on a running system:

***@i386-a3-carp:/ # rm /etc/resolv.conf
***@i386-a3-carp:/ # cat /etc/resolv.conf
cat: /etc/resolv.conf: No such file or directory
***@i386-a3-carp:/ # sh /etc/rc.d/rtsold restart
Stopping rtsold.
Waiting for PIDS: 1047.
Starting rtsold.
***@i386-a3-carp:/ # cat /etc/resolv.conf
cat: /etc/resolv.conf: No such file or directory


After a reboot:

***@i386-a3-carp:~ # ps ax | grep rts
372 - SCs 0:00.01 /usr/sbin/rtsold -a
375 - Ss 0:00.01 rtsold: system.syslog (rtsold)
376 - S 0:00.00 rtsold: rtsold.script (rtsold)
693 u0 R+ 0:00.01 grep rts
***@i386-a3-carp:~ # cat /etc/resolv.conf
# Generated by resolvconf
nameserver ..

***@i386-a3-carp:~ # rtsol vtnet0
failed to run script: Invalid argument
***@i386-a3-carp:~ # sh /etc/rc.d/rtsold restart
Stopping rtsold.
Waiting for PIDS: 372.
Starting rtsold.
Oct 16 18:28:33 i386-a3-carp rtsold[734]: <call_script> failed to run
script: Invalid argument


/bz
Mark Johnston
2018-10-16 20:04:14 UTC
Reply
Permalink
Post by Bjoern A. Zeeb
Post by Mark Johnston
Post by Bjoern A. Zeeb
Post by Mark Johnston
https://people.freebsd.org/~markj/patches/rtsold_capsicum.diff
(0) the git rename doesn’t really work when applying the diff with
FreeBSD’s patch so the mv has to be done manually
(1) the rtsol Makefile also needs cap_syslog and util to link to
otherwise rtsold.c has unresolved symbols
(2) rtsol seem to have worked when manually invoked;
/etc/resolv.conf
was created (I had rm’ed it) and the 3 nameserver lines
re-appeared;
sorry can’t test the search string here
Thanks. I made some last-minute changes and forgot to retest, of
course. :(
I uploaded a new patch which should fix all of these issues - could you
give it a try?
failed to run script: Invalid argument
Hadn’t noticed that before.
That's a cosmetic bug. I uploaded a new patch which should fix it.
Post by Bjoern A. Zeeb
cat: /etc/resolv.conf: No such file or directory
Stopping rtsold.
Waiting for PIDS: 1047.
Starting rtsold.
cat: /etc/resolv.conf: No such file or directory
resolvconf -a will only update /etc/resolv.conf if the info in
/var/run/resolvconf/interfaces/vtnet0 has changed, I believe. Try
deleting that file too, and then try running rtsol.
Post by Bjoern A. Zeeb
372 - SCs 0:00.01 /usr/sbin/rtsold -a
375 - Ss 0:00.01 rtsold: system.syslog (rtsold)
376 - S 0:00.00 rtsold: rtsold.script (rtsold)
693 u0 R+ 0:00.01 grep rts
# Generated by resolvconf
nameserver ..
failed to run script: Invalid argument
Stopping rtsold.
Waiting for PIDS: 372.
Starting rtsold.
Oct 16 18:28:33 i386-a3-carp rtsold[734]: <call_script> failed to run
script: Invalid argument
/bz
Bjoern A. Zeeb
2018-10-22 11:57:44 UTC
Reply
Permalink
Post by Mark Johnston
Post by Bjoern A. Zeeb
Post by Mark Johnston
Post by Bjoern A. Zeeb
Post by Mark Johnston
https://people.freebsd.org/~markj/patches/rtsold_capsicum.diff
(0) the git rename doesn’t really work when applying the diff with
FreeBSD’s patch so the mv has to be done manually
(1) the rtsol Makefile also needs cap_syslog and util to link to
otherwise rtsold.c has unresolved symbols
(2) rtsol seem to have worked when manually invoked;
/etc/resolv.conf
was created (I had rm’ed it) and the 3 nameserver lines
re-appeared;
sorry can’t test the search string here
Thanks. I made some last-minute changes and forgot to retest, of
course. :(
I uploaded a new patch which should fix all of these issues - could you
give it a try?
failed to run script: Invalid argument
Hadn’t noticed that before.
That's a cosmetic bug. I uploaded a new patch which should fix it.
Same URL? I’d try to test that tomorrow then.
Post by Mark Johnston
Post by Bjoern A. Zeeb
cat: /etc/resolv.conf: No such file or directory
Stopping rtsold.
Waiting for PIDS: 1047.
Starting rtsold.
cat: /etc/resolv.conf: No such file or directory
resolvconf -a will only update /etc/resolv.conf if the info in
/var/run/resolvconf/interfaces/vtnet0 has changed, I believe. Try
deleting that file too, and then try running rtsol.
When I deleted /etc/resolv.conf and then rtsol manually it had
re-appeared. Unclear to me what was in /var/run; I just wanted to point
out the difference in behaviour; maybe you are right; I’ll go and
check if deleting in /var/run/ as well makes a difference.
Mark Johnston
2018-10-24 19:56:27 UTC
Reply
Permalink
Post by Bjoern A. Zeeb
Post by Mark Johnston
Post by Bjoern A. Zeeb
Post by Mark Johnston
Post by Bjoern A. Zeeb
Post by Mark Johnston
https://people.freebsd.org/~markj/patches/rtsold_capsicum.diff
(0) the git rename doesn’t really work when applying the diff with
FreeBSD’s patch so the mv has to be done manually
(1) the rtsol Makefile also needs cap_syslog and util to link to
otherwise rtsold.c has unresolved symbols
(2) rtsol seem to have worked when manually invoked;
/etc/resolv.conf
was created (I had rm’ed it) and the 3 nameserver lines
re-appeared;
sorry can’t test the search string here
Thanks. I made some last-minute changes and forgot to retest, of
course. :(
I uploaded a new patch which should fix all of these issues - could you
give it a try?
failed to run script: Invalid argument
Hadn’t noticed that before.
That's a cosmetic bug. I uploaded a new patch which should fix it.
Same URL? I’d try to test that tomorrow then.
Yes, I just uploaded a new version of the patch to
https://people.freebsd.org/~markj/patches/rtsold_capsicum.diff and would
appreciate any further testing that you can do.
Post by Bjoern A. Zeeb
Post by Mark Johnston
Post by Bjoern A. Zeeb
cat: /etc/resolv.conf: No such file or directory
Stopping rtsold.
Waiting for PIDS: 1047.
Starting rtsold.
cat: /etc/resolv.conf: No such file or directory
resolvconf -a will only update /etc/resolv.conf if the info in
/var/run/resolvconf/interfaces/vtnet0 has changed, I believe. Try
deleting that file too, and then try running rtsol.
When I deleted /etc/resolv.conf and then rtsol manually it had
re-appeared. Unclear to me what was in /var/run; I just wanted to point
out the difference in behaviour; maybe you are right; I’ll go and
check if deleting in /var/run/ as well makes a difference.
I don't observe that behaviour with either the stock or patched
rtsol(8): for resolvconf(8) to update /etc/resolv.conf (or re-generate
it), something under /var/run/resolvconf/interfaces needs to have
changed. So, in my case, deleting /etc/resolv.conf *and*
/var/run/resolvconf/interfaces/re0:slaac will cause resolv.conf to be
regenerated once rtsold(8) decides to re-run resolvconf(8), but
deleting resolv.conf on its own will not.
Bjoern A. Zeeb
2018-11-02 23:25:40 UTC
Reply
Permalink
On 24 Oct 2018, at 19:56, Mark Johnston wrote:

Hi,

sorry I lost track on this.
Post by Mark Johnston
Yes, I just uploaded a new version of the patch to
https://people.freebsd.org/~markj/patches/rtsold_capsicum.diff and would
appreciate any further testing that you can do.
The rtsol Makefile does not cleanly apply to my HEAD.

Also there seems to be an empty .else case in both rtsold and rtsol
Makefiles.

Also I couldn’t get rtsol to link until I realised that it was rescue
which didn’t want to link (-j24 output can be confusing). I guess
with -DSMALL gone and MK_CASPER not turned off for rescue or whatever it
is the result is not what we expect?

Just a few lines for you.

..
15229
^
15230 1 warning generated.
15231 iscsid_stub.c:1:70: warning: implicit declaration of function
'main' is invalid in C99 [-Wimplicit-function-declaration]
15232 int _crunched_iscsid_stub(int argc, char **argv, char
**envp){return main(argc,argv,envp);}
15233
^
15234 1 warning generated.
15235
/tank/users/bz/obj/tank/users/bz/git_bz_experimental_v6only/amd64.amd64/tmp/usr/bin/ld:
error: undefined symbol: cap_init
15236 >>> referenced by _$$hide$$ rtsol.lo rtsock.c
15237 >>> rtsol.lo:(_$$hide$$ rtsol.lo main)
15238
15239
/tank/users/bz/obj/tank/users/bz/git_bz_experimental_v6only/amd64.amd64/tmp/usr/bin/ld:
error: undefined symbol: cap_service_open
15240 >>> referenced by _$$hide$$ rtsol.lo rtsock.c
15241 >>> rtsol.lo:(_$$hide$$ rtsol.lo main)
15242
15243
/tank/users/bz/obj/tank/users/bz/git_bz_experimental_v6only/amd64.amd64/tmp/usr/bin/ld:
error: undefined symbol: cap_service_open
15244 >>> referenced by _$$hide$$ rtsol.lo rtsock.c
15245 >>> rtsol.lo:(_$$hide$$ rtsol.lo main)
15246
15247
/tank/users/bz/obj/tank/users/bz/git_bz_experimental_v6only/amd64.amd64/tmp/usr/bin/ld:
error: undefined symbol: cap_service_open
15248 >>> referenced by _$$hide$$ rtsol.lo rtsock.c
15249 >>> rtsol.lo:(_$$hide$$ rtsol.lo main)
15250
15251
/tank/users/bz/obj/tank/users/bz/git_bz_experimental_v6only/amd64.amd64/tmp/usr/bin/ld:
error: undefined symbol: nvlist_create
15252 >>> referenced by _$$hide$$ rtsol.lo rtsock.c
15253 >>> rtsol.lo:(_$$hide$$ rtsol.lo main)
15254
..
Post by Mark Johnston
Post by Bjoern A. Zeeb
Post by Mark Johnston
resolvconf -a will only update /etc/resolv.conf if the info in
/var/run/resolvconf/interfaces/vtnet0 has changed, I believe. Try
deleting that file too, and then try running rtsol.
When I deleted /etc/resolv.conf and then rtsol manually it had
re-appeared. Unclear to me what was in /var/run; I just wanted to point
out the difference in behaviour; maybe you are right; I’ll go and
check if deleting in /var/run/ as well makes a difference.
I don't observe that behaviour with either the stock or patched
rtsol(8): for resolvconf(8) to update /etc/resolv.conf (or re-generate
it), something under /var/run/resolvconf/interfaces needs to have
changed. So, in my case, deleting /etc/resolv.conf *and*
/var/run/resolvconf/interfaces/re0:slaac will cause resolv.conf to be
regenerated once rtsold(8) decides to re-run resolvconf(8), but
deleting resolv.conf on its own will not.
I wonder if that’s a bug (unrelated to yours). I also noticed that
when my nameservers changed /etc/resolv.conf did not always reflect
this.

/bz
Mark Johnston
2018-11-05 17:34:53 UTC
Reply
Permalink
Post by Bjoern A. Zeeb
Hi,
sorry I lost track on this.
No problem, thanks for testing.
Post by Bjoern A. Zeeb
Post by Mark Johnston
Yes, I just uploaded a new version of the patch to
https://people.freebsd.org/~markj/patches/rtsold_capsicum.diff and would
appreciate any further testing that you can do.
The rtsol Makefile does not cleanly apply to my HEAD.
I updated the patch yet again, it should apply this time. The newest
version requires HEAD as of r340130.
Post by Bjoern A. Zeeb
Also there seems to be an empty .else case in both rtsold and rtsol
Makefiles.
Fixed, thanks.
Post by Bjoern A. Zeeb
Also I couldn’t get rtsol to link until I realised that it was rescue
which didn’t want to link (-j24 output can be confusing). I guess
with -DSMALL gone and MK_CASPER not turned off for rescue or whatever it
is the result is not what we expect?
In other cases (e.g., ping(8)) we simply disable libcasper support for
rescue binaries, so I've done the same here.
Post by Bjoern A. Zeeb
Post by Mark Johnston
Post by Bjoern A. Zeeb
Post by Mark Johnston
resolvconf -a will only update /etc/resolv.conf if the info in
/var/run/resolvconf/interfaces/vtnet0 has changed, I believe. Try
deleting that file too, and then try running rtsol.
When I deleted /etc/resolv.conf and then rtsol manually it had
re-appeared. Unclear to me what was in /var/run; I just wanted to point
out the difference in behaviour; maybe you are right; I’ll go and
check if deleting in /var/run/ as well makes a difference.
I don't observe that behaviour with either the stock or patched
rtsol(8): for resolvconf(8) to update /etc/resolv.conf (or re-generate
it), something under /var/run/resolvconf/interfaces needs to have
changed. So, in my case, deleting /etc/resolv.conf *and*
/var/run/resolvconf/interfaces/re0:slaac will cause resolv.conf to be
regenerated once rtsold(8) decides to re-run resolvconf(8), but
deleting resolv.conf on its own will not.
I wonder if that’s a bug (unrelated to yours). I also noticed that
when my nameservers changed /etc/resolv.conf did not always reflect
this.
Loading...