Blob Blame History Raw
# Set to 1 if building an empty subscription-only package.
%define empty_package		0

#######################################################
# Only need to update these variables and the changelog
%define kernel_ver	3.10.0-1160.25.1.el7
%define kpatch_ver	0.9.2
%define rpm_ver		1
%define rpm_rel		8

%if !%{empty_package}
# Patch sources below. DO NOT REMOVE THIS LINE.
#
# https://bugzilla.redhat.com/1935112
Source100: CVE-2021-3347.patch
#
# https://bugzilla.redhat.com/1962518
Source101: CVE-2021-33034.patch
#
# https://bugzilla.redhat.com/1975256
Source102: CVE-2021-33909.patch
#
# https://bugzilla.redhat.com/1971474
Source103: CVE-2021-32399.patch
#
# https://bugzilla.redhat.com/1980516
Source104: CVE-2021-22555.patch
#
# https://bugzilla.redhat.com/1997195
Source105: CVE-2021-3715.patch
#
# https://bugzilla.redhat.com/1975766
Source106: CVE-2021-22543.patch
#
# https://bugzilla.redhat.com/1988221
Source107: CVE-2021-37576.patch
#
# https://bugzilla.redhat.com/1981703
Source108: CVE-2020-36385.patch
#
# https://bugzilla.redhat.com/2034878
Source109: CVE-2021-4155.patch
#
# https://bugzilla.redhat.com/2031986
Source110: CVE-2021-0920.patch
#
# https://bugzilla.redhat.com/2042766
Source111: CVE-2020-0466.patch
#
# https://bugzilla.redhat.com/2044373
Source112: CVE-2022-0330.patch
#
# https://bugzilla.redhat.com/2047616
Source113: CVE-2022-22942.patch
#
# https://bugzilla.redhat.com/2033360
Source114: CVE-2021-4028.patch
#
# https://bugzilla.redhat.com/2032491
Source115: CVE-2021-4083.patch
# End of patch sources. DO NOT REMOVE THIS LINE.
%endif

%define sanitized_rpm_rel	%{lua: print((string.gsub(rpm.expand("%rpm_rel"), "%.", "_")))}
%define sanitized_kernel_ver	%{lua: print((string.gsub(string.gsub(rpm.expand("%kernel_ver"), ".el7", ""), "%.", "_")))}
%define kernel_ver_arch	%{kernel_ver}.%{_arch}

Name:		kpatch-patch-%{sanitized_kernel_ver}
Version:	%{rpm_ver}
Release:	%{rpm_rel}.el7

%if %{empty_package}
Summary:	Initial empty kpatch-patch for kernel-%{kernel_ver_arch}
%else
Summary:	Live kernel patching module for kernel-%{kernel_ver_arch}
%endif

Group:		System Environment/Kernel
License:	GPLv2
ExclusiveArch:	x86_64 ppc64le

Conflicts:	%{name} < %{version}-%{release}

Provides:	kpatch-patch = %{kernel_ver_arch}
Provides:	kpatch-patch = %{kernel_ver}

%if !%{empty_package}
Requires:	systemd
%endif
Requires:	kpatch >= 0.4.0-3
Requires:	kernel-uname-r = %{kernel_ver_arch}

%if !%{empty_package}
BuildRequires:	gcc elfutils-devel rpmdevtools asciidoc bc hmaccalc m4 net-tools xmlto zlib-devel binutils-devel newt-devel python-devel perl(ExtUtils::Embed) bison audit-libs-devel numactl-devel pciutils-devel openssl gettext kernel-devel ncurses-devel hostname java-devel python-docutils
BuildRequires:	kernel-devel = %{kernel_ver}
BuildRequires:	kernel-debuginfo = %{kernel_ver}

%ifarch x86_64
BuildRequires: pesign
%endif

%ifarch ppc64le
BuildRequires: gcc-plugin-devel
%endif

Source0:	https://github.com/dynup/kpatch/archive/v%{kpatch_ver}.tar.gz

Source10:	kernel-%{kernel_ver}.src.rpm

# kpatch-build patches
# Patch1: backport.patch

%global _dupsign_opts --keyname=rhelkpatch1

%define builddir	%{_builddir}/kpatch-%{kpatch_ver}
%define kpatch		%{_sbindir}/kpatch
%define kmoddir		%{_usr}/lib/kpatch/%{kernel_ver_arch}
%define patchmodname	kpatch-%{sanitized_kernel_ver}-%{version}-%{sanitized_rpm_rel}
%define patchmod	%{patchmodname}.ko

%define _missing_build_ids_terminate_build 1
%define _find_debuginfo_opts -r
%undefine _include_minidebuginfo
%undefine _find_debuginfo_dwz_opts

%description
This is a kernel live patch module which can be loaded by the kpatch
command line utility to modify the code of a running kernel.  This patch
module is targeted for kernel-%{kernel_ver}.

%prep
%autosetup -n kpatch-%{kpatch_ver} -p1

