Page MenuHomeFreeBSD

System V standardized IPC syscalls concerned with manipulating semaphore sets
ClosedPublic

Authored by aniketp on Jun 19 2018, 3:57 AM.

Details

Summary

This revision introduces test cases for System V standardized system calls concerned
with creating and manipulating semaphore sets. These system calls are categorized
within inter-process-communication audit class (as expected).

System calls in question are:

  • semget(2)
  • semop(2)
  • semctl(2)

Note:
semctl(2) takes as argument a cmd which is a separate audit event in itself.
List of semctl(2) audit events:

  • AUE_SEMCTL [Illegal Command]
  • AUE_SEMCTL_GETALL
  • AUE_SEMCTL_GETNCNT
  • AUE_SEMCTL_GETZCNT
  • AUE_SEMCTL_GETPID
  • AUE_SEMCTL_GETVAL
  • AUE_SEMCTL_SETALL
  • AUE_SEMCTL_SETVAL
  • AUE_SEMCTL_STAT
  • AUE_SEMCTL_RMID
  • AUE_SEMCTL_SET

For full details, please see: sys/security/audit/audit_bsm_klib.c#L271

Each of them have been treated as separate audit events. (And hence, separate tests)

Test Plan

Execute make && make install from test/sys/audit.
Execute kyua test from /usr/tests/sys/audit. All testcases should succeed.

Diff Detail

Repository
rS FreeBSD src repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

aniketp created this revision.Jun 19 2018, 3:57 AM
asomers requested changes to this revision.Jun 19 2018, 4:14 PM
asomers added inline comments.
tests/sys/audit/inter-process.c
49 ↗(On Diff #44058)

This is defined in sem.h. Don't redefine it here. Just #define _WANT_SEMUN before including sem.h.

53 ↗(On Diff #44058)

IMHO, "arg" is too vague a name for a global variable.

780 ↗(On Diff #44058)

There's actually nothing in the spec that says this should fail. However, the man page does say that semget should fail in either of the two following situations:

  • key is IPC_PRIVATE and nsems is <= 0
  • key is IPC_PRIVATE, and flags does not include IPC_CREAT.
810 ↗(On Diff #44058)

sizeof(sop) would be safer.

858 ↗(On Diff #44058)

arg->array is used uninitialized here. But GETVAL doesn't need the fourth argument, anyway.

961 ↗(On Diff #44058)

GETPID does not require the fourth argument.

1012 ↗(On Diff #44058)

GETNCNT doesn't require arg, either.

1167 ↗(On Diff #44058)

semvals is used uninitialized.

1270 ↗(On Diff #44058)

It makes no sense to initialize two fields of a union, because initializing the second one will wipe out the first.

This revision now requires changes to proceed.Jun 19 2018, 4:14 PM
aniketp updated this revision to Diff 44145.Jun 20 2018, 11:51 AM
aniketp marked 7 inline comments as done.

Replace arg with semarg; And some minor changes

aniketp added inline comments.Jun 20 2018, 11:55 AM
tests/sys/audit/inter-process.c
1167 ↗(On Diff #44058)

semvals would be filled up by the SETALL command. Man-page doesn't say we need to explicitely initialize it.

asomers requested changes to this revision.Jun 20 2018, 2:59 PM
asomers added inline comments.
tests/sys/audit/inter-process.c
858 ↗(On Diff #44058)

Why don't you just remove the fourth argument and invoke it as semctl(semid, 0, GETVAL)?

1167 ↗(On Diff #44058)

I don't see that at all. Are you thinking about GETALL?

This revision now requires changes to proceed.Jun 20 2018, 2:59 PM
aniketp updated this revision to Diff 44151.Jun 20 2018, 3:51 PM
  • Remove semarg from GETVAL, GETPID, GETZCNT, GETNCNT
  • Initialize semvals in SETALL by first calling GETALL
aniketp added inline comments.Jun 20 2018, 3:51 PM
tests/sys/audit/inter-process.c
858 ↗(On Diff #44058)

Oops! I had removed them from all GET* commands. Must have crept back it when I git stashed the changes.
Will remove them again.

Don't forget the _WANT_SEMUN change.

tests/sys/audit/inter-process.c
1391 ↗(On Diff #44151)

Technically you're still using semarg uninitialized here. I recommend simply removing it.

aniketp updated this revision to Diff 44273.Jun 21 2018, 11:59 PM

Define _WANT_SEMUN instead of declaring union semun in the test program

asomers accepted this revision.Jun 22 2018, 12:54 AM
This revision is now accepted and ready to land.Jun 22 2018, 12:54 AM
This revision was automatically updated to reflect the committed changes.