
sediff Command in Linux
Security-Enhanced Linux (SELinux) is a strong security feature built into the Linux kernel that helps enforce security rules. It uses a system called mandatory access control (MAC) to control what users and processes can do with system resources.
An important task when managing SELinux settings is to check for differences between different versions of SELinux policies. This is where the sediff tool is useful. It helps us compare SELinux policies. In this tutorial, we will understand what sediff is, how it works, its features, and how to use it effectively.
Table of Contents
Here is a comprehensive guide to the options available with the sediff command −
- What is sediff Command?
- How does sediff Command work in Linux?
- How to Install sediff Command?
- How to Use sediff Command in Linux?
- sediff Command Options
- Comparing Two Policy Files with sediff Command
What is sediff Command?
sediff is a command-line tool used to compare two SELinux policy files. It helps identify differences between policy versions, making it useful for updates, patches, or audits. By tracking changes in SELinux rules and contexts, sediff helps administrators prevent security risks and unwanted behavior in secure Linux environments.
Features of sediff
Here are the key features of sediff, a tool designed for comparing and highlighting differences between files −
- sediff compares two SELinux policy files and highlights the differences, such as changes in rules or policy settings, helping administrators easily spot modifications.
- The tool displays the comparison results in a clear and easy-to-understand format, making it simple to interpret the differences.
- sediff works seamlessly with other SELinux utilities, like semodule, seinfo, and semanage, making it a useful tool for managing SELinux policies.
- sediff aids in auditing SELinux policy changes by showing what modifications were made and offering insights into the reasons behind them.
How does sediff Command work in Linux?
sediff compares SELinux policy modules in both binary and text formats. It looks at two compiled policy files and shows any changes, like new rules, updates, or deletions.
When you use sediff, it gives you a clear output that highlights the differences between the policies. This makes it easier for administrators to spot changes, such as added or changed rules and deleted ones, helping them assess the impact of these changes.
How to Install sediff Command?
Sediff is a tool that comes with the policycoreutils package, which is typically pre-installed on most Linux distributions that support SELinux. However, if you don't have it yet, you can easily install it by running a simple command, depending on your Linux distribution.
For systems like CentOS or RHEL, you can use the following command to install the package −
sudo yum install policycoreutils
For Debian or Ubuntu-based systems, use this command −
sudo apt-get install policycoreutils
After the installation is finished, you'll be able to start using sediff to compare SELinux policies and analyze the differences between them.
How to Use sediff Command in Linux?
sediff is useful for auditing SELinux policy changes, comparing policy updates, detecting security vulnerabilities from unintended modifications, and verifying the correctness of applied patches. It helps ensure consistency, security, and compliance in SELinux-managed systems.
The basic syntax to use sediff is quite simple. Here's the general command structure −
sediff [OPTIONS] [EXPRESSION] POLICY1 POLICY2
Here, POLICY1 refers to the policy file you're using as the reference and POLICY2 is the policy file that you want to compare the old one to. Moreover, you can specify an expression to focus on specific policy elements you want to compare. If no expression is provided, sediff will compare all supported elements by default.
Note − A policy refers to a file containing a binary SELinux policy. On Linux, this file is often named by version, like policy.30. On Android systems, it's usually called sepolicy. If you don't provide a policy file, sediff will show an error and exit.
sediff Command Options
You can also add options to customize how the comparison is done, but the main idea is to provide the old and new policy files for comparison −
Option | Description |
---|---|
-h, --help | Shows help information about the command and then exits. Use this option if you need guidance on how to use the command. |
--stats | Displays only the difference statistics, showing how things have changed, and then exits. |
--version | Shows the version information of the command or tool you are using and then exits. |
-v, --verbose | Provides extra information during execution. This option is useful if you want to see more details about what the command is doing. |
--debug | Turns on debugging mode, which gives detailed output useful for troubleshooting or understanding the internal process of the command. |
Component Differences
Here are different options to compare various aspects of the policies −
Option | Description |
---|---|
--common | Compares permission sets that are common between the two policies. |
-c, --class | Compares object classes. |
-t, --type | Compares attributes linked to types. |
-a, --attribute | Compares types assigned to attributes. |
-r, --role | Compares types authorized for roles. |
-u, --user | Compares roles assigned to users. |
-b, --bool | Compares default boolean values. |
--sensitivity | Compares sensitivity definitions. |
--category | Compares category definitions. |
--level | Compares MLS (Multi-Level Security) level definitions. |
Type Enforcement Rule Differences
To compare rules related to type enforcement, use these options −
Option | Description |
---|---|
-A | Compares allow and allowxperm rules. |
--allow | Compares allow rules. |
--auditallow | Compares auditallow rules. |
--dontaudit | Compares dontaudit rules. |
--neverallow | Compares neverallow rules. |
--allowxperm | Compares allowxperm rules. |
--auditallowxperm | Compares auditallowxperm rules. |
--dontauditxperm | Compares dontauditxperm rules. |
--neverallowxperm | Compares neverallowxperm rules. |
-T, --type_trans | Compares type_transition rules. |
--type_member | Compares type_member rules. |
--type_change | Compares type_change rules. |
RBAC and MLS Rule Differences
For Role-Based Access Control (RBAC) and MLS rules, you can use −
- --role_allow to compare role allow rules.
- --role_trans to compare role transition rules.
- --range_trans to compare range transition rules.
For a profound understanding of the sediff command, run the following command −
man sediff

Comparing Two Policy Files with sediff Command
To perform a basic comparison of two SELinux policy files, use the sediff command as follows −
sediff /path/to/old_policy.pp /path/to/new_policy.pp
This will show you the differences between the two policy files, so you can easily see what has changed. More specifically, the output will highlight the following −
- Added Policies − These are policies that are found in the new policy file but not in the old one.
- Removed Policies − These are policies that were in the old policy file but are missing from the new one.
- Modified Policies − These are policies that exist in both files but have been changed in the newer file.
Conclusion
sediff is a useful command line utility that plays a vital role in maintaining the integrity and security of SELinux-managed systems. Comparing SELinux policy files helps administrators easily detect changes, audit updates, and verify patch implementations.
sediff offers a clear and efficient way to understand policy differences while you're tracking modifications for compliance or analyzing potential security risks. Its ease of use and rich comparison options make it an essential utility for anyone managing SELinux policies.