Commit Graph

2392 Commits

Author SHA1 Message Date
Joe Lawrence
c77352f03d Bump to version v0.9.10
Updates of interest:
    v0.9.10:
    - Support for Amazon Linux, Anolis OS, and OpenCloudOS distros
    - Fix cleanup when kpatch is installed in read-only location
    - Added RHEL-8.9, 9.3, 8.10, 9.4, and 9.5 integration tests
    - Added AL2023 integration tests
    - Support for __patchable_function_entries sections

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2025-01-20 15:41:25 -05:00
Joe Lawrence
b57508e694
Merge pull request #1428 from bhllamoreaux/photon-patches
Patches from Photon OS
2025-01-17 16:29:31 -05:00
Joe Lawrence
b15c09c1e5
Merge pull request #1433 from joe-lawrence/kmod-patch-hook
kmod: fix OOT kpatch kmod build
2025-01-17 16:29:04 -05:00
Joe Lawrence
a907d450a7 kmod: fix OOT kpatch kmod build
Starting from linux commit 13b25489b6f8 ("kbuild: change working
directory to external module directory with M="), the kpatch-build
fails:

  make -C /root/linux M=/root/.kpatch/tmp/patch CFLAGS_MODULE=''
  make[1]: Entering directory '/root/linux'
  make[2]: Entering directory '/root/.kpatch/tmp/patch'
    LDS     kpatch.lds
  make -C /root/linux M=/root/.kpatch/tmp/patch CFLAGS_MODULE='' patch-hook.o
  ***
  *** The external module source tree is not clean.
  *** Please run 'make -C /root/linux M=/root/linux clean'
  ***

The easiest and quickest way to fix the build is to remove the
$(KPATCH_MAKE) patch-hook.o in Makefile.  Unfortunately this would mean
make `patch-hook.o` cannot be performed directly.  However the Makefile
still lists patch-hook.o's source dependencies, so if any are updated,
the kpatch module would be rebuilt anyway.

Thanks for Sumanth Korikkar for reporting, debugging, and suggesting
this workaround.

Closes: #1430 ("kpatch-build fails: unable to locate patch-hook.o since linux commit 13b25489b6f8")
Reported-by: Sumanth Korikkar <sumanthk@linux.ibm.com>
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2025-01-16 16:23:29 -05:00
Joe Lawrence
9ba1ce88c6
Merge pull request #1431 from sumanthkorikkar/fix-non-compat-config
kpatch-syscall: Fix kpatch s390 error when CONFIG_COMPAT is disabled
2025-01-16 10:19:16 -05:00
Sumanth Korikkar
55c118c942 kpatch-syscall: Fix kpatch s390 build error when CONFIG_COMPAT is disabled
When CONFIG_COMPAT is disabled (No 31 bit emulation support), macro
__S390_SYS_STUBx() is nop.
(See arch/s390/include/asm/syscall_wrapper.h).
Also, __SC_COMPAT_CAST definition is not available, which leads to build
error.

Hence, __KPATCH_S390_SYS_STUBx() inherited from __S390_SYS_STUBx() macro,
should point also point to nop when CONFIG_COMPAT is disabled.

Signed-off-by: Sumanth Korikkar <sumanthk@linux.ibm.com>
2025-01-03 17:26:11 +01:00
Joe Lawrence
a9a7360a29
Merge pull request #1426 from joe-lawrence/s390x-rhel-9.6-syscall
Update s390x syscall wrappers for RHEL-9.6
2024-12-12 10:56:46 -05:00
Brennan Lamoreaux
846db25d80 use dynamic prefix offset instead of hardcoding
In commit [1], kpatch added support for function padding,
and CONFIG_CFI_CLANG, which hardcoded a value of 16 for
the prefix size.

In some cases, the padding around __cfi prefixed functions can
vary. For example, in Photon OS 5.0, the __cfi prefix
size is modified in a patch for the gcc RAP plugin [2].

Since we have read the prefix size anyways, we can use it
instead of hardcoding.

Ref:
1. 3e54c63b17
2. https://github.com/vmware/photon/blob/5.0/SPECS/linux/secure/gcc-rap-plugin-with-kcfi.patch

Signed-off-by: Brennan Lamoreaux <brennan.lamoreaux@broadcom.com>
2024-12-11 21:55:01 +00:00
Joe Lawrence
e42c7990ca kpatch-syscall: update for s390x RHEL-9.6 backports
RHEL-9.6 backported the upstream v6.3 s390x syscall updates, so add a
distro-specific kernel version check around the correct definitions.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2024-12-09 19:00:26 -05:00
Joe Lawrence
cbf2bc957c
Merge pull request #1415 from joe-lawrence/patchable_function_entries
create-diff-object: __patchable_function_entries section support
2024-12-04 10:00:13 -05:00
Joe Lawrence
7b6fee6f88 create-diff-object: Create __patchable_function_entries sections
The __mcount_loc section contains the addresses of patchable ftrace
sites which is used by the ftrace infrastructure in the kernel to create
a list of tracable functions and to know where to patch to enable
tracing of them.  On some kernel configurations, section is called
__patchable_function_entries and is generated by the compiler.  Either of
__mcount_loc or __patchable_function_entries is recognised by the kernel
but for these configurations, use __patchable_function_entries as it is
what is expected.

The x86_64 arch is special (of course).  Unlike other arches (ppc64le
and aarch64) a x86_64 kernel built with -fpatchable-function-entry will
generate nops AND create rela__patchable_function_entries for functions even
marked as notrace.  For this arch, always create __mount_loc sections and
rely on __fentry__ relocations to indicate ftrace call sites.

Note: this patch is a refactoring of original code by Pete Swain
<swine@google.com> for aarch64.  At the same time, this version squashes
several follow up commits from him and zimao <zimao@microsoft.com>.  The
intent is minimize the eventual changeset for aarch64 support now that
other arches are making use of __patchable_function_entries sections.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2024-12-03 09:26:10 -05:00
Joe Lawrence
8cb842086a
Merge pull request #1422 from ryanbsull/integration-tests-rhel-9.5-final
Integration tests rhel-9.5 final
2024-11-06 09:37:48 -05:00
Joe Lawrence
891c6b0362
Merge pull request #1421 from puranjaymohan/amzn2023-tests
test/integration/amzn-2023: Add integration tests for AL2023
2024-11-04 15:58:29 -05:00
Ryan Sullivan
5dcc40b064 test/integration/rhel-9.5: add tests for kernel-5.14.0-503.11.1.el9_5
Signed-off-by: Ryan Sullivan <rysulliv@redhat.com>
2024-10-31 14:43:22 -04:00
Puranjay Mohan
90ab713a78 test/integration/amzn-2023: Add integration tests for AL2023
This commit adds tests for Amazon Linux 2023. All patches apply and
integration tests pass.

Signed-off-by: Puranjay Mohan <pjy@amazon.com>
2024-10-28 13:49:53 +00:00
Joe Lawrence
17b795bcbb
Merge pull request #1420 from georgejguo/master
kpatch-build/Makefile: remove duplicate entry for create-kpatch-module.c
2024-10-23 12:44:10 -04:00
George Guo
b5d955cf4c kpatch-build/Makefile: remove duplicate entry for create-kpatch-module.c
create-kpatch-module.c is duplicated in kpatch-build/Makefile.

Signed-off-by: George Guo <guodongtai@kylinos.cn>
2024-10-17 18:28:40 +08:00
Joe Lawrence
5787dcd8f2
Merge pull request #1418 from joe-lawrence/shellcheck-oct-2024
tree: fix latest shellcheck complaints
2024-10-10 17:33:06 -04:00
Joe Lawrence
3dd3e58848
Merge pull request #1417 from joe-lawrence/gnu11
kpatch-build: set C language standard to gnu11
2024-10-10 17:32:52 -04:00
Joe Lawrence
34102d0058
Merge pull request #1407 from wardenjohn/add_version_show
kpatch-build: introduce version print option
2024-10-10 17:32:32 -04:00
Joe Lawrence
285560fa80 kpatch-build: set C language standard to gnu11
Add -std=gnu11 to CFLAGS for kpatch-build tooling.  This aligns with the
kernel build and avoids confusion when older tooling may default to
earlier versions.

Closes: #1416 ("C99 code vs. gcc defaults?")
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2024-10-10 15:16:53 -04:00
Joe Lawrence
c799fde067 tree: fix latest shellcheck complaints
Fix the following:

  In kpatch/kpatch line 358:
                                  break
                                  ^-- SC2317 (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly).

  In kpatch-build/kpatch-build line 1424:
                  "$TOOLSDIR"/create-diff-object $CDO_FLAGS "orig/$i" "patched/$i" "$KOBJFILE_NAME" \
                                                 ^--------^ SC2086 (info): Double quote to prevent globbing and word splitting.

  In kpatch-build/kpatch-build line 1494:
      MAKEVARS[$idx]=${MAKEVARS[$idx]/${KPATCH_CC_PREFIX}/}
               ^--^ SC2004 (style): $/${} is unnecessary on arithmetic variables.

  In kpatch-build/kpatch-build line 1510:
          "$TOOLSDIR"/create-klp-module $extra_flags "$TEMPDIR/patch/tmp.ko" "$TEMPDIR/patch/$MODNAME.ko" 2>&1 | logger 1
                                        ^----------^ SC2086 (info): Double quote to prevent globbing and word splitting.

  In test/integration/lib.sh line 119:
                  tdnf install -y linux-$flavor-debuginfo
                                        ^-----^ SC2086 (info): Double quote to prevent globbing and word splitting.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>

squash
2024-10-10 14:34:41 -04:00
Joe Lawrence
2f6a812a5f
Merge pull request #1413 from jpoimboe/no-irce
readme: remove IRC references
2024-09-05 10:52:23 -04:00
Josh Poimboeuf
eef32ad5f2
Merge pull request #1411 from joe-lawrence/fail-on-kernel-ibt
kpatch-build: fail CONFIG_X86_KERNEL_IBT as not supported
2024-09-03 18:21:22 -05:00
Josh Poimboeuf
f35f27cd98 readme: remove IRC references
We no longer hang out on IRC.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2024-09-03 15:43:14 -07:00
Josh Poimboeuf
f85f8a3299
Merge pull request #1412 from ohnatiuk1/man-remove-file-timestamp
man: fix reproducibility - remove file timestamps
2024-09-03 17:39:32 -05:00
Oleksandr Hnatiuk
531d8f1715 man: fix reproducibility - remove file timestamps
Man pages for kpatch are created via gzip which includes timestamp of original
file by default. This means the compressed file will change depending on the
time at which the repository was cloned / updated, leading to non-deterministic
builds. Pass option to disable this.

Signed-off-by: Oleksandr Hnatiuk <ohnatiuk@cisco.com>
2024-08-27 12:35:20 -07:00
Joe Lawrence
6de56acc29 kpatch-build: fail CONFIG_X86_KERNEL_IBT as not supported
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2024-08-26 14:22:28 -04:00
Joe Lawrence
269a061df6
Merge pull request #1403 from blitz/nixos-fixes
NixOS Fixes
2024-08-21 15:20:59 -04:00
Joe Lawrence
ec726afeab
Merge pull request #1406 from georgejguo/master
patch-author-guide: correct the example CVE ID information
2024-08-21 15:20:43 -04:00
Yongde Zhang
8cdf5678ac kpatch-build: introduce version print option
Introduce an option to print the version of kpatch-build.
2024-08-01 23:24:02 +08:00
George Guo
431e0b22a8 patch-author-guide: correct the example CVE ID information
The official website says CVE users should reference
CVE-2016-5696 instead of CVE-2016-5389.

Signed-off-by: George Guo <guodongtai@kylinos.cn>
2024-08-01 09:40:21 +08:00
Julian Stecklina
828b557b50 Fix cleanup when kpatch is installed in read-only location
On NixOS files are installed with mode 444 (read-only). This causes
directories in $TEMPDIR to be read-only as well, because they are
created by:

cp -LR "$DATADIR/patch" "$TEMPDIR" || die

which preserves the mode of the directory. We could do
--no-preserve=mode, but this will make people with non-coreutils cp
unhappy. Instead just chmod the files after copying.

If this patch is not applied, cleanup complains like this:

rm: cannot remove '/home/julian/.kpatch/tmp/patch/kpatch.h': Permission denied
rm: cannot remove '/home/julian/.kpatch/tmp/patch/Makefile': Permission denied
rm: cannot remove '/home/julian/.kpatch/tmp/patch/kpatch-macros.h': Permission denied
...

Signed-off-by: Julian Stecklina <julian.stecklina@cyberus-technology.de>
2024-07-29 14:07:31 +02:00
Joe Lawrence
6115a1a4e7
Merge pull request #1397 from joe-lawrence/small-upstream-kernel-fixes
Small upstream kernel fixes
2024-07-18 13:59:29 -04:00
Joe Lawrence
f1ce4791d2
Merge pull request #1400 from sumanthkorikkar/add-fpic-flag-s390
s390/kpatch-build: add -fPIC flag with -mno-pic-data-is-text-relative
2024-07-16 09:37:54 -04:00
Sumanth Korikkar
5695dce6de s390/kpatch-build: add -fPIE flag with -mno-pic-data-is-text-relative
-mno-pic-data-is-text-relative compiler flag expects -fPIC/-fPIE flag
along with it.  Since kernel commit 778666df60f0 ("s390: compile
relocatable kernel without -fPIE"), the -fPIC/-fPIE flag is missing when
creating kpatch module and this can lead to the following error:

cc1: error: ‘-mno-pic-data-is-text-relative’ cannot be used without
‘-fpic’/‘-fPIC’.

Previously kpatch-build didnt show up this issue, as the previous kernel
was built with -fPIE.

However, kpatch build could fail with kernel commit 778666df60f0 ("s390:
compile relocatable kernel without -fPIE"), where -fPIE is not included.
Hence, include it in kpatch-build for all kernels < 6.10.0

Note:
Latest s390 kernel is built with -fPIC flag.
i.e. kernel commit 00cda11d3b2e ("s390: Compile kernel with -fPIC and
link with -no-pie"). Hence, there is no need to explicitly add it again
in kpatch-build.

Signed-off-by: Sumanth Korikkar <sumanthk@linux.ibm.com>
2024-06-24 14:28:33 +02:00
Joe Lawrence
7d89578c6f kpatch-build: suppress make directory info for make kernelversion
When invoking kpatch-build through integration testing, like:

  $ make PATCH_DIR="linux-6.9.0" \
         KPATCH_BUILD_OPTS="--sourcedir /root/linux" \
         integration-slow

results in an error as kpatch-build's `make kernelversion` adds
directory information to its output:

  make[2]: Entering directory '/root/linux'
  6.9.0
  make[2]: Leaving directory '/root/linux'

This screws up kpatch-build's assignment of the make output to
LOCALVERSION, which was expecting only "6.9.0".

Add --no-print-directory to the make invocation to avoid the undesired
entering / leaving directory info.

Fixes: 629b5acf3d ("kpatch-build: Fix setlocalversion issue with 6.3 kernel")
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2024-06-07 11:12:51 -04:00
Joe Lawrence
77d9346383 kpatch-build: fix setlocalversion for pre-v6.3 kernels
Commit 629b5acf3d ("kpatch-build: Fix setlocalversion issue with 6.3
kernel") fixed VERMAGIC_STRING between kpatch original/patched kernel
builds by creating a temporary scripts/setlocalversion script.	This was
accomplished by saving the output from `make kernelversion` into a
KERNELVERSION environment variable and running the (original)
scripts/setlocalversion to gather a "vX.Y" + "<src version>" pair of
strings.

Unfortunately pre-v6.3 scripts/setlocalversion does not use the
KERNELVERSION environment variable, so the same efforts results in an
unusable "<NULL>" + "<src version>" version string pair.

Restore the original `scripts/setlocalversion --save-scmversion`
invocation for source trees that (still) support the --save-scmversion
option.

Fixes: 629b5acf3d ("kpatch-build: Fix setlocalversion issue with 6.3 kernel")
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2024-06-07 10:22:03 -04:00
Joe Lawrence
711ee6d322 kpatch-build: fix USERSRCDIR builds
Commit 69e71f8dcc ("kpatch-build: cleanup kernel file backup/restore")
consolidated a bunch of kernel-tree copy and restoring.  As part of that
effort, when kpatch-build is invoked with a -s|--sourcedir USERSRCDIR
value the vmlinux file is now saved to "$TEMPDIR/kernel-backup/" and not
simply "$TEMPDIR/".  This results in kpatch-build confusion like:

  readelf: /home/jolawren/.kpatch/tmp/vmlinux: Error: No such file

Update the VMLINUX reassignment in this case to point to the new path.

Fixes: 69e71f8dcc ("kpatch-build: cleanup kernel file backup/restore")
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2024-06-07 10:21:42 -04:00
Joe Lawrence
63cc79c225 kpatch-build: fix DISTRO check when specifying USERSRCDIR
When kpatch-build is invoked with a -s|--sourcedir USERSRCDIR value,
kpatch-build doesn't source the /etc/os-release file as it can't assume
that the user-specified kernel source config matches any particular
distribution.  Subsequent is_supported_{rpm,deb}_distro() function calls
will result in ugly syntax errors like:

  kpatch-build: line 697: SUPPORTED_RPM_DISTROS: bad array subscript
  kpatch-build: line 692: SUPPORTED_DEB_DISTROS: bad array subscript

Enhance the is_supported_{rpm,deb}_distro() functions to check that a
non-NULL distribution string argument exists before indexing the
SUPPORTED_{RPM,DEB}_DISTROS associative arrays.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2024-06-07 10:21:39 -04:00
Joe Lawrence
6457c4ccf9
Merge pull request #1396 from mihails-strasuns/al-id
Recognize Amazon Linux ID in kpatch-build
2024-06-06 10:23:22 -04:00
Puranjay Mohan
90a92f9492 Recognize Amazon Linux ID in kpatch-build
Make kpatch-build aware about the ID of Amazon Linux distributions. No
other special changes are needed.

Signed-off-by: Puranjay Mohan <pjy@amazon.com>
2024-06-05 12:08:36 +00:00
Joe Lawrence
09e153d3c9
Merge pull request #1394 from ZzzMao/rpm-spec
Fix formatting issue and date errors in spec file
2024-05-14 22:21:15 -04:00
Joe Lawrence
bb93ac9c65
Merge pull request #1393 from joe-lawrence/ld-orphan-error
Fix builds with CONFIG_ERROR
2024-05-14 22:20:58 -04:00
Joe Lawrence
b75d4c4449
Merge pull request #1392 from ryanbsull/x86-paravirt-fix
kpatch-build: handle paravirt absence in Linux v6.8+
2024-05-14 22:20:46 -04:00
Ziwei Mao
7e5eddc105 Update spec file
Fix formatting issue and date error
2024-05-10 17:27:55 +00:00
Joe Lawrence
69e71f8dcc kpatch-build: cleanup kernel file backup/restore
Temporarily editing kernel tree sources has become a recurring
requirement in kpatch-build.  Pull the saving/restoring of these files
into a common function helpers to standardize the pattern.

Reported-and-tested-by: Zhijun Wang <zhijwang@redhat.com>
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2024-05-07 15:38:27 -04:00
Joe Lawrence
56dfdbeb5b kpatch-build: demote CONFIG_LD_ORPHAN_WARN_LEVEL
Upstream kernel v6.1+ commit linux@e1789d7c752e ("kbuild: upgrade the
orphan section warning to an error if CONFIG_WERROR is set") and
CONFIG_WERROR will result in failed kernel builds due to the linker
reporting tons of "unplaced orphan section `.text.<function>`
<object-file.o>" errors.

Workaround this by temporarily demoting such errors in the top-level
kernel Makefile.

Reported-and-tested-by: Zhijun Wang <zhijwang@redhat.com>
Closes: #1391 ("CONFIG_WERROR=y and CONFIG_LD_ORPHAN_WARN_LEVEL="error" break kpatch-build")
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2024-05-07 15:34:03 -04:00
Ryan Sullivan
36ba2b8dfc kpatch-build: handle paravirt absence in Linux v6.8+
Upstream kernel commit f7af6977621a ("x86/paravirt: Remove no longer
needed paravirt patching code") v6.8+ removed the .parainstructions
section and its paravirt_patch_site struct. Therefore this checks the
kernel version and does not export the struct size if the kernel
version is >= v6.8.0, avoiding the code path for it in
create-diff-object.c entirely.

Fixes: https://github.com/dynup/kpatch/issues/1380

Signed-off-by: Ryan Sullivan <rysulliv@redhat.com>
2024-05-03 16:06:23 -04:00
Joe Lawrence
ef68b4e416
Merge pull request #1383 from joe-lawrence/integration-dmesg-again
kpatch-test: add dmesg entry at start of test
2024-04-23 16:17:37 -04:00