Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
072d5bc
Count pool and parallel tasks once in both runtime backends
Nov 24, 2026
f708525
Refuse what student code left running does once its test has ended
Nov 24, 2026
505b072
Refuse a withinPath and supervised package that name different classes
Nov 24, 2026
3f10e5b
Count a new java.util.Timer as one thread in both runtime modes
Nov 24, 2026
6e67c17
Do not count the threads HttpClient starts for itself with instrument…
Nov 24, 2026
9af15c0
Let the thread that ended a test pass before any other check
Nov 24, 2026
cc779a3
Supervise student code JUnit runs between the tests of a container
Nov 24, 2026
2c8f7ad
Count each HttpClient as one thread and check its requests where they…
Nov 24, 2026
8421cfc
Never lift the checks when arming a container again
Nov 24, 2026
40ec25f
Allow the image clean-up thread the JDK starts for itself
Nov 26, 2026
1e4bff1
Iterate no student collection in the AspectJ thread check, and give p…
Nov 26, 2026
0ed0bef
Let the JDK delete the socket file of its selector pipe on Windows
Nov 26, 2026
953e1a2
Test which call stacks count as the JDK starting its image clean-up t…
Nov 26, 2026
041baba
Search any collection for tasks only in invokeAll and invokeAny
Nov 26, 2026
5dd305b
Let the JDK connect the socket of its selector pipe on Windows
Nov 26, 2026
b48876e
Search only plain JDK collections for the tasks of a thread operation
Nov 26, 2026
fdef986
Count a task that is also a list as a task
Nov 26, 2026
a1d2eda
Read no sorted set for tasks, and count every task of a batch
Nov 26, 2026
3ac646c
Read the tasks of invokeAll as a collection only at the outer level
Nov 26, 2026
90a0f7b
Let a pool task inside invokeAll pass only if the batch check validat…
Nov 26, 2026
216022a
Judge every task the JDK hands on inside a counted pool call against …
Nov 26, 2026
fb5c015
Record the tasks of invokeAll from the same copy the check validated
Nov 26, 2026
1aba9a7
Hand the pool exactly the checked tasks under AspectJ, and check what…
Nov 26, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .settings/cpd-allowed-duplications.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
# group or any change to a group's participating files fails the build.
de.tum.cit.ase.ares.api.aop.AOPMode.java,de.tum.cit.ase.ares.api.architecture.ArchitectureMode.java
de.tum.cit.ase.ares.api.aop.java.instrumentation.advice.JavaInstrumentationConnectNetworkMethodAdvice.java,de.tum.cit.ase.ares.api.aop.java.instrumentation.advice.JavaInstrumentationReceiveNetworkMethodAdvice.java,de.tum.cit.ase.ares.api.aop.java.instrumentation.advice.JavaInstrumentationSendNetworkMethodAdvice.java
de.tum.cit.ase.ares.api.aop.java.instrumentation.advice.JavaInstrumentationConnectNetworkMethodAdvice.java,de.tum.cit.ase.ares.api.aop.java.instrumentation.advice.JavaInstrumentationCreatePathMethodAdvice.java,de.tum.cit.ase.ares.api.aop.java.instrumentation.advice.JavaInstrumentationCreateThreadMethodAdvice.java,de.tum.cit.ase.ares.api.aop.java.instrumentation.advice.JavaInstrumentationDeletePathMethodAdvice.java,de.tum.cit.ase.ares.api.aop.java.instrumentation.advice.JavaInstrumentationExecuteCommandMethodAdvice.java,de.tum.cit.ase.ares.api.aop.java.instrumentation.advice.JavaInstrumentationOverwritePathMethodAdvice.java,de.tum.cit.ase.ares.api.aop.java.instrumentation.advice.JavaInstrumentationReadPathMethodAdvice.java,de.tum.cit.ase.ares.api.aop.java.instrumentation.advice.JavaInstrumentationReceiveNetworkMethodAdvice.java,de.tum.cit.ase.ares.api.aop.java.instrumentation.advice.JavaInstrumentationSendNetworkMethodAdvice.java
de.tum.cit.ase.ares.api.aop.java.instrumentation.advice.JavaInstrumentationConnectNetworkMethodAdvice.java,de.tum.cit.ase.ares.api.aop.java.instrumentation.advice.JavaInstrumentationCreatePathMethodAdvice.java,de.tum.cit.ase.ares.api.aop.java.instrumentation.advice.JavaInstrumentationDeletePathMethodAdvice.java,de.tum.cit.ase.ares.api.aop.java.instrumentation.advice.JavaInstrumentationExecuteCommandMethodAdvice.java,de.tum.cit.ase.ares.api.aop.java.instrumentation.advice.JavaInstrumentationOverwritePathMethodAdvice.java,de.tum.cit.ase.ares.api.aop.java.instrumentation.advice.JavaInstrumentationReadPathMethodAdvice.java,de.tum.cit.ase.ares.api.aop.java.instrumentation.advice.JavaInstrumentationReceiveNetworkMethodAdvice.java,de.tum.cit.ase.ares.api.aop.java.instrumentation.advice.JavaInstrumentationSendNetworkMethodAdvice.java
de.tum.cit.ase.ares.api.aop.java.instrumentation.advice.JavaInstrumentationConnectNetworkMethodAdvice.java,de.tum.cit.ase.ares.api.aop.java.instrumentation.advice.JavaInstrumentationCreateThreadMethodAdvice.java,de.tum.cit.ase.ares.api.aop.java.instrumentation.advice.JavaInstrumentationDeletePathMethodAdvice.java,de.tum.cit.ase.ares.api.aop.java.instrumentation.advice.JavaInstrumentationExecuteCommandMethodAdvice.java,de.tum.cit.ase.ares.api.aop.java.instrumentation.advice.JavaInstrumentationOverwritePathMethodAdvice.java,de.tum.cit.ase.ares.api.aop.java.instrumentation.advice.JavaInstrumentationReadPathMethodAdvice.java,de.tum.cit.ase.ares.api.aop.java.instrumentation.advice.JavaInstrumentationReceiveNetworkMethodAdvice.java,de.tum.cit.ase.ares.api.aop.java.instrumentation.advice.JavaInstrumentationSendNetworkMethodAdvice.java
de.tum.cit.ase.ares.api.aop.java.instrumentation.advice.JavaInstrumentationCreatePathMethodAdvice.java,de.tum.cit.ase.ares.api.aop.java.instrumentation.advice.JavaInstrumentationCreateThreadMethodAdvice.java
de.tum.cit.ase.ares.api.aop.java.instrumentation.advice.JavaInstrumentationCreatePathMethodAdvice.java,de.tum.cit.ase.ares.api.aop.java.instrumentation.advice.JavaInstrumentationExecutePathMethodAdvice.java
de.tum.cit.ase.ares.api.aop.java.instrumentation.advice.JavaInstrumentationDeletePathMethodAdvice.java,de.tum.cit.ase.ares.api.aop.java.instrumentation.advice.JavaInstrumentationExecutePathMethodAdvice.java
de.tum.cit.ase.ares.api.aop.java.instrumentation.advice.JavaInstrumentationExecutePathMethodAdvice.java,de.tum.cit.ase.ares.api.aop.java.instrumentation.advice.JavaInstrumentationOverwritePathMethodAdvice.java,de.tum.cit.ase.ares.api.aop.java.instrumentation.advice.JavaInstrumentationReadPathMethodAdvice.java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ The security validator performs a **series of checks** to decide whether the thr
1. **Re-entrancy Guard**: `enterAdvice()`/`exitAdvice()`: nested advice invocations on the same thread (triggered by the advice's own class loading and stack walking) return immediately, so only the outermost interception is enforced
2. **Is Security Enabled?** → If no: 🟢 (in instrumentation mode, a missing/empty `restrictedPackage` allows immediately)
3. **Configuration Consistency**: If `threadClassAllowedToBeCreated` and `threadNumberAllowedToBeCreated` have different lengths → 🔴 SecurityException (this runs **before** the callstack check)
4. **Internal Bypasses**: Thread creations owned by `ProcessBuilder`/`Runtime.exec` process I/O (`isThreadCreationFromCommandExecution()`) or by Ares's own `@StrictTimeout` machinery (`isThreadCreationFromAresTimeout()`) → 🟢. On Windows, instrumentation further lets Java 17, 21 and 25 pass their own shell-folder task to a COM thread (`isJdkShellFolderHandOffWithoutStudentCode()`) → 🟢. This holds only when a `FileSystemView` method that Ares already checks as a file read asked for it.
4. **Internal Bypasses**: Thread creations owned by `ProcessBuilder`/`Runtime.exec` process I/O (`isThreadCreationFromCommandExecution()`) or by Ares's own `@StrictTimeout` machinery (`isThreadCreationFromAresTimeout()`) → 🟢. On Windows, instrumentation further lets Java 17, 21 and 25 pass their own shell-folder task to a COM thread (`isJdkShellFolderHandOffWithoutStudentCode()`) → 🟢. This holds only when a `FileSystemView` method that Ares already checks as a file read asked for it. Instrumentation further lets the Java runtime start its image clean-up thread (`isJdkImageDisposerSetUp()`) → 🟢. The runtime starts that thread for the first image stream. Only runtime code lies between that start and the check.
5. **Does the Call Come from Student Code?** → If no: 🟢
6. **Are All Thread Classes Allowed?** → Parameters, receiver instance, and object state are resolved into **one de-duplicated set** and checked in a single pass, so the quota is consumed at most once per distinct class per interception → If a class is forbidden or its quota is exhausted: 🔴
7. **Block and Throw Error** → If violation found
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,18 @@ Implemented by `ThreadPermission` in
The implicit tokens exist because not every thread is created by name. A parallel stream, a `Thread.sleep` or a `SubmissionPublisher` submission all reach the threading machinery without the student ever writing `new Thread(...)`, so each needs a token a policy can refer to.

`Lambda-Expression` covers a thread body supplied as a lambda, which has no nameable class.

A task handed to an executor or to `CompletableFuture` counts against the class of the task,
in both runtime modes. The pool threads that then run it are not counted again. `Arrays.parallelSort`,
`Arrays.parallelPrefix` and `Arrays.parallelSetAll` count as `<implicit-thread-op:parallel>`.

A new `java.util.Timer` starts its thread at once, so each timer counts as one thread of the class
`java.util.TimerThread`, in both runtime modes. The tasks scheduled on a timer run on that thread
and are not counted again.

A new `java.net.http.HttpClient` starts a selector thread at once, so each client counts as one
thread of the class `java.net.http.HttpClient`, in both runtime modes. Ares counts neither the
tasks the client hands to its pool nor the pool threads that run them. That holds even for a
Java Development Kit (JDK) executor the student built and handed to
`HttpClient.newBuilder().executor(...)`. Only an executor the student implements counts what its
own code starts. The network policy still decides which hosts and ports the client reaches.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ regardingTheSupervisedCode:
| --- | --- |
| `thisPolicyFileCompliesToThePolicyVersion` | The policy format the file is written against. A root field rather than a member of `regardingTheSupervisedCode`. Must be exactly `1`; a file that omits it is rejected on load. |
| `theFollowingProgrammingLanguageConfigurationIsUsed` | Selects the processing pipeline (build system, static analysis tool and dynamic analysis backend). See the table below. |
| `theSupervisedCodeUsesTheFollowingPackage` | The root package containing all student code to be supervised. |
| `theSupervisedCodeUsesTheFollowingPackage` | The root package containing all student code to be supervised. It must hold every class below the `withinPath` of `@Policy`, and `withinPath` must hold every compiled student class of this package. Ares refuses a run where the two differ, since one of its two checks then sees nothing. |
| `theMainClassInsideThisPackageIs` | The entrypoint class used to construct the call graph of the student program. |
| `theFollowingClassesAreTestClasses` | Test classes that execute student code. These are trusted and not sandboxed. Ares sandboxes an unlisted test class, helper class or superclass inside the supervised package like student code, constructor and setup and teardown methods included. |
| `regardingFileSystemInteractions` | Which paths the student code may interact with, and which operations (read, create, overwrite, execute, delete) are allowed. |
Expand All @@ -105,6 +105,20 @@ instance created for that method. A `@BeforeAll`, an `@AfterAll` and an instance
whole class (`@TestInstance(PER_CLASS)`) run before any method policy is known, so Ares restricts
them only when the test class itself carries `@Policy`. `@BeforeAll` and `@AfterAll` need
`@Public` or `@Hidden` on the class as well.

The argument source of a parameterised test, such as a `@MethodSource` method, runs under the
policy of that test, even for arguments it builds between two invocations. The same holds for
arguments JUnit closes after an invocation and for the tests a `@TestFactory` stream builds after
the factory has returned. The argument source of a `@ParameterizedClass` and the static
initialiser of a test class are class phases: Ares restricts them under the `@Policy` of the
class when the class carries `@Public` or `@Hidden` as well. The static initialiser escapes this
if something initialises the class before Ares sees it. JUnit does so for a class with a static
`@RegisterExtension` or `@ExtendWith` field, and an extension registered before Ares can too.

Once a test has ended, Ares refuses everything the policy restricts to code the test left running,
such as a thread or a shutdown hook. Between two tests of a parameterised test, a parameterised
class or a test factory with a policy, such code gets the allowances of that container instead,
until the container ends.
:::

## Supported programming language configurations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,32 +179,47 @@ public static Object getSettingsLock() {
private static volatile String frozenDefaultTempDirectory = null;

/**
* Resets the configuration settings to their default values.
* <p>
* This method is called via reflection from
* {@link de.tum.cit.ase.ares.api.jupiter.JupiterSecurityExtension} when a test
* does not have a {@link de.tum.cit.ase.ares.api.Policy} annotation or when the
* policy is explicitly deactivated with {@code @Policy(activated = false)}.
* This ensures that AOP advices from previous tests do not affect subsequent
* tests running in the same JVM instance.
* </p>
* <p>
* Design Rationale (I-032, scoped): synchronises on {@link #SETTINGS_LOCK} so
* this whole-set reset cannot interleave, field by field, with a concurrent
* {@link de.tum.cit.ase.ares.api.aop.java.JavaAOPTestCase#setJavaAdviceSettingValue}
* call (which synchronises on the same lock — see that class). This closes the
* race between concurrent <em>writers</em> (two security-test-case setup/reset
* sequences interleaving on the same JVM). It deliberately does
* <strong>not</strong> attempt the full fix the audit describes (a single
* immutable policy object behind one atomically-swapped reference): that would
* also require every <em>reader</em> — the settings-reading prelude of all
* eight {@code check*InteractionImpl} methods across both AOP backends — to
* synchronise on the same lock for its whole multi-field read sequence, a much
* larger change this session cannot safely verify without running the full
* test/architecture matrix. See the audit write-up for the full reasoning; this
* is the "scope the first commit to the swap mechanism" fallback it explicitly
* permits.
* </p>
* The thread that ended the last supervised test, or {@code null} while a test
* runs supervised. Only this thread, which runs JUnit and Ares, goes unchecked
* after a test has ended; any other thread the test left running, such as a
* shutdown hook, keeps being checked against no allowance at all.
*/
private static volatile Thread supervisionEndedOnThread = null;

/**
* Whether no thread is checked at all, because Ares does not guard what runs
* now: a test whose policy is deactivated, or a class phase without a policy.
*/
private static volatile boolean supervisionSuspended = false;

/**
* Ends a supervised test. Every allowance goes, but the package, the test
* classes and the modes stay, so code the test left running is refused from now
* on. The calling thread goes unchecked until the next test is armed. The
* package is never cleared here, since a moment without it would check nothing.
*/
public static void endSupervision() {
synchronized (SETTINGS_LOCK) {
clearAllowances();
JavaAOPTestCaseSettings.supervisionEndedOnThread = Thread.currentThread();
JavaAOPTestCaseSettings.supervisionSuspended = false;
}
}

/**
* Lifts every check until {@link #endSupervision()} runs, for a phase Ares does
* not guard.
*/
public static void suspendSupervision() {
supervisionSuspended = true;
}

/**
* Resets every setting to its default, so nothing is checked at all, except the
* frozen temp directory, which holds for the whole JVM. Writers synchronise on
* {@link #SETTINGS_LOCK}, so a reset never interleaves field by field with a
* write of {@code JavaAOPTestCase}; readers do not, so it is not atomic for
* them.
*/
public static void reset() {
synchronized (SETTINGS_LOCK) {
Expand All @@ -215,21 +230,31 @@ public static void reset() {
JavaAOPTestCaseSettings.mainClass = null;
JavaAOPTestCaseSettings.allowedListedPackages = null;
JavaAOPTestCaseSettings.allowedListedClasses = null;
JavaAOPTestCaseSettings.pathsAllowedToBeRead = null;
JavaAOPTestCaseSettings.pathsAllowedToBeOverwritten = null;
JavaAOPTestCaseSettings.pathsAllowedToBeCreated = null;
JavaAOPTestCaseSettings.pathsAllowedToBeExecuted = null;
JavaAOPTestCaseSettings.pathsAllowedToBeDeleted = null;
JavaAOPTestCaseSettings.hostsAllowedToBeConnectedTo = null;
JavaAOPTestCaseSettings.portsAllowedToBeConnectedTo = null;
JavaAOPTestCaseSettings.hostsAllowedToBeSentTo = null;
JavaAOPTestCaseSettings.portsAllowedToBeSentTo = null;
JavaAOPTestCaseSettings.hostsAllowedToBeReceivedFrom = null;
JavaAOPTestCaseSettings.portsAllowedToBeReceivedFrom = null;
JavaAOPTestCaseSettings.commandsAllowedToBeExecuted = null;
JavaAOPTestCaseSettings.argumentsAllowedToBePassed = null;
JavaAOPTestCaseSettings.threadClassAllowedToBeCreated = null;
JavaAOPTestCaseSettings.threadNumberAllowedToBeCreated = null;
clearAllowances();
JavaAOPTestCaseSettings.supervisionEndedOnThread = null;
JavaAOPTestCaseSettings.supervisionSuspended = false;
}
}

/**
* Removes every allowance of the policy, for files, network, commands and
* threads. The caller holds {@link #SETTINGS_LOCK}.
*/
private static void clearAllowances() {
JavaAOPTestCaseSettings.pathsAllowedToBeRead = null;
JavaAOPTestCaseSettings.pathsAllowedToBeOverwritten = null;
JavaAOPTestCaseSettings.pathsAllowedToBeCreated = null;
JavaAOPTestCaseSettings.pathsAllowedToBeExecuted = null;
JavaAOPTestCaseSettings.pathsAllowedToBeDeleted = null;
JavaAOPTestCaseSettings.hostsAllowedToBeConnectedTo = null;
JavaAOPTestCaseSettings.portsAllowedToBeConnectedTo = null;
JavaAOPTestCaseSettings.hostsAllowedToBeSentTo = null;
JavaAOPTestCaseSettings.portsAllowedToBeSentTo = null;
JavaAOPTestCaseSettings.hostsAllowedToBeReceivedFrom = null;
JavaAOPTestCaseSettings.portsAllowedToBeReceivedFrom = null;
JavaAOPTestCaseSettings.commandsAllowedToBeExecuted = null;
JavaAOPTestCaseSettings.argumentsAllowedToBePassed = null;
JavaAOPTestCaseSettings.threadClassAllowedToBeCreated = null;
JavaAOPTestCaseSettings.threadNumberAllowedToBeCreated = null;
}
}
Loading
Loading