%build
kdevdir=/usr/src/kernels/%{kernel_ver_arch}
vmlinux=/usr/lib/debug/lib/modules/%{kernel_ver_arch}/vmlinux

# kpatch-build
make -C kpatch-build

# patch module
for i in %{sources}; do
	[[ $i == *.patch ]] && patch_sources="$patch_sources $i"
done
export CACHEDIR="%{builddir}/.kpatch"
kpatch-build/kpatch-build -n %{patchmodname} -r %{SOURCE10} -v $vmlinux --skip-cleanup $patch_sources || { cat "${CACHEDIR}/build.log"; exit 1; }


%install
installdir=%{buildroot}/%{kmoddir}
install -d $installdir
install -m 755 %{builddir}/%{patchmod} $installdir


%files
%{_usr}/lib/kpatch


%post
if [[ %{kernel_ver_arch} = $(uname -r) ]]; then
	cver="%{rpm_ver}_%{rpm_rel}"
	pname=$(echo "kpatch_%{sanitized_kernel_ver}" | sed 's/-/_/')

	lver=$({ %{kpatch} list | sed -nr "s/^${pname}_([0-9_]+)\ \[enabled\]$/\1/p"; echo "${cver}"; } | sort -V | tail -1)

	if [ "${lver}" != "${cver}" ]; then
		echo "WARNING: at least one loaded kpatch-patch (${pname}_${lver}) has a newer version than the one being installed."
		echo "WARNING: You will have to reboot to load a downgraded kpatch-patch"
	else
		%{kpatch} load %{kmoddir}/%{patchmod}
	fi
fi
%{kpatch} install -k %{kernel_ver_arch} %{kmoddir}/%{patchmod}
sync
exit 0


%postun
%{kpatch} uninstall -k %{kernel_ver_arch} %{patchmod}
sync
exit 0

%else
%description
This is an empty kpatch-patch package which does not contain any real patches.
It is only a method to subscribe to the kpatch stream for kernel-%{kernel_ver}.

%files
%doc
%endif

%changelog
* Thu Mar 24 2022 Joe Lawrence <joe.lawrence@redhat.com> [1-8.el7]
- kernel: fget: check that the fd still exists after getting a ref to it [2032491] {CVE-2021-4083}
- kernel: use-after-free in RDMA listen() [2033360] {CVE-2021-4028}

* Fri Feb 11 2022 Joe Lawrence <joe.lawrence@redhat.com> [1-7.el7]
- kernel: failing usercopy allows for use-after-free exploitation [2047616] {CVE-2022-22942}
- kernel: possible privileges escalation due to missing TLB flush [2044373] {CVE-2022-0330}
- kernel: use after free in eventpoll.c may lead to escalation of privilege [2042766] {CVE-2020-0466}
- kernel: Use After Free in unix_gc() which could result in a local privilege escalation [2031986] {CVE-2021-0920}
- kernel: xfs: raw block device data leak in XFS_IOC_ALLOCSP IOCTL [2034878] {CVE-2021-4155}

* Fri Nov 12 2021 Joe Lawrence <joe.lawrence@redhat.com> [1-6.el7]
- kernel: use-after-free in drivers/infiniband/core/ucma.c ctx use-after-free [1981703] {CVE-2020-36385}

* Wed Sep 29 2021 Joe Lawrence <joe.lawrence@redhat.com> [1-5.el7]
- kernel: powerpc: KVM guest OS users can cause host OS memory corruption [1988221] {CVE-2021-37576}
- kernel: Improper handling of VM_IO|VM_PFNMAP vmas in KVM can bypass RO checks [1975766] {CVE-2021-22543}

* Tue Aug 31 2021 Joe Lawrence <joe.lawrence@redhat.com> [1-4.el7]
- kernel: use-after-free in route4_change() in net/sched/cls_route.c [1997195] {CVE-2021-3715}

* Mon Aug 16 2021 Joe Lawrence <joe.lawrence@redhat.com> [1-3.el7]
- kernel: out-of-bounds write in xt_compat_target_from_user() in net/netfilter/x_tables.c [1980516] {CVE-2021-22555}
- kpatch: kernel: race condition for removal of the HCI controller [1971474] {CVE-2021-32399}

* Fri Jul 09 2021 Joe Lawrence <joe.lawrence@redhat.com> [1-2.el7]
- kernel: size_t-to-int conversion vulnerability in the filesystem layer [1975256] {CVE-2021-33909}
- kernel: use-after-free in net/bluetooth/hci_event.c when destroying an hci_chan [1962518] {CVE-2021-33034}

* Fri May 21 2021 Artem Savkov <asavkov@redhat.com> [1-1.el7]
- Use after free via PI futex state [1935112] {CVE-2021-3347}

* Fri Apr 16 2021 Yannick Cote <ycote@redhat.com> [0-0.el7]
- An empty patch to subscribe to kpatch stream for kernel-3.10.0-1160.25.1.el7 [1950389]