如何防止Java应用程序在GNU/Linux上执行流程?
换句话说,现代GNU/Linux或JVM(理想情况下是Java 11+)是否能够防止Java过程执行其他过程?
诸如Log4shell和Spring4shell之类的问题似乎是可能的,因为JVM允许Java应用程序执行其他程序。
在操作系统级别上,我想可能有一些过程隔离,监狱等,是否有完整的例子?
JVM本身怎么样?使用“ nofollow noreferrer”>安全管理器在最近的版本中消失了,还有哪些选项可以使Java Virtual Machine硬化?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定是否有一个好方法可以做到这一点。
如 rlimit_nproc 限制。
但是,不要为您的Java应用程序这样做 - 您会破坏它。
线程只是Linux上的一种特殊类型,如果限制NPROC,则无法创建新线程。
在运行的Java应用程序上观察此行为
,然后在Java应用程序的Stdout上
观察此行为,我尝试了在Docker容器中运行的生产应用程序。
请注意,如果您的过程作为root 运行,则 nproc限制不会执行。
此外,使用简单的clojure repl(或IT的jshell变体)重现它非常容易:
https://stackoverflow.com/questions/questions/27348744/prevent-frevent-frevent-forevent-frevent-frevent-frevent-frevent-frevent-frevent-frevent-frevent-frevent-frevent-
I'm not sure there's a good way to do that.
As discussed in Prevent forking in a child process,
you can set
RLIMIT_NPROC
limit.However, don't do that for your java app - you will break it.
Threads are just a special type of a process on Linux and if you restrict nproc you won't be able to create new threads.
Observe this behavior on a running java application
Then on the stdout of the java app
I tried this for a production app running in a docker container.
Note that nproc limit isn't enforced if you the process is running as root.
Morever, it's quite easy to reproduce it with a simple Clojure REPL (or JShell variant of it):
Resources: