COMP3301 Semester 1 2024 Assignment 1
COMP3301 Assignment 11
OpenBSD Zones “Episode 3: Return of the Sys(call)”2
Due: 3pm Monday in Week 5(19th of August)3
Submission: BlackBoard (reflection) and Git.4
Demo and git are marked in your lab session in week 55
Last Updated: July 30, 20246
1 Academic Integrity7
All assessments are individual. You should feel free to discuss aspects of C programming and8
assessment specifications with fellow students and discuss the related APIs in general terms.9
You should not actively help (or seek help from) other students with the actual10
coding of your assessment. It is cheating to look at another student’s code, and it is11
cheating to allow your code to be seen or shared in printed or electronic form. You should note12
that all submitted code will be subject to automated checks for plagiarism and collusion. If we13
detect plagiarism or collusion (outside of the base code given to everyone), formal misconduct14
proceedings will be initiated against you.15
If you’re having trouble, seek help from a teaching staff member. Do not be tempted to copy16
another studen 代 写COMP3301 pisode 3: Return of t’s code. You should read and understand the statements on student misconduct17
in the course profile and on the school website: eecs.uq.edu.au/current-stu…
guidelines-and-policies-students/student-conduct.19
1.1 Use of AI Tools20
All assessment tasks evaluate students’ abilities, skills and knowledge without the aid of gen-21
erative Artificial Intelligence (AI) or Machine Translation (MT). Students are advised that the22
use of AI technologies to develop responses (e.g. code generation) is strictly prohibited and23
may constitute student misconduct under the Student Code of Conduct.24
2 Introduction25
This assignment will extend a basic implementation of “zones” in the OpenBSD kernel. The26
main area of improvement will be separating group and user permissions on zone operations.27
You will be provided with a diff that adds the basic zones functionality to OpenBSD. You will28
need to make changes and improvements on top of this diff.29
The purpose of this assignment is for you to demonstrate an understanding of the role of an30
operating system kernel and how it supports processes making system calls, as well as your31
skills in reading, understanding, and modifying existing code.32
Page 1 of 11
COMP3301 Semester 1 2024 Assignment 1
2.1 Background33
Zones extend the isolation of processes beyond what is traditionally provided by UNIX and34
UNIX-like systems, including OpenBSD. Traditionally, all processes running on an OpenBSD35
are visible to all other processes. This can be demonstrated by running commands like top(1),36
ps(1), and pgrep(1)/pkill(1), which can show all processes running in a system:37
ps−axPIDTTSTATTIMECOMMAND1??I0:01.01/sbin/init35862??Ip0:00.01/sbin/slaacd9544??Ip0:00.01slaacd:engine(slaacd)33073??IpU0:00.01slaacd:frontend(slaacd)96644??IU0:00.01/sbin/dhcpleased82639??Ip0:00.01dhcpleased:engine(dhcpleased)68436??IpU0:00.01dhcpleased:frontend(dhcpleased)6881??IpU0:00.01/sbin/resolvd69588??IpU0:00.03syslogd:[priv](syslogd)54598??Spc0:00.03/usr/sbin/syslogd14516??IU0:00.01pflogd:[priv](pflogd)15079??Spc0:00.12pflogd:[running]−s160−ipflog0−f/var/log/pflog94692??S37809??Sp0:00.26ntpd:dnsengine(ntpd)1816??I63841??I0:00.01sshd:/usr/sbin/sshd[listener]0of10−100startups83125??Ip0:00.02/usr/sbin/smtpd58972??Ipc0:00.02smtpd:crypto(smtpd)99695??Ipc0:00.02smtpd:control(smtpd)5777??Ip0:00.02smtpd:lookup(smtpd)45996??Ipc0:00.04smtpd:dispatcher(smtpd)37682??Ipc0:00.02smtpd:queue(smtpd)97246??Ipc0:00.02smtpd:scheduler(smtpd)48848??IpU0:00.00sndiod:helper(sndiod)47188??I96369??Ip0:00.02/usr/sbin/cron45067??I0:00.07sshd:dlg[priv](sshd)32638??S0:00.03sshd:dlg@ttyp0(sshd)1730p0Sp0:00.02−ksh(ksh)16990p0R+pU/20:00.00ps−ax3342800I+pU0:00.01/usr/libexec/gettystd.9600tty00
‘‘‘
While all processes are visible to each other, they are restricted from interacting with each38
other based on the user that each process is running as. A non-root user can only signal their39
own processes. Attempts to signal processes running as another user fails:40
whoamidlg ps -U _sndio
PID TT STAT TIME COMMAND
47188 ?? Ikill47188ksh:kill:47188:Operationnotpermitted
Page 2 of 11
COMP3301 Semester 1 2024 Assignment 1
However, the root user is allowed to signal any process:41
doaskill47188doas(dlg@comp3301.eait.uq.edu.au)password: ps -U sndio
PID TT STAT TIME COMMAND
3ZonesImplementation42Zonesareimplementedforthisassignmenttoaddfurtherisolationofprocesses.Processes43runningwithinazonecanonlyseeandinteractwithprocessesrunningwithinthesamezone,44regardlessofwhichuserwithinthezoneisrunningthecommands.Thisimplementationis45looselymodelledonthedesignofSolarisZonesasdescribedinPSARC/2002/174.46Theexceptiontothisenhancedisolationisforprocessesrunninginthe”global”zone,whichis47thedefaultzonethatiscreatedandexistsonboot.Processesrunningintheglobalzonecan48seeallotherprocessesinthesystem,includingthoserunninginother(non−global)zones,and49therootuserintheglobalzonecansignalanyoftheseprocessestoo.However,non−rootusers50intheglobalzonecannotsignalprocessesinotherzones,eveniftheyarerunningasthesame51user.52Theprovideddiffimplementschangestothekernelandseveraluserlandutilitiesandaddsa53zone(8)commandandmanpage.Thezone(8)commandprovidesseveralsub−commandsthat54exposethefunctionalityofthekernelzonesubsystem.553.1ProvidedZoneSyscalls56zonecreate()57zoneidtzonecreate(constchar∗zonename);zonecreate()createsanewzoneidforuseinthesystem,withauniquenamespecifiedby58zonename.59zonedestroy()60intzonedestroy(zoneidtz);zonedestroy()deletesthespecifiedzoneinstance.Thezonemusthavenorunningprocesses61insideitfortherequesttosucceed.62zoneenter()63intzoneenter(zoneidtz);zoneenter()movesthecurrentprocessintothespecifiedzone.64Page3of11COMP3301Semester12024Assignment1zonelist()65intzonelist(zoneidt∗zs,sizet∗nzs);Intheglobalzonezonelist()providesthelistofzonesintherunningsystemasanarrayof66zoneidts.Ifruninanon−globalzone,thelistwillonlycontainthecurrentzone.67zonename()68intzonename(zoneidtz,char∗name,sizetnamelen);Thezonename()syscallprovidesthenameofthezoneidentifiedbythezargument.Ifrun69inanon−globalzonethezidmustbetheidentifierforthecurrentzone.Intheglobalzoneit70canbeanyzoneidentifier.71zoneid()721zoneidtzoneid(constchar∗name);zoneid()providestheidassociatedwiththenamezone.Ifruninanon−globalzone,onlythe73currentzonenamemaybespecified.IfnameisaNULLpointerthezoneidcallingprocessis74runninginisreturned.75zonestats()761intzonestats(zoneidtz,structzstats∗zstats);zonestats()providesanassortmentofoperatingsystemstatisticsresultingfromprocesses77inthezoneassociatedwiththeidz.783.2zone(8)791usage:zonecreatezonename2zonedestroyzonename3zoneexeczonenamecommand...4zonelist5zoneid[zonename]6zonename[zid]7zonestats[−H][−oproperty[,...]zone[...]Thezone(8)programusesthezonesyscallstoallowsystemsadministratorsoroperatorsto80usethezonesubsysteminthekernel.81zonecreate82zonecreateusesthezonecreate()syscalltocreateazonewiththespecifiedname.83zonedestroy84zonedestroyusesthezonedestroy()syscalltocreateazonewiththespecifiedname.Ifa85zonewiththespecifiednamedoesnotexist,zone(8)willattempttointerprettheargument86asanumericzoneidentifier.87Page4of11COMP3301Semester12024Assignment1zoneexec88zoneexecusesthezoneenter()syscalltomoveitselfintothespecifiedzone,andthen89executestheprogram.Ifazonewiththespecifiednamedoesnotexist,zone(8)willattempt90tointerprettheargumentasanumericzoneidentifier.91zonelist92zonelistusesthezonelist()syscalltofetchalistofidsforthecurrentlyrunningzones,93anditeratesoveritcallingthezonename()syscalltoprintoutthelistofzoneidsandnames.94zonename/zoneid95zonenameandzoneidusetheirassociatedsyscallszonename()andzoneid()toreturn96thenameofazonegivenitsid,ortheidofazonegivenitsname.97zonestats98zonestatsusesthezonestat()syscalltoobtainandprintouttotheuseraseriesofstatis−99ticsfromprocessesrunninginthecurrentzone.Seethemanualpageinzone(8)formore100information.1013.3YourTasks102Youwillbeaddingadditionalfunctionalitytoaseriesofzone(8)sub−commands,addingthree103newzone(8)sub−commands,andimplementinganynecessarychangestothekernelzones104systemtosupportthem.105Youradditionalfunctionalitycentersaroundzonepermissions.Fileshaveanassociated“user”106and“group”,andthisuserorgroupmayhavepermissiontooperateonthefile.Yourtaskisto107associatezoneswithaparticularownerandgroup,andallowtheownerofthezoneandusers108whoareinthatgrouptoperformoperationsonthezone(regardlessofwhethertheyarethe109ownerofthezone).110Inshort,wherezonesarenowonlycontrollablebyroot,yourchangeswillallowtheownerof111azoneandadifferentgroupofuserstocontrolazone.112Theadditionalsub−commandsyouwillbeimplementingare:zonerename,whichwillchange113thenameofazone;zonechown,whichwillchangetheownerofazoneinamannersimilar114totheexistingchown(8);andzonechgrp,whichwillchangethegroupofazoneinamanner115similartotheexistchgrp(8).1164Instructions117Tocompletetheassignment,youwillneedtodothefollowing.1184.1Applythediff1191−Fetchhttps://stluc.manta.uqcloud.net/comp3301/public/2024/a1−zones−base.patch2−Createana1branch3−‘gitcheckout−ba1‘Page5of11COMP3301Semester12024Assignment14−Applythebasepatchtothea1branch5−‘gitam/path/to/a1−zones−base.patch‘in/usr/src6−Buildthekernel7−‘cd/usr/src/sys/arch/amd64/compile/GENERIC.MP‘8−‘makeobj‘9−‘makeconfig‘10−‘make−j5‘11−‘doasmakeinstall‘12−Rebootintothekernel13−‘doasreboot‘14−‘makeobj‘in/usr/src15−‘doasmakeincludes‘in/usr/src/include16−Verifythezonessyscallsarein/usr/include/sys/syscall.h17−Verify/usr/include/sys/zones.hexists18−Makeandinstalllibc19−‘cd/usr/src/lib/libc‘20−‘make−j5‘21−‘doasmakeinstall‘22−Optional:makeps,andpkill/pgrep23−makezone(8)24−‘cd/usr/src/usr.sbin/zone‘25−‘make‘26−‘doasmakeinstall‘27−Verify‘zone(8)‘andthezonessubsystemworks:28 zone list
29ID NAME
300 global
31zonecreate32usage:zonecreatezonename33 zone create test
34zone: create: Operation not permitted
35doaszonecreatetest36doas(dlg@comp3301.eait.uq.edu.au)password:37 zone list
38ID NAME
390 global
4042101 test
41zoneid42043 zone id test
4442101
45zoneexectestps−aux46zone:enter:Operationnotpermitted47 doas zone exec test ps -aux
48USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
49root 41705 0.0 0.1 628 580 p0 R+pU/0 3:37PM 0:00.14 ps -aux
50doaszoneexectestzoneid514210152 doas zone exec test zone id global
53zone: id: No such process
54Asyouaddthefunctionalityspecifiedinthenextsections,someofthesestepswillberepeated.120eg,changingthekernelmeansrebuildingandinstallingthekernel.Addingasyscallmeans121makingthesyscallstubasafunctionvisibleintheheaders(makeincludes),andcallable122throughlibc.123Page6of11COMP3301Semester12024Assignment1Anoteonerrors124Wehaveover−specifiedtheerrorsyoushouldreturnfromyoursyscalls−ifyoudonotrequirean125errorcode(forexample,neverreturningENOMEMonmemoryfailuresbecauseyouneverallocate126anymemory)thenyoudonothavetouseit.Thereverseisalsotrue−ifyoufindanerrorcase127thatisnotlisted,chooseanappropriateerrorfromerrno(2).Wewillnotexplicitlytestall128errors,butduringyourcodeinterview,wewillexpectyoutobeabletoexplainthesuitability129oftheerrorcodesyouuse.1304.2ZoneRename131Thezone(8)commandsshouldbeextendedtoenablerenamingofzones.Zonesshouldonly132beabletoberenamedbytheowner,root,ormembersofthezone’sgroup.Additionally,the133globalzonecannotberenamed,andzonenamesmustbeunique.1341 zone
2usage: zone create zonename
3zone destroy zonename
4zone exec zonename command ...
5zone list
6zone name [id]
7zone id [zonename]
8zone rename id name
9doaszonecreatefoo10 zone list
11ID NAME
120 global
13289 foo
14doaszonerename298bar15 zone list
16ID NAME
170 global
18289 bar
19doaszonerename0something20zone:name:Permissiondenied21 doas zone rename 289 global
22zone: name: File exists
4.3 Modifications to Existing Syscalls135
zone_create() syscall136
The zone_create() syscall should now ensure that the created zone is associated with the137
group of the user that created it, as well as the user themself. Additionally, this will mean138
ensuring that non-root users can create zones.139
All other syscalls140
The full suite of zone* syscalls should permit users with matching credentials to perform zone141
operations on them, not only the owner and the root user.142
Page 7 of 11
COMP3301 Semester 1 2024 Assignment 1
4.4 Zone name and zone list143
zone_name() syscall144
The zone_name() syscall should be renamed to zone_info(). Subsequently, it should return145
not only the name and namelen, but a struct, containing the id of the user and the id of the146
group that has permission to control the zone. The zone(8) userland sub-command for zone147
name should also be modified in line with these changes - the name should be changed to zone148
info and the additional information should be provided to the user.149
zone list150
The zone list subcommand should now take flags: -o and -g. If either of these flags are151
provided, the owner and the group that have control over the zones should also be printed, in152
table format.153
4.5 Zone chown and chgrp154
The zone(8) commands and the kernel zones system should be extended to enable changing155
the owner and group of a zone. Zone owners and groups should only be able to be changed by156
the owner, root, or members of the zone’s group. Additionally, the owner of the global zone157
cannot be changed.158
1 zone
2usage: zone create zonename
3zone destroy zonename
4zone exec zonename command ...
5zone list
6zone name [id]
7zone id [zonename]
8zone chown [id]
9zone chgrp [id]
To support these subcommands, you will need to implement the following system calls:159
zone_chown() syscall160
int zone_chown(zoneid_t z, uid_t user);
The zone_chown() syscall alters the owner of the zone identified by the z argument. The new161
owner should be the owner identified by the user argument. If called from a non-global zone162
then the z id must be the identifier for the current zone, but in the global zone it can be any163
zone identifier.164
Potential Errors:165
? EPERM - the user does not have permission to alter the zone z166
? ESRCH - the zone identified by z does not exist167
? ENOMEM - the system was not able to allocate memory168
? EINVAL - the zone to alter was the global zone169
Page 8 of 11
COMP3301 Semester 1 2024 Assignment 1
zone_chgrp() syscall170
int zone_chgrp(zoneid_t z, gid_t group);
The zone_chgrp() syscall alters the owner of the zone identified by the z argument. The new171
owner should be the group identified by the group argument. If called from a non-global zone172
then the z id must be the identifier for the current zone, but in the global zone it can be any173
zone identifier.174
Potential Errors:175
? EPERM - the user does not have permission to alter the zone z176
? ESRCH - the zone identified by z does not exist177
? ENOMEM - the system was not able to allocate memory178
? EINVAL - the zone to alter was the global zone179
5 Other Requirements & Suggestions180
5.1 Code Style181
Your code is to be written according to OpenBSD’s style guide, as per the ‘style(9)‘ man page.182
An automatic tool for checking for style violations is available at uqcloud.net/comp3301/public/2022/cstyle.pl>. This tool will be used to calculate your184
style marks for this assignment.185
5.2 Compilation186
Your code for this assignment is to be built on an amd64 OpenBSD 7.5 system identical to your187
course-provided VM.188
189
The following steps must succeed:190
? make obj; make config; make in src/sys/arch/amd64/compile/GENERIC.MP191
? make obj; make includes in src192
? make obj; make; make install in src/lib/libc193
? make obj; make; make install in src/usr.sbin/zone194
The existing Makefiles in the provided code are functional as-is, but may need modification195
as part of your work for this assignment. Note that the existing Makefile ensures the -Wall196
flag is passed to the compiler, as well as a few other warning and error-related flags.197
Page 9 of 11
COMP3301 Semester 1 2024 Assignment 1
5.3 Provided code198
The provided code which forms the basis for this assignment can be downloaded as a single199
patch file at:200
https://stluc.manta.uqcloud.net/comp3301/public/2024/a1-zones-base.patch201
202
You should create a new a1 branch in your repository based on the openbsd-7.5 tag using git203
checkout, and then apply this base patch using the git am command:204
1 git checkout -b a1 openbsd -7.5
2ftphttps://stluc.manta.uqcloud.net/comp3301/public/2024/a1−zones−base.patch3 git am < a1 -zones -base.patch
4$ git push origin a1
5.4 Recommendations205
The following order will likely be the most reasonable way to complete this assignment:206
- Download, build, and install the zones patch.207
- Add the zone rename subcommand to zone(8).208
- Minimally modify zone_create() to store credentials.209
- Rewrite zone_name() to zone_info().210
This ensures you have a way to view the credentials of a zone.211
- Add the zone_chown() and zone_chgrp() syscalls.212
- Add the corresponding zone chown and zone chgrp commands to zone(8).213
- Fix up any tiny bugs and ensure it’s all working. But you did that as you were going... right?214
Additionally, it is strongly recommended (and in some cases, required) that the following APIs215
be considered for use as part of your changes:216
? ucred(9) - provides necessary handlers for dealing with user and group credentials217
? copyin(9)/copyout(9) - provides the ability to copy data across the userspace boundary218
? user_from_uid(3) - conversions from group/user name to id and back219
? strtonum(3) - BSD style safe string to int conversions220
? Finally, you may wish to look at the header file sys/proc.h to see how user and group221
credentials are currently stored by threads.222
Page 10 of 11
COMP3301 Semester 1 2024 Assignment 1
6 Reflection223
Provide a reflection on your implementation by briefly answering the following questions:224
- Describe the steps you took or draw a flowchart.225
- Describe an error that you encountered.226
- Describe how the error was debugged.227
- Describe how the bug was solved.228
Upload both pdf and your answers it as a pdf to the Blackboard a1 reflection submission. Page229
length is a maximum 2 pages or less. Pdf name must be your STUDENT NUMBER -230
a1.pdf. Note this is your XXXXXXXX ID number and not sXXXXXXX login.231
7 Submission232
Submission must be made electronically by committing to your Git repository on ‘source.eait.uq.edu.au‘.233
In order to mark your assignment the markers will check out the ‘a1‘ branch from your reposi-234
tory. Code checked into any other branch in your repository will not be marked.235
236
As per the ‘source.eait.uq.edu.au‘ usage guidelines, you should only commit source code and237
Makefiles.238
239
Your ‘a1‘ branch should consist of:240
? The openbsd-7.5 base commit241
? The A1 base patch commit242
? Commit(s) for adding the required functionality243
7.1 Marking244
Your submission will be marked by course tutors and staff, during an in-person demo with you,245
at your lab session during the due week. You must attend your session, in-person, otherwise246
your submission will not be marked. Online attendence, e.g. zoom, is not permitted.247
WX:codinghelp