Skip to content

Commit f03c89f

Browse files
authored
Merge pull request #320 from stackhpc/fix/CVE-2023-41914-v2
Fix CVE 2023 41914
2 parents 76be3d8 + 4c6aa82 commit f03c89f

File tree

12 files changed

+207
-1
lines changed

12 files changed

+207
-1
lines changed

ansible/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,5 @@ roles/*
4242
!roles/proxy/**
4343
!roles/resolv_conf/
4444
!roles/resolv_conf/**
45+
!roles/cve-2023-41914
46+
!roles/cve-2023-41914/**

ansible/adhoc/cve-2023-41914.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
- hosts: openhpc
2+
gather_facts: no
3+
become: yes
4+
tasks:
5+
- import_role:
6+
name: cve-2023-41914

ansible/fatimage.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Builder version of site.yml just installing binaries
22

3+
- hosts: builder
4+
become: no
5+
gather_facts: no
6+
tasks:
7+
- name: Report hostname (= final image name)
8+
command: hostname
9+
310
- name: Run pre.yml hook
411
vars:
512
appliances_environment_root: "{{ lookup('env', 'APPLIANCES_ENVIRONMENT_ROOT') }}"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# cve-2023-41914
2+
3+
This role fixes [Slurm CVE-2023-41914](https://lists.schedmd.com/pipermail/slurm-announce/2023/000100.html):
4+
5+
> A number of race conditions have been identified within the slurmd/slurmstepd processes that can lead to the user taking ownership of an arbitrary file on the system. A related issue can lead to the user overwriting an arbitrary file on the compute node (although with data that is not directly under their control). A related issue can also lead to the user deleting all files and sub-directories of an arbitrary target directory on the compute node.
6+
7+
**NB:** It is only suitable for use on systems installed from OpenHPC v2.6.1 (Slurm v22.05).
8+
9+
At the time of writing, new OpenHPC packages have been built but are not available from the respositories (reference), hence `dnf update ...` is not available.
10+
11+
This role can be run in two ways:
12+
13+
1. To remediate an existing system, run `tasks/main.yml`, e.g. using the playbook `ansible/adhoc/cve-2023-41914.yml`. This will:
14+
- Stop all Slurm services
15+
- Backup the slurmdbd mysql database to the volume-backed directory `/var/lib/state/mysql-backups/` on the control node (by default).
16+
- Uninstall the affected packages and install updated rpms from the OpenHPC build system.
17+
- Restart Slurm services.
18+
19+
**NB**: This playbook will ALWAYS stop and restart Slurm, even if no updates are actually required.
20+
21+
2. To remediate images during build (i.e no Slurm services are running, no slurm database exists), run `tasks/install-rpms.yml`, e.g. using the following in an environment pre-hook:
22+
23+
```yaml
24+
- hosts: builder
25+
gather_facts: no
26+
become: yes
27+
tasks:
28+
- name: Apply fixes for cve-2023-41914
29+
import_role:
30+
name: cve-2023-41914
31+
tasks_from: install-rpms.yml
32+
```
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
# _cve_2023_41814_installed_slurm: []
3+
cve_2023_41914_mysql_backup_path: "{{ mysql_datadir }}-backups/{{ lookup('pipe', 'date --iso-8601=seconds') }}.sql"
4+
5+
cve_2023_41914_rpm_url: http://obs.openhpc.community:82/OpenHPC:/2.6.2:/Factory/EL_8/x86_64
6+
cve_2023_41914_rpms: # see cve_2023_41914_rpm_url
7+
- slurm-ohpc # has to be first as dependency
8+
- slurm-contribs-ohpc
9+
- slurm-devel-ohpc
10+
- slurm-example-configs-ohpc
11+
- slurm-libpmi-ohpc
12+
- slurm-ohpc-slurmrestd
13+
- slurm-openlava-ohpc
14+
- slurm-pam_slurm-ohpc
15+
- slurm-perlapi-ohpc
16+
- slurm-slurmctld-ohpc
17+
- slurm-slurmd-ohpc
18+
- slurm-slurmdbd-ohpc
19+
- slurm-sview-ohpc
20+
- slurm-torque-ohpc
21+
cve_2023_41914_rpm_fix_ver: '22.05.10'
22+
cve_2023_41914_rpm_fix_release: '2.1.ohpc.2.6.2'
23+
_cve_2023_41814_updates: []
24+
cve_2023_41914_pkglist_path: "{{ appliances_environment_root }}/{{ inventory_hostname }}-cve_2023_41814_updates"
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
- name: Validate suitability
2+
include_tasks: validate.yml
3+
when: _cve_2023_41814_installed_pkgs is undefined
4+
5+
- name: Identify packages to update
6+
set_fact:
7+
_cve_2023_41814_updates: "{{ _cve_2023_41814_updates + [item] }}"
8+
loop: "{{ cve_2023_41914_rpms }}"
9+
when:
10+
- item in ansible_facts.packages
11+
- cve_2023_41914_rpm_fix_ver is version(ansible_facts.packages[item][0].version, '>')
12+
13+
- name: Write packages to be modified to a file
14+
# allows recovery from failures in subsequent package deletion/rpm install
15+
copy:
16+
dest: "{{ cve_2023_41914_pkglist_path }}"
17+
content: "{{ _cve_2023_41814_updates | to_nice_yaml }}"
18+
when: _cve_2023_41814_updates | length > 0
19+
delegate_to: localhost
20+
21+
- name: Read packages to modify
22+
set_fact:
23+
_cve_2023_41814_updates: "{{ lookup('file', cve_2023_41914_pkglist_path) | from_yaml }}"
24+
25+
- name: Identify architecture
26+
setup:
27+
gather_subset: architecture
28+
29+
- name: Remove installed packages
30+
dnf:
31+
name: "{{ _cve_2023_41814_updates }}"
32+
state: absent
33+
34+
- name: Install rpms
35+
dnf:
36+
name: "{{ cve_2023_41914_rpm_url }}/{{ item }}-{{ cve_2023_41914_rpm_fix_ver }}-{{ cve_2023_41914_rpm_fix_release }}.{{ ansible_architecture }}.rpm"
37+
loop: "{{ _cve_2023_41814_updates }}"
38+
register: _cve_2023_41814_rpm_installs
39+
40+
- name: Reload systemd units
41+
command: systemctl daemon-reload
42+
when: _cve_2023_41814_rpm_installs.changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- include_tasks: validate.yml
2+
- include_tasks: pre-upgrade.yml
3+
- include_tasks: install-rpms.yml
4+
- include_tasks: post-upgrade.yml
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
- name: Start slurmdbd
2+
systemd:
3+
name: slurmdbd
4+
state: started
5+
# NB: this approach is only suitable for minor version upgrades
6+
# major ones may timeout on service start due to db upgrades
7+
when: openhpc_enable.database | default('false') | bool
8+
9+
- name: Start slurmctld
10+
systemd:
11+
name: slurmctld
12+
state: started
13+
when: openhpc_enable.control | default('false') | bool
14+
15+
- name: Start slurmd
16+
systemd:
17+
name: slurmd
18+
state: started
19+
when: openhpc_enable.batch | default('false') | bool or 'login' in group_names
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
- name: Stop slurmd
2+
systemd:
3+
name: slurmd
4+
state: stopped
5+
when: openhpc_enable.batch | default('false') | bool or 'login' in group_names
6+
7+
- name: Stop slurmctld
8+
systemd:
9+
name: slurmctld
10+
state: stopped
11+
when: openhpc_enable.control | default('false') | bool
12+
13+
- name: Stop slurmdbd
14+
systemd:
15+
name: slurmdbd
16+
state: stopped
17+
when: openhpc_enable.database | default('false') | bool
18+
19+
- name: Ensure backup directory exists
20+
file:
21+
path: "{{ cve_2023_41914_mysql_backup_path | dirname }}"
22+
state: directory
23+
owner: root
24+
group: root
25+
when: openhpc_enable.control | default(false) | bool
26+
27+
- name: Ensure mysqldump tool installed
28+
dnf:
29+
name: mysql
30+
when: openhpc_enable.control | default(false) | bool
31+
32+
- name: Backup database
33+
community.mysql.mysql_db:
34+
name: slurm_acct_db
35+
state: dump
36+
target: "{{ cve_2023_41914_mysql_backup_path }}"
37+
login_user: root
38+
login_password: "{{ mysql_root_password }}"
39+
login_host: "{{ mysql_host }}"
40+
when: openhpc_enable.control | default(false) | bool
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
- name: Get package facts
2+
package_facts:
3+
4+
- name: Set fact for installed Slurm packages
5+
# this is a subset (same format) as ansible_facts.packages
6+
set_fact:
7+
_cve_2023_41814_installed_pkgs: "{{ ansible_facts.packages | dict2items | selectattr('key', 'match', 'slurm-') | items2dict }}"
8+
9+
- name: Ensure only a single version of all slurm-* packages is installed
10+
assert:
11+
that: item.value | length == 1
12+
loop: "{{ _cve_2023_41814_installed_pkgs | dict2items }}"
13+
14+
- name: Ensure major version of installed Slurm matches upgrade
15+
assert:
16+
that: _slurm_installed_major_ver == ['22', '05']
17+
fail_msg: "{{ item.key }} has major version {{ _slurm_installed_major_ver | join('.') }}, expecting 22.05"
18+
loop: "{{ _cve_2023_41814_installed_pkgs | dict2items }}"
19+
when: item.key.startswith('slurm')
20+
vars:
21+
_slurm_installed_major_ver: "{{ item.value[0].version.split('.')[0:2] }}"
22+

0 commit comments

Comments
 (0)