Security of Embedded Java Virtual Machine

本文从四个方面探讨了嵌入式Java虚拟机的安全性:MIDP2.0安全机制、Java语言特性、类文件验证及JVM实现。特别强调了在资源受限的嵌入式环境中如何确保Java应用的安全运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Security of Embedded Java Virtual Machine

This article introduces the security of embedded Java virtual machine (EJVM).

Meeting this topic, you may consider it an introduction of J2ME security mechanism. No! Although security model of MIDP 2 seems perfect, it’s only a part of security solution of embedded Java virtual machine.

picture 1: J2ME technical architecture

Picture 1 shows the technical architecture of J2ME, security solution should cover all these levels. In my opinion, I consider security of EJVM in four aspects:

MIDP 2.0 Security Mechanism

Java language

Class files verifying

Implementation of JVM

Let me introduce them respectively.

1 MIDP 2.0 Security Mechanism

MIDP (Mobile Information Device Profile) 2.0 has a complete authorization model.

1.1 Sensitive Operations

In mobile information device, some operations are very sensitive for the users. Network connection is one of them. Because the hardware resource is very limited, and data transferring is expensive.

The MIDP 2.0 specification defines a set of operations as sensitive. To perform any one of it, the application must get approval from user.

javax.microedition.io.Connector.http

javax.microedition.io.Connector.socket

javax.microedition.io.Connector.https

javax.microedition.io.Connector.ssl

javax.microedition.io.Connector.datagram

javax.microedition.io.Connector.serversocket

javax.microedition.io.Connector.datagramreceiver

javax.microedition.io.Connector.comm

javax.microedition.io.PushRegistry

table 1: sensitive operations/permissions list

As table 1 shows, permission names are not same as package names, but they are similar.

For example, if a MIDlet want to connect to some server with HTTP, is must get permission to do that. Because connecting HTTP is a sensitive operation, only when user approve, the MIDlet can go on.

1.2 Permission

Normally, there are several kinds of permission level user can choose. Take WTK 2.0 of SUN for example, three kinds of permission can be selected by user:

Oneshot: The MIDP implementation retains no memory of the user's decision and will ask for a permission every time it is needed.

Session: The implementation remembers the user's decision until the MIDlet is terminated.

Blanket: The user's decision sticks until the MIDlet suite is uninstalled.

1.3 Protection Domain

If user must choose to grant or deny the authorization, it’ll be a lot of trouble. In fact, users don’t have to do that every time, at least for these safe MIDlets. MIDlet suites are classified into different protection domains. Each domain has different permissions authorization. A domain stands for some level of safety, some permissions are granted and some denied by default.

Usually, there will be at least three kinds of protection domain defined:

Manufactory: These MIDlet suites are made by device vendors or operators, they are absolutely safe, so every permission are granted, the MIDlet suite can do any sensitive operation on the platform.

Trusted: These MIDlet suites are made by trusty vendors, but there still be security risk, so some critical permission are denied by default, when such operations are performed, user will be queried.

Untrusted: Vendor of MIDlet suite is unknown, the program may be dangerous, so every sensitive operation must get user’s grant.

2 Java language

As a language, Java has some mechanism to enhance the security inner itself.

2.1 Structured memory access

One measure to enhance the security in language level is structured memory access. It means that developer can’t access memory directly.

Why unrestrained memory access would be a security risk is that a wily cracker could potentially use memory pointer to subvert the security system. If, for example, a cracker could learn where in memory a class loader is stored, it could assign a pointer to that memory and manipulate the class loader's data. By enforcing structured access to memory, the Java virtual machine yields programs that are robust, but also frustrates crackers who dream of harnessing the internal memory of the Java virtual machine for their own devious plots.

2.2 Checking of array boundary

Another aspect of enhanced security is about array. A common error of C/C++ programmer is covering bytes beyond boundary while writing data to an array. Some times, this will cause serious problem, even make the program crash. And this is common method used by crackers to attack a system. But this will never happen in Java language.

According to Java language specification, Java Virtual Machine will check the use of array, if a programmer wants to write or read a member of array by index which is beyond the boundary, an exception will be threw out.

2.3 Garbage collection

Automatic garbage collection is another vantage of Java language. In C/C++ language, programmers have to free the memory blocks which are allocated manually. Memory leakage won’t give attack chances to crackers, but it will bring down the performance of program, especially in embedded system, the memory resource is very limited, memory leakage may cause serious problem.

