Page MenuHomeFreeBSD

wall(1): cappsicumizing wall
Needs ReviewPublic

Authored by hanslu952_gmail.com on Jun 12 2024, 7:53 AM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Dec 31, 10:09 PM
Unknown Object (File)
Mon, Dec 30, 11:19 PM
Unknown Object (File)
Sun, Dec 29, 10:54 PM
Unknown Object (File)
Sat, Dec 28, 10:48 PM
Unknown Object (File)
Fri, Dec 27, 11:42 AM
Unknown Object (File)
Thu, Dec 26, 4:03 PM
Unknown Object (File)
Fri, Dec 13, 11:30 AM
Unknown Object (File)
Nov 25 2024, 5:09 AM
Subscribers

Details

Reviewers
oshogbo
lwhsu
Summary

The first problem is to use pdfork.
because fork() is disallowed in capability mode,
we use pdfork() to replace ,the semantic is same as rwhod
The second problem is to limit the file descriptor used by open.
it sets up a specific right (write) for a file descriptor and then
attempts to enforce the limitation. If the operation fails,
the program will terminate with a specific error message

Sponsored by: Google, Inc. (GSoC 2024)

Test Plan

Nonblocking test

setup a c program to fill up the pipe of /dev/pts/$any num
the program code is as follows
https://hackmd.io/@black13524/ryClhYgnA

$ cc -o nonblocking nonblocking.c
$ ./nonblocking
$ make 
$ ktrace ./wall-test msg
$ kdump -f ktrace.out

normal test

$ make 
$ ktrace ./wall-test msg
$ kdump -f ktrace.out

Set up enotcapable to get coredump

$ sysctl kern.trap_enotcap=1
$ sysctl kern.corefile= /tmp/coredumps/%N.core
$ gdb executable corefile

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 58476
Build 55364: arc lint + arc unit

Event Timeline

There are a very large number of changes, so older changes are hidden. Show Older Changes
oshogbo requested changes to this revision.Jun 13 2024, 4:30 PM

In the "Test plan" please provide an example of testing blocking (forked version) and unblocked version.

usr.bin/wall/ttymsg.c
58

Why this has to be global?

67–70

I guess we don't need foked and fdp.

128

Does this code complies? I think you have a typo in variable name.

usr.bin/wall/wall.c
128

No need for extra line.

192

I think we have to enter capability mode a little bit earlier then before exit.
The cap_enter/caph_enter function is a barrier which says here starts a "untrusted part", know you are protecting nothing.

This revision now requires changes to proceed.Jun 13 2024, 4:30 PM
  • Fix pdfork and take off unneccessary code
  • remove line break

Hym I don't think this is complete patch.
Can you try to regenerate git diff -U99999 first_commit^ (the ^ is important)

There are many whitespace changes, if possible, please don't change the original ones (even they are wrong) in a feature addition change, or it would cause unnecessary review complexity.

usr.bin/wall/ttymsg.c
125

Why we are entering capability mode here?

128

How can this work?
You are reassigning fd (which was the open file) to a process descriptor.

path sandboxing and enter capability mode earlier

  • Reupload due to including wrong commit
usr.bin/wall/ttymsg.c
59
68

We can combine 3 int variables to a single line.

72

Why we need ./ ?

92

So WRONLY or RDONLY or maybe O_RDWR?

96
127–128

How removed forked change the process menagment?
How many child process will have this process before and after this change.

usr.bin/wall/wall.c
74
83

Why?

93–94
164
226
usr.bin/wall/ttymsg.c
127–128

each parent still creates one child,but the number of parent process grows exponentially when pdfork is called more than once.
like:
once is the same
when pdfork is called twice
we will have five parent ,each parent create one child

usr.bin/wall/ttymsg.c
127–128

I don't think this what we want, no?

usr.bin/wall/ttymsg.c
72

to get the needed file without using absolute path

usr.bin/wall/ttymsg.c
72

But file and ./file are both relative.

hanslu952_gmail.com retitled this revision from Capsicumizing wall to wall(1): cappsicumizing wall.Jul 17 2024, 3:53 PM
hanslu952_gmail.com edited the test plan for this revision. (Show Details)
usr.bin/wall/ttymsg.c
67–70

Why fd2? Where is fd1?

128

Why close dfd?

131–132

Why dfd?
Where do we clean fd2?

142

Why dfd?

150–151

Why dfd?

usr.bin/wall/wall.c
78

Why fd2? Where is fd1?

96

Why we need these transformations?

191

Wasn't devfd was closed in ttymsg?

hanslu952_gmail.com edited the test plan for this revision. (Show Details)
  • fix fd problem
usr.bin/wall/ttymsg.c
86

With got we cannot get these errors?

86

sorry...

With "openat" we cannot get these errors?

93

Why have we changed the way we return errors?

130

Why have you changed identation?

131

Where are we closing the process descriptor?

133

Why we removed this?

159

Why we remove this part?

usr.bin/wall/wall.c
124

I guess /dev/pts?

usr.bin/wall/ttymsg.c
131

I think _exit() will close the process?

usr.bin/wall/ttymsg.c
131

Which one?
Which one has a process descriptor?

usr.bin/wall/ttymsg.c
131

It seems not in tty,in main after closing devfd?

usr.bin/wall/ttymsg.c
131

Oh sorry,I used gdb wrong ,It wont exit.I found that it should exit at 160 - 161,so I will add back it

  • add back forked and fix returned errors