Design and Implementation of IPC access control for Android

Source: Internet
Author: User

3.3.1 Design and Implementation of IPC Hook Functions

IPC binder is the most important inter-process communication mechanism for Android. Therefore, mandatory access control must be implemented here.

1. Modify secuirty. h

Open the terminal shell, enter the command "CD/android4.0/kernel/goldfish/include/Linux/Vim security. H", find the security_operations structure, and add the function pointer variable, as shown below:

/*

* This is the main security structure.

*/

Struct security_operations {

Charname [security_name_max + 1];

# Ifdef have_smack

/*

* To add a binder hook

**/

INT (* binder_transaction) (struct task_struct * From, struct task_struct * );

# Endif

Then, after the security_operations definition ends, add the function declaration as follows:

# Ifdef have_smack

Int security_binder_transaction (structtask_struct * From, struct task_struct * );

# Endif

Add the security_binder_transaction definition to the implementation of the lsm hook function, as follows:

# Ifdef have_smack

Static inline intsecurity_binder_transaction (struct task_struct * From, struct task_struct * ){

Return 0;

}

# Endif

2. Modify security. C.

Open the terminal shell, enter the command "CD/android4.0/kernel/goldfish/security/Vim security. c", and add the function as follows:

# Ifdefhave_smack

Intsecurity_binder_transaction (struct task_struct * From, struct task_struct * ){

Returnsecurity_ops-> binder_transaction (from, );

}

# Endif

3. Modify smack_lsm.c

Open the terminal shell, enter the command "CD/android4.0/kernel/goldfish/security/smack/Vim smack_lsm.c", and add the function "smack_binder_transaction", as shown below:

# Ifdefhave_smack

/*

* Smack_binder_transaction-to check bindertransaction between two tasks

**/

Static intsmack_binder_transaction (struct task_struct * From, struct task_struct * ){

Int RC1, RC2;

/*

* Ask the two task must have writepermission to each other

**/

RC1 = smk_access (task_security (from), task_security (to), may_write );

RC2 = smk_access (task_security (to), task_security (from), may_write );

 

Return RC1 = 0 & RC2 = 0? ;

}

# Endif

This hook function is used to determine whether the source process from and target process to have the permission to write to each other. Finally, the new member variables in the security_operations smack_ops struct are as follows:

Structsecurity_operations smack_ops = {

. Name = "Smack ",

# Ifdefhave_smack

. Binder_transaction = smack_binder_transaction,

# Endif

4. recompile the simulator Kernel

The method for compiling the android kernel is described in Chapter 2, which is not described here.

3.3.2

Each process is divided into two parts: user space and kernel space. The user space of different processes cannot be shared. The process kernel space uses Android binder to implement IPC. The binder driver code is located in "/android4.0/kernel/goldfish/driver/staging/Android/bind. in the c file, the binder_transaction function uses the data of the binder_transaction_data struct to perform operations such as binder addressing, copying binder IPC data, and generating and retrieving binder nodes. Open the terminal shell and enter the command "cd ".
/Host/android4.0/kernel/goldfish/Drivers/staging/Android/Vim binder. C ", find the definition of this function, as follows:

Static voidbinder_transaction (struct binder_proc * proc, struct binder_thread * thread, struct binder_transaction_data * TR, int reply );

After determining the source and target processes, add the following code:

If (security_binder_transaction (proc-> Tsk, target_proc-> TSK )){

Return_error = br_failed_reply;

Goto err_invalid_target_handle;

}

Specifically, target_proc-> tsk points to task_struct of the target process, proc-> tsk points to task_struct of the source process, and security_task_movememory is added to determine whether the current process has write permission on the source process, security_binder_transaction is used to determine whether the source process has the write permission on the target process. These two functions are LSM hook functions. Because the kernel has been loaded with the smack module, they point to smack_task_movememory and smack_binder_transaction of the smack. The above code is added to prevent the process from abusing IPC without authorization.
Binder for communication, as shown in:

As shown in, the service client calls the foo function of the Service server through binder. The service client passes binder IPC data to the Service server through binderdriver, which is the medium for communication between the source and target processes, the IPC check mechanism is to check whether the source and target processes have the "write" permission to each other in the binder driver. If the process security label is not "_", smack can be used to control the process. For example, if the upper-layer application wants to send text messages, the Linux Process corresponding to the upper-layer application communicates with the radio process in binderdriver, if the smack rule denies the upper-layer application's "write" permission on radio, the upper-layer application cannot implement the function of sending text messages. For another example, if upper-layer applications want to access the address book, the upper-layer applications are also in the binder
The driver communicates with the address book process. If the smack rule allows upper-layer applications to "write" the address book process, upper-layer applications can access the address book. Malware may bypass the permission check mechanism on the android framework layer, but they cannot bypass the kernel's IPC check.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.