Page MenuHomeFreeBSD

System V standardized IPC syscalls concerned with manipulating semaphore sets
ClosedPublic

Authored by aniketp on Jun 19 2018, 3:57 AM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Mar 11, 3:07 PM
Unknown Object (File)
Mon, Mar 11, 3:07 PM
Unknown Object (File)
Mon, Mar 11, 3:07 PM
Unknown Object (File)
Feb 7 2024, 7:21 PM
Unknown Object (File)
Dec 27 2023, 9:52 PM
Unknown Object (File)
Dec 20 2023, 6:07 AM
Unknown Object (File)
Dec 17 2023, 12:59 PM
Unknown Object (File)
Dec 10 2023, 8:55 PM
Subscribers

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 - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

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 marked 7 inline comments as done.

Replace arg with semarg; And some minor changes

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
  • Remove semarg from GETVAL, GETPID, GETZCNT, GETNCNT
  • Initialize semvals in SETALL by first calling GETALL
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.

Define _WANT_SEMUN instead of declaring union semun in the test program

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.