Java language can release programmers from these troubles. Unused memory collection will be performed by VM. If an object is not referenced by any handle, it’ll be marked as “unreferenced”, and will be freed in some appropriate occasion.

 

3 Class files verifying

To ensure the security, some kinds of class file scanning will be performed before executing. Each scanning is to verify some different content.

However, these verifying are not strictly prescribed in JVM specification, it depends on implementation. Usually, PC JVM will perform all these scanning, but for EJVM it may me different.

3.1 Common Verifying of class files

Although compliant Java compilers should not generate malformed class files, a Java virtual machine can't tell how a particular class file was created. Because a class file is just a sequence of bytes, a virtual machine can't know whether a particular class file was generated by a well-meaning Java compiler or by shady crackers bent on compromising the integrity of the virtual machine. As a consequence, all Java virtual machine implementations have a class file verifier that can be invoked on class files, to make sure the types they define are safe to use.

For common used JVM on PC, four scanning will be performed during loading a class file:

3.1.1 Structural Checks on the Class File

The first scanning is to ensure the structure of class file.

The verifier performs many checks during this pass. For example, every class file must start with the same four bytes, the magic number: 0xCAFEBABE. The purpose of the magic number is to make it easy for the class file parser to reject files that were either damaged or were never intended to be class files in the first place. The verifier also makes sure the major and minor version numbers declared in the class file are within the range supported by that implementation of the Java virtual machine.

Also during pass one, the class file verifier checks to make sure the class file is neither truncated nor enhanced with extra trailing bytes. Although different class files can be different lengths, each individual component contained inside a class file indicates its length as well as its type. The verifier can use the component types and lengths to determine the correct total length for each individual class file.

3.1.2 Semantic Checks on the Type Data

During this pass, the verifier looks at individual components, to make sure they are well-formed instances of their type of component. For example, a method descriptor (its return type and the number and types of its parameters) is stored in the class file as a string that must adhere to a certain context-free grammar. One check the verifier performs on individual components is to make sure each method descriptor is a well-formed string of the appropriate grammar.

3.1.3 Byte code Verification

During this pass, which is commonly called the "byte code verifier," the Java virtual machine performs a data-flow analysis on the streams of byte codes that represent the methods of the class.

This step is the longest one. The byte code verifier does a great deal of checking. It checks to make sure that no matter what path of execution is taken to get to a certain “opcode” in the byte code stream, the operand stack always contains the same number and types of items. It checks to make sure no local variable is accessed before it is known to contain a proper value. It checks that fields of the class are always assigned values of the proper type, and that methods of the class are always invoked with the correct number and types of arguments. The byte code verifier also checks to make sure that each opcode is valid.

After this scanning, the stream of byte code is proved to be safe for the Java virtual machine to execute.

3.1.4 Verification of Symbolic References

Pass four of the class file verifier takes place when the symbolic references contained in a class file are resolved in the process of dynamic linking. During pass four, the Java virtual machine follows the references from the class file being verified to the referenced class files, to make sure the references are correct.

When the Java virtual machine resolves a symbolic reference, pass four of the class file verifier makes sure the reference is valid. If the reference is not valid--for instance, if the class cannot be loaded or if the class exists but doesn't contain the referenced field or method--the class file verifier throws an error.

3.2 Verifying performed by EJVM

For EJVM, if four scanning are all performed each time when loading a new class file, the performance will be greatly reduced. In embedded system, the speed of CPU is much lower then PC, four times of verifying is too time-consuming.

Usually, EJVM use other method to guarantee correctness of class files:

(1) Standard library classes are verified before they are solidified in ROM. During loading period, no verifying is performed.

(2) MIDlet suites are verified during installation. Once they are installed in device, they are considered as safe, no need to verify any more.

4 Implementation of JVM

4.1 Buffer Overflow (Inner JVM)

Buffer overflow, or buffer overrun, is an anomalous condition where a process attempts to store data beyond the boundaries of a fixed-length buffer. The result is that the extra data overwrites adjacent memory locations. The overwritten data may include other buffers, variables and program flow data, and may result in erratic program behavior, a memory access exception, program termination (a crash), incorrect results or a possible breach of system security.

Buffer overflow is the most commonly used method by cracker to infiltrate a system. Usually, cracker will copy more data into the fixed-length buffer, cover the return address of the function. When the function returns, the process will jump to somewhere to go on executing, while a piece of carefully designed code which called “shellcode” is waiting there. Then the system will be managed by cracker.

