Repository navigation
Keep existing robots working with the robot security (#124) - #126
flemming-n-larsen wants to merge 9 commits into
Conversation
…ange global state
…n they are loaded Scanner on a file, ImageIO.write, Thread.stop on a robot's own threads, and creating a FileOutputStream, FileWriter or FileReader of a file descriptor no longer prevent a robot from being loaded. As with the SecurityManager, a robot is stopped when it really tries to do what it is not allowed to do.
|
It's funny I was just starting to make a PR when you posted this. So I will read over these. |
|
Every robot on the roborumble 1-vs-1 list was tested. e32.Omni 0.06 is rejected by both builds but wasn't yet found. Its bundled commons-math3 RandomDataGenerator uses MessageDigest and SecureRandom, which aren’t allowed. It runs normally on 1.11.1, but it broke with 1.11.2. Both classes look safe to allow.
Melee, twinduel, and teams are pending. |
|
Other robots blocked
Other issues worth noting: |
…own files, and load the time zone rules Robots were punished for Java looking up the providers of the time zone rules on the class path with the SecurityManager, the first time they used e.g. ZipOutputStream.
# Conflicts: # robocode.tests/src/test/java/net/sf/robocode/test/host/security/RobotClassVerifierTest.java
… handle more ways of using the replaced calls Replacing the new instruction with a method call only works without branches in the arguments, as the stack map refers to it, so it is now only used for Scanner, which is final, and is rejected with a clear message when it cannot be used. Also support Thread.stop() via a subclass, method handles, the constructors with a Charset, and stopping a thread before it starts. ImageIO no longer looks up plugins with the class loader of the robot, and Logger cannot be extended to load a resource bundle.
|
Thanks, this was very thorough. I've pushed updates to the PR, and everything you listed is covered except where noted:
The review also led to more fixes: I ran 23 of these robots against |
|
I'll rerun the entire set, it might take an hour or two however. |
|
Retested with all four rumbles (1,247 1v1 robots, 430 melee, 51 teams, 28 twin-duel teams), on Java 21 with the SecurityManager and on Java 25. No regressions, no robot stopped for a security violation, and no failed battles. e32.Omni 0.06 and kawigi.sbf.TidalWave 0.8 now load and fight. One thing that isn’t from this PR, but that the PR makes visible: Krabb.sliNk.Garm catches a StackOverflowError in its movement code and then gets the stack trace. If that’s the first stack trace through java.base in the JVM, StackTraceElement$HashedModules fails to initialize on the nearly full stack, and from then on every getStackTrace() in the JVM throws NoClassDefFoundError. Before this PR, the stack trace Robocode printed for TidalWave’s rejection at startup initialized that class first. Taking one stack trace through JDK code at startup, e.g. from a caught Integer.parseInt("x"), prevents it: GarmTeam vs ImWithStupidTeam went from 4 of 8 failing to 0 of 8 on Java 25. |
|
Thanks for finding the stack trace problem. The fix is on |
|
No need to wait on me, probably won't have time to poke at the autorumble more until this weekend. |
# Conflicts: # robocode.host/src/main/java/net/sf/robocode/host/HostManager.java
Fixes #124. Since 1.11.2, robots are rejected when loaded if they refer to something they may not use, even in code that never runs. Many of these robots are no longer updated, so this makes them work without any changes, inside Robocode.
Logger,Level,AWTKeyStroke,MessageDigestandSecureRandom, except the methods that change global state or load resource bundles.ImageIO.writeto a stream,new Scanner(File)with the same check asFileReader, andThread.stop()on a robot's own threads. Java 20+ can't stop threads, so there it interrupts.FileOutputStream,FileWriterandFileReader(FileDescriptor). Nothing is opened, and subclasses ofFileOutputStreamandFileWriterare still rejected when loaded.FileOutputStream,FileWriterandZipFileare replaced with small subclasses inrobocode.util, sonewstays valid.Scanneris final, so its constructor call is replaced with a static call. That is rejected with a clear message if the arguments contain a branch, or when it is used as a method reference.Tested: all tests on Java 17, 25 and 26 (141). 23 RoboRumble robots ran against
sample.Fireon Java 8 and 26, none stopped by the sandbox. KurtBot and Omni 0.06 are built for Java 17 and ran on Java 26 only. WhiteFang throws an exception from its own code at random, on all Java versions.Please check these in particular:
javax/imageio/spiisn't allowed.doPrivilegedcalls inRobotCompat.Loggermethods complete?@Chase-san, could you try this against AutoRumble? @jkflying, I'd like your eyes on the sandbox parts.