The processes in an operating system must be protected from one another’s



tải về 252.86 Kb.
Chế độ xem pdf
trang26/34
Chuyển đổi dữ liệu13.12.2022
Kích252.86 Kb.
#53970
1   ...   22   23   24   25   26   27   28   29   ...   34
Abraham Silberschatz-Operating System Concepts (9th,2012.12)-trang-649-679

648
Chapter 14
Protection
It can be complicated for the
JVM
to determine what class is responsible for a
request to access a protected resource. Accesses are often performed indirectly,
through system libraries or other classes. For example, consider a class that
is not allowed to open network connections. It could call a system library to
request the load of the contents of a
URL
. The
JVM
must decide whether or not
to open a network connection for this request. But which class should be used
to determine if the connection should be allowed, the application or the system
library?
The philosophy adopted in Java is to require the library class to explicitly
permit a network connection. More generally, in order to access a protected
resource, some method in the calling sequence that resulted in the request must
explicitly assert the privilege to access the resource. By doing so, this method
takes responsibility
for the request. Presumably, it will also perform whatever
checks are necessary to ensure the safety of the request. Of course, not every
method is allowed to assert a privilege; a method can assert a privilege only if
its class is in a protection domain that is itself allowed to exercise the privilege.
This implementation approach is called
stack inspection
. Every thread
in the
JVM
has an associated stack of its ongoing method invocations. When
a caller may not be trusted, a method executes an access request within a
doPrivileged
block to perform the access to a protected resource directly or
indirectly.
doPrivileged()
is a static method in the
AccessController
class
that is passed a class with a
run()
method to invoke. When the
doPrivileged
block is entered, the stack frame for this method is annotated to indicate this
fact. Then, the contents of the block are executed. When an access to a protected
resource is subsequently requested, either by this method or a method it
calls, a call to
checkPermissions()
is used to invoke stack inspection to
determine if the request should be allowed. The inspection examines stack
frames on the calling thread’s stack, starting from the most recently added
frame and working toward the oldest. If a stack frame is first found that has the
doPrivileged()
annotation, then
checkPermissions()
returns immediately
and silently, allowing the access. If a stack frame is first found for which
access is disallowed based on the protection domain of the method’s class,
then
checkPermissions()
throws an
AccessControlException
. If the stack
inspection exhausts the stack without finding either type of frame, then
whether access is allowed depends on the implementation (for example, some
implementations of the
JVM
may allow access, while other implementations
may not).
Stack inspection is illustrated in Figure 14.9. Here, the
gui()
method of
a class in the untrusted applet protection domain performs two operations,
first a
get()
and then an
open()
. The former is an invocation of the
get()
method of a class in the

tải về 252.86 Kb.

Chia sẻ với bạn bè của bạn:
1   ...   22   23   24   25   26   27   28   29   ...   34




Cơ sở dữ liệu được bảo vệ bởi bản quyền ©hocday.com 2024
được sử dụng cho việc quản lý

    Quê hương