Although Java language has “array boundary checking” to prevent buffer overflow, for JVM it’s another pair of shoes, because JVM is written in local language (C/C++). Buffer Overflow is not a particular threaten for JVM, but JVM will suffer it as well.

4.2 Native Interface (Out of JVM)

Java Native Interface (JNI) is a topic of J2SE, not J2ME, that’s right! But for EJVM, for the standard library of MIDP, some implementation of EJVM may support JNI to implement features depending on system.

JNI breaks the OO concept of Java language. When EJVM is going to call some native interface, it must load some dynamic link library at first and then call the functions. From view point of security, there is too much risk in this procedure: the library file may be unauthorized, or it may be replaced, the function may be unsafe, etc.

5 Summary

This article summaries the security of embedded Java virtual machine from four aspects. The security solution of J2ME is complete and trustable. But from view of implementation of EJVM, every EJVM is distinguished from each other, so there are still some risks.

### Self-Ensemble Concept In the realm of machine learning, self-ensemble refers to a technique where multiple models are created from variations or augmentations of training data points. These models collectively contribute towards making predictions that can be more robust than those made by any single model alone[^1]. The ensemble is built using different snapshots of the same neural network at various stages during its training process. The core idea behind this approach lies in leveraging diverse perspectives provided by these varied instances of the model trained on slightly altered datasets derived through transformations like noise addition or dropout regularization techniques applied over original inputs. This diversity helps improve generalization capabilities while reducing variance across predictions. #### Applications in Machine Learning One prominent application area for self-ensembles involves semi-supervised learning scenarios wherein only limited labeled examples exist alongside abundant unlabeled ones available for use during training phases. By applying consistency regularization methods such as Mean Teacher (MT), Temporal Ensembling (TE), Virtual Adversarial Training (VAT), etc., one ensures stable performance even when dealing with scarce supervision signals. Another significant utilization pertains to unsupervised domain adaptation tasks aiming to transfer knowledge acquired within source domains characterized by ample annotated samples into target environments lacking sufficient labeling but sharing similar characteristics otherwise unobserved directly due to distributional shifts between them both spatially and temporally speaking. Additionally, self-ensemble has been successfully employed in improving adversarial robustness against carefully crafted attacks designed specifically targeting deep networks' vulnerabilities exposed under certain conditions leading potentially catastrophic failures unless properly mitigated beforehand via defensive mechanisms embedded throughout architecture design choices including preprocessing steps taken prior feeding raw input features into subsequent layers responsible ultimately producing final outputs after passing several intermediate computations along pathways connecting neurons together forming complex webs capable performing intricate pattern recognition feats beyond human comprehension levels achievable today thanks largely advances brought forth recent years particularly around computational power availability coupled efficient algorithms development enabling faster experimentation cycles yielding better results overall time frame considered historically relevant benchmarks established previously before current era commenced officially ushering new age artificial intelligence research endeavors worldwide spanning numerous disciplines ranging natural sciences social studies humanities arts culture technology engineering mathematics statistics physics chemistry biology medicine health care environmental sustainability energy resources management policy governance ethics law regulation compliance security privacy protection safety assurance quality control standards setting benchmark creation measurement evaluation assessment feedback improvement innovation disruption transformation evolution revolution renaissance enlightenment awakening consciousness expansion awareness elevation transcendence ascension liberation freedom empowerment autonomy sovereignty independence interdependence cooperation collaboration coordination synchronization harmonization integration synthesis analysis decomposition reconstruction deconstruction construction building designing creating imagining envisioning conceptualizing theorizing hypothesizing experimenting validating verifying falsifying refuting rebutting arguing debating discussing communicating collaborating cooperating coordinating synchronizing harmonizing integrating synthesizing analyzing decomposing reconstructing deconstructing constructing building designing creating imagining envisioning conceptualizing theorizing hypothesizing experimenting validating verifying falsifying refuting rebutting arguing debating discussing communicating. ```python import numpy as np def create_self_ensemble(model, X_train, y_train=None): ensembles = [] # Create multiple versions of the dataset with slight modifications. for i in range(5): modified_X = apply_transformation(X_train.copy()) if y_train is not None: ensemble_model = train_model(model, modified_X, y_train) else: ensemble_model = train_unsupervised_model(model, modified_X) ensembles.append(ensemble_model) return ensembles def predict_with_self_ensemble(ensembles, X_test): all_predictions = [] for model in ensembles: prediction = model.predict(X_test) all_predictions.append(prediction) averaged_prediction = np.mean(all_predictions, axis=0) return averaged_prediction ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值