Compare
4db45fc1da3d62d0fa6e8f1e457ae92e8741ed07..4505a262deae7df06e33617dfc104d5541eec91d
x86/kcfi: Decode the kCFI check from the trap address
Since commit b2250d63e6422 ("x86/kcfi: Optimize call sequence"), a
CONFIG_FINEIBT=y kernel running in kCFI mode rewrites each kCFI call
site at boot so that a failed check traps on the 0xd6 byte of
"test $0xd6, %al", one byte past where the compiler's "ud2" was.
handle_cfi_failure() steps "addr" back one byte to find the trap in
.kcfi_traps, but decode_cfi_insn() still decodes from regs->ip, so it
reads each instruction starting at its second byte.
"movl $-<id>, %r10d" then decodes as "movl $-<id>, %edx", so the
reported type is right by accident, but "addl -15(%r11), %r10d" decodes
as "addl -15(%rbx), %edx", so the reported target is whatever %rbx holds:
CFI failure at lkdtm_indirect_call+0x16/0x20 (target: 0x12; expected type: 0xc79a2d1b)
Pass the adjusted address to decode_cfi_insn() and decode from it.
Tested ARCH=x86_64 defconfig with CONFIG_CFI=y and CONFIG_LKDTM=y under
QEMU, with LKDTM's CFI_FORWARD_PROTO and both Clang 24.0.0git and GCC
17.0.0 (experimental, with the kCFI series). With CONFIG_FINEIBT=y in
kCFI mode, the report gives %rbx as the target without this change, and
the expected lkdtm_increment_int() with it. With cfi=fineibt, with
cfi=fineibt,paranoid, and with CONFIG_FINEIBT=n, it gives
lkdtm_increment_int() both with and without this change.
Fixes: b2250d63e6422 ("x86/kcfi: Optimize call sequence")
Assisted-by: LLM
Signed-off-by: Kees Cook <kees@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://patch.msgid.link/20261012090436.1676525-1-kees@kernel.org
Kees Cook <kees@kernel.org> · 2026-10-12 09:04 UTC · committed by Peter Zijlstra
7 files changed,
+15
−15
- arch/x86/kernel/cfi.c
- sound/soc/codecs/cs42l52.c
- sound/soc/codecs/cs42l56.c
- sound/soc/codecs/max98371.c
- sound/soc/codecs/nau8822.c
- sound/soc/codecs/pcm3168a.c
- sound/soc/codecs/wm8978.c
modified arch/x86/kernel/cfi.c
| @@ -10,11 +10,11 @@ | |||
| 10 | 10 | #include <asm/insn-eval.h> | |
| 11 | 11 | ||
| 12 | 12 | /* | |
| 13 | - | * Returns the target address and the expected type when regs->ip points | |
| 13 | + | * Returns the target address and the expected type when addr points | |
| 14 | 14 | * to a compiler-generated CFI trap. | |
| 15 | 15 | */ | |
| 16 | - | static bool decode_cfi_insn(struct pt_regs *regs, unsigned long *target, | |
| 17 | - | u32 *type) | |
| 16 | + | static bool decode_cfi_insn(struct pt_regs *regs, unsigned long addr, | |
| 17 | + | unsigned long *target, u32 *type) | |
| 18 | 18 | { | |
| 19 | 19 | char buffer[MAX_INSN_SIZE]; | |
| 20 | 20 | struct insn insn; | |
| @@ -29,13 +29,13 @@ static bool decode_cfi_insn(struct pt_regs *regs, unsigned long *target, | |||
| 29 | 29 | * movl -<id>, %r10d ; 6 bytes | |
| 30 | 30 | * addl -<pos>(%reg), %r10d; 4 bytes | |
| 31 | 31 | * je .Ltmp1 ; 2 bytes | |
| 32 | - | * ud2 ; <- regs->ip | |
| 32 | + | * ud2 ; <- addr | |
| 33 | 33 | * .Ltmp1: | |
| 34 | 34 | * | |
| 35 | 35 | * We can decode the expected type and the target address from the | |
| 36 | 36 | * movl/addl instructions. | |
| 37 | 37 | */ | |
| 38 | - | if (copy_from_kernel_nofault(buffer, (void *)regs->ip - 12, MAX_INSN_SIZE)) | |
| 38 | + | if (copy_from_kernel_nofault(buffer, (void *)addr - 12, MAX_INSN_SIZE)) | |
| 39 | 39 | return false; | |
| 40 | 40 | if (insn_decode_kernel(&insn, &buffer[offset])) | |
| 41 | 41 | return false; | |
| @@ -44,7 +44,7 @@ static bool decode_cfi_insn(struct pt_regs *regs, unsigned long *target, | |||
| 44 | 44 | ||
| 45 | 45 | *type = -(u32)insn.immediate.value; | |
| 46 | 46 | ||
| 47 | - | if (copy_from_kernel_nofault(buffer, (void *)regs->ip - 6, MAX_INSN_SIZE)) | |
| 47 | + | if (copy_from_kernel_nofault(buffer, (void *)addr - 6, MAX_INSN_SIZE)) | |
| 48 | 48 | return false; | |
| 49 | 49 | if (insn_decode_kernel(&insn, &buffer[offset])) | |
| 50 | 50 | return false; | |
| @@ -82,7 +82,7 @@ enum bug_trap_type handle_cfi_failure(struct pt_regs *regs) | |||
| 82 | 82 | return BUG_TRAP_TYPE_NONE; | |
| 83 | 83 | } | |
| 84 | 84 | ||
| 85 | - | if (!decode_cfi_insn(regs, &target, &type)) | |
| 85 | + | if (!decode_cfi_insn(regs, addr, &target, &type)) | |
| 86 | 86 | return report_cfi_failure_noaddr(regs, addr); | |
| 87 | 87 | ||
| 88 | 88 | break; | |
modified sound/soc/codecs/cs42l52.c
| @@ -290,7 +290,7 @@ static const char * const cs42l52_ng_type_text[] = { | |||
| 290 | 290 | }; | |
| 291 | 291 | ||
| 292 | 292 | static SOC_ENUM_SINGLE_DECL(ng_type_enum, | |
| 293 | - | CS42L52_NOISE_GATE_CTL, 7, | |
| 293 | + | CS42L52_NOISE_GATE_CTL, 6, | |
| 294 | 294 | cs42l52_ng_type_text); | |
| 295 | 295 | ||
| 296 | 296 | static const char * const left_swap_text[] = { | |
modified sound/soc/codecs/cs42l56.c
| @@ -481,7 +481,7 @@ static const struct snd_kcontrol_new cs42l56_snd_controls[] = { | |||
| 481 | 481 | 0, 0x3f, 0, 0), | |
| 482 | 482 | SOC_SINGLE_TLV("Limiter MAX", CS42L56_LIM_THRESHOLD_CTL, | |
| 483 | 483 | 5, 0x07, 1, alc_tlv), | |
| 484 | - | SOC_SINGLE_TLV("Limiter Cushion", CS42L56_LIM_THRESHOLD_CTL, | |
| 484 | + | SOC_SINGLE_TLV("Limiter Cushion", CS42L56_ALC_THRESHOLD, | |
| 485 | 485 | 2, 0x07, 1, alc_tlv), | |
| 486 | 486 | ||
| 487 | 487 | SOC_SINGLE("NG Switch", CS42L56_NOISE_GATE_CTL, 6, 1, 1), | |
modified sound/soc/codecs/max98371.c
| @@ -166,7 +166,7 @@ static const struct snd_kcontrol_new max98371_snd_controls[] = { | |||
| 166 | 166 | 0, (1<<MAX98371_DHT_MAX_WIDTH)-1, 0, | |
| 167 | 167 | max98371_dht_max_gain), | |
| 168 | 168 | SOC_SINGLE_TLV("Speaker DHT Min Volume", MAX98371_DHT_GAIN, | |
| 169 | - | 4, (1<<MAX98371_DHT_GAIN_WIDTH)-1, 0, | |
| 169 | + | 0, (1<<MAX98371_DHT_GAIN_WIDTH)-1, 0, | |
| 170 | 170 | max98371_dht_min_gain), | |
| 171 | 171 | SOC_SINGLE_TLV("Speaker DHT Rotation Volume", MAX98371_DHT_GAIN, | |
| 172 | 172 | 0, (1<<MAX98371_DHT_ROT_WIDTH)-1, 0, | |
modified sound/soc/codecs/nau8822.c
| @@ -383,9 +383,9 @@ static const struct snd_kcontrol_new nau8822_snd_controls[] = { | |||
| 383 | 383 | NAU8822_REG_RIGHT_ADC_BOOST_CONTROL, 0, 7, 0, boost_tlv), | |
| 384 | 384 | ||
| 385 | 385 | SOC_SINGLE("DAC 128x Oversampling Switch", | |
| 386 | - | NAU8822_REG_DAC_CONTROL, 3, 1, 0), | |
| 386 | + | NAU8822_REG_DAC_CONTROL, 5, 1, 0), | |
| 387 | 387 | SOC_SINGLE("ADC 128x Oversampling Switch", | |
| 388 | - | NAU8822_REG_ADC_CONTROL, 3, 1, 0), | |
| 388 | + | NAU8822_REG_ADC_CONTROL, 5, 1, 0), | |
| 389 | 389 | }; | |
| 390 | 390 | ||
| 391 | 391 | /* LMAIN and RMAIN Mixer */ | |
modified sound/soc/codecs/pcm3168a.c
| @@ -103,7 +103,7 @@ static SOC_ENUM_SINGLE_DECL(pcm3168a_dac_zf_func, PCM3168A_DAC_ATT_DEMP_ZF, | |||
| 103 | 103 | static const char *const pcm3168a_pol[] = { "Active High", "Active Low" }; | |
| 104 | 104 | ||
| 105 | 105 | static SOC_ENUM_SINGLE_DECL(pcm3168a_dac_zf_pol, PCM3168A_DAC_ATT_DEMP_ZF, | |
| 106 | - | PCM3168A_DAC_ZREV_SHIFT, pcm3168a_pol); | |
| 106 | + | PCM3168A_DAC_ATSPDA_SHIFT, pcm3168a_pol); | |
| 107 | 107 | ||
| 108 | 108 | static const char *const pcm3168a_con[] = { "Differential", "Single-Ended" }; | |
| 109 | 109 | ||
modified sound/soc/codecs/wm8978.c
| @@ -255,9 +255,9 @@ static const struct snd_kcontrol_new wm8978_snd_controls[] = { | |||
| 255 | 255 | ||
| 256 | 256 | /* DAC / ADC oversampling */ | |
| 257 | 257 | SOC_SINGLE("DAC 128x Oversampling Switch", WM8978_DAC_CONTROL, | |
| 258 | - | 3, 1, 0), | |
| 258 | + | 5, 1, 0), | |
| 259 | 259 | SOC_SINGLE("ADC 128x Oversampling Switch", WM8978_ADC_CONTROL, | |
| 260 | - | 3, 1, 0), | |
| 260 | + | 5, 1, 0), | |
| 261 | 261 | }; | |
| 262 | 262 | ||
| 263 | 263 | /* Mixer #1: Output (OUT1, OUT2) Mixer: mix AUX, Input mixer output and DAC */ | |