Verify that Shared Library Files Have Restrictive Permissions

Classification:

compliance

Framework:

Control:

Description

System-wide shared library files, which are linked to executables during process load time or run time, are stored in the following directories by default:

/lib
/lib64
/usr/lib
/usr/lib64

Kernel modules, which can be added to the kernel during runtime, are stored in /lib/modules. All files in these directories should not be group-writable or world-writable. If any file in these directories is found to be group-writable or world-writable, correct its permission with the following command:

$ sudo chmod go-w *FILE*

Rationale

Files from shared library directories are loaded into the address space of processes (including privileged ones) or of the kernel itself at runtime. Restrictive permissions are necessary to protect the integrity of the system.

Remediation

Shell script

The following script can be run on the host to remediate the issue.

find -H /lib/ -perm /g+w,o+w -type f -regex '^.\*$' -exec chmod g-w,o-w {} \;

find -H /lib64/ -perm /g+w,o+w -type f -regex '^.\*$' -exec chmod g-w,o-w {} \;

find -H /usr/lib/ -perm /g+w,o+w -type f -regex '^.\*$' -exec chmod g-w,o-w {} \;

find -H /usr/lib64/ -perm /g+w,o+w -type f -regex '^.\*$' -exec chmod g-w,o-w {} \;

Ansible playbook

The following playbook can be run with Ansible to remediate the issue.

- name: Find /lib/ file(s) recursively
 command: find -H /lib/ -perm /g+w,o+w -type f -regex "^.\*$"
 register: files\_found
 changed\_when: false
 failed\_when: false
 check\_mode: false
 tags:
 - NIST-800-53-AC-6(1)
 - NIST-800-53-CM-5(6)
 - NIST-800-53-CM-5(6).1
 - NIST-800-53-CM-6(a)
 - configure\_strategy
 - file\_permissions\_library\_dirs
 - low\_complexity
 - low\_disruption
 - medium\_severity
 - no\_reboot\_needed

- name: Set permissions for /lib/ file(s)
 file:
 path: '{{ item }}'
 mode: g-w,o-w
 state: file
 with\_items:
 - '{{ files\_found.stdout\_lines }}'
 tags:
 - NIST-800-53-AC-6(1)
 - NIST-800-53-CM-5(6)
 - NIST-800-53-CM-5(6).1
 - NIST-800-53-CM-6(a)
 - configure\_strategy
 - file\_permissions\_library\_dirs
 - low\_complexity
 - low\_disruption
 - medium\_severity
 - no\_reboot\_needed

- name: Find /lib64/ file(s) recursively
 command: find -H /lib64/ -perm /g+w,o+w -type f -regex "^.\*$"
 register: files\_found
 changed\_when: false
 failed\_when: false
 check\_mode: false
 tags:
 - NIST-800-53-AC-6(1)
 - NIST-800-53-CM-5(6)
 - NIST-800-53-CM-5(6).1
 - NIST-800-53-CM-6(a)
 - configure\_strategy
 - file\_permissions\_library\_dirs
 - low\_complexity
 - low\_disruption
 - medium\_severity
 - no\_reboot\_needed

- name: Set permissions for /lib64/ file(s)
 file:
 path: '{{ item }}'
 mode: g-w,o-w
 state: file
 with\_items:
 - '{{ files\_found.stdout\_lines }}'
 tags:
 - NIST-800-53-AC-6(1)
 - NIST-800-53-CM-5(6)
 - NIST-800-53-CM-5(6).1
 - NIST-800-53-CM-6(a)
 - configure\_strategy
 - file\_permissions\_library\_dirs
 - low\_complexity
 - low\_disruption
 - medium\_severity
 - no\_reboot\_needed

- name: Find /usr/lib/ file(s) recursively
 command: find -H /usr/lib/ -perm /g+w,o+w -type f -regex "^.\*$"
 register: files\_found
 changed\_when: false
 failed\_when: false
 check\_mode: false
 tags:
 - NIST-800-53-AC-6(1)
 - NIST-800-53-CM-5(6)
 - NIST-800-53-CM-5(6).1
 - NIST-800-53-CM-6(a)
 - configure\_strategy
 - file\_permissions\_library\_dirs
 - low\_complexity
 - low\_disruption
 - medium\_severity
 - no\_reboot\_needed

- name: Set permissions for /usr/lib/ file(s)
 file:
 path: '{{ item }}'
 mode: g-w,o-w
 state: file
 with\_items:
 - '{{ files\_found.stdout\_lines }}'
 tags:
 - NIST-800-53-AC-6(1)
 - NIST-800-53-CM-5(6)
 - NIST-800-53-CM-5(6).1
 - NIST-800-53-CM-6(a)
 - configure\_strategy
 - file\_permissions\_library\_dirs
 - low\_complexity
 - low\_disruption
 - medium\_severity
 - no\_reboot\_needed

- name: Find /usr/lib64/ file(s) recursively
 command: find -H /usr/lib64/ -perm /g+w,o+w -type f -regex "^.\*$"
 register: files\_found
 changed\_when: false
 failed\_when: false
 check\_mode: false
 tags:
 - NIST-800-53-AC-6(1)
 - NIST-800-53-CM-5(6)
 - NIST-800-53-CM-5(6).1
 - NIST-800-53-CM-6(a)
 - configure\_strategy
 - file\_permissions\_library\_dirs
 - low\_complexity
 - low\_disruption
 - medium\_severity
 - no\_reboot\_needed

- name: Set permissions for /usr/lib64/ file(s)
 file:
 path: '{{ item }}'
 mode: g-w,o-w
 state: file
 with\_items:
 - '{{ files\_found.stdout\_lines }}'
 tags:
 - NIST-800-53-AC-6(1)
 - NIST-800-53-CM-5(6)
 - NIST-800-53-CM-5(6).1
 - NIST-800-53-CM-6(a)
 - configure\_strategy
 - file\_permissions\_library\_dirs
 - low\_complexity
 - low\_disruption
 - medium\_severity
 - no\_reboot\_needed