0

I've tried to transform https://github.com/pq-crystals/kyber in a kernel module but I got a DOUBLEFAULT exception.

Here is my fork: https://github.com/fwag/kyber

Here the core dump and disassembly:

crash> bt
PID: 3230     TASK: ffff9069d0b90000  CPU: 0    COMMAND: "insmod"
 #0 [fffffe000000ad60] machine_kexec at ffffffff9768b0e0
 #1 [fffffe000000adc0] __crash_kexec at ffffffff97798772
 #2 [fffffe000000ae90] crash_kexec at ffffffff97799a5c
 #3 [fffffe000000aea0] oops_end at ffffffff97642aba
 #4 [fffffe000000aec8] die at ffffffff97642ce3
 #5 [fffffe000000aef8] exc_double_fault at ffffffff9836300b
 #6 [fffffe000000af50] asm_exc_double_fault at ffffffff98400c8f
    [exception RIP: indcpa_keypair+65]
    RIP: ffffffffc09f07b1  RSP: ffff9df1c3ce6a38  RFLAGS: 00010246
    RAX: 0000000000000000  RBX: ffff9df1c3cea320  RCX: 0000000000000000
    RDX: 0000000000000000  RSI: 0000000000000020  RDI: ffff9df1c3cea240
    RBP: ffff9df1c3cea2b0   R8: 0000000000000010   R9: ffff9069d19b97d0
    R10: 0000000000000000  R11: 0000000000000000  R12: 0000000000000000
    R13: ffff9df1c3ce7240  R14: 0000000000000000  R15: ffff9df1c3ceaf60
    ORIG_RAX: ffffffffffffffff  CS: 0010  SS: 0018
--- <DOUBLEFAULT exception stack> ---
 #7 [ffff9df1c3ce6a38] indcpa_keypair at ffffffffc09f07b1 [kkyber]
 #8 [ffff9df1c3cea2b8] crypto_kem_keypair at ffffffffc09f02f7 [kkyber]
 #9 [ffff9df1c3cea2d8] test_keys at ffffffffc09f3312 [kkyber]
#10 [ffff9df1c3cebbd0] my_init_module at ffffffffc09f33ce [kkyber]
#11 [ffff9df1c3cebbe0] do_one_initcall at ffffffff976039c8
#12 [ffff9df1c3cebc50] do_init_module at ffffffff97792ed2
#13 [ffff9df1c3cebc78] load_module at ffffffff977953dd
#14 [ffff9df1c3cebd98] __do_sys_finit_module at ffffffff9779593f
#15 [ffff9df1c3cebe70] __x64_sys_finit_module at ffffffff977959ba
#16 [ffff9df1c3cebe80] do_syscall_64 at ffffffff9836252c
#17 [ffff9df1c3cebec8] syscall_exit_to_user_mode at ffffffff98366c27
#18 [ffff9df1c3cebee0] do_syscall_64 at ffffffff98362539
#19 [ffff9df1c3cebf08] syscall_exit_to_user_mode at ffffffff98366c27
#20 [ffff9df1c3cebf20] do_syscall_64 at ffffffff98362539
#21 [ffff9df1c3cebf50] entry_SYSCALL_64_after_hwframe at ffffffff98400099
    RIP: 00007f13ab09d76d  RSP: 00007ffd869a7a18  RFLAGS: 00000246
    RAX: ffffffffffffffda  RBX: 000055752255b790  RCX: 00007f13ab09d76d
    RDX: 0000000000000000  RSI: 0000557521fcc358  RDI: 0000000000000003
    RBP: 0000000000000000   R8: 0000000000000000   R9: 00007f13ab174580
    R10: 0000000000000003  R11: 0000000000000246  R12: 0000557521fcc358
    R13: 0000000000000000  R14: 000055752255b760  R15: 0000000000000000
    ORIG_RAX: 0000000000000139  CS: 0033  SS: 002b
crash> dis indcpa_keypair
0xffffffffc09f0770 <indcpa_keypair>:    nopl   0x0(%rax,%rax,1) [FTRACE NOP]
0xffffffffc09f0775 <indcpa_keypair+5>:  push   %rbp
0xffffffffc09f0776 <indcpa_keypair+6>:  mov    %rsp,%rbp
0xffffffffc09f0779 <indcpa_keypair+9>:  push   %r15
0xffffffffc09f077b <indcpa_keypair+11>: mov    %rsi,%r15
0xffffffffc09f077e <indcpa_keypair+14>: mov    $0x20,%esi
0xffffffffc09f0783 <indcpa_keypair+19>: push   %r14
0xffffffffc09f0785 <indcpa_keypair+21>: push   %r13
0xffffffffc09f0787 <indcpa_keypair+23>: lea    -0x3070(%rbp),%r13
0xffffffffc09f078e <indcpa_keypair+30>: push   %r12
0xffffffffc09f0790 <indcpa_keypair+32>: xor    %r12d,%r12d
0xffffffffc09f0793 <indcpa_keypair+35>: push   %rbx
0xffffffffc09f0794 <indcpa_keypair+36>: mov    %rdi,%rbx
0xffffffffc09f0797 <indcpa_keypair+39>: lea    -0x70(%rbp),%rdi
0xffffffffc09f079b <indcpa_keypair+43>: sub    $0x3850,%rsp
0xffffffffc09f07a2 <indcpa_keypair+50>: mov    %gs:0x28,%rax
0xffffffffc09f07ab <indcpa_keypair+59>: mov    %rax,-0x30(%rbp)
0xffffffffc09f07af <indcpa_keypair+63>: xor    %eax,%eax
0xffffffffc09f07b1 <indcpa_keypair+65>: call   0xffffffffc09f32c0 <randombytes>

Futhermore, I've tried to comment out some lines of code but the issue still appears somewhere else.

Thanks in advance for your help

knip
  • 71
  • 5
  • 1
    Stack Overflow is not a debug-my-great-program service. We could help with particular problem, which is caused by a particular part of code, but that part of code should be in the question post. See [ask]. – Tsyvarev Mar 17 '23 at 00:12
  • See https://stackoverflow.com/q/46677676/5264491 – Ian Abbott Mar 17 '23 at 11:51
  • @Tsyvarev I wanted just to know how to debug it as a double fault is quite generic. I'm using the part of code under directory ref and it should not use AVX2. – knip Mar 17 '23 at 12:51
  • There is a little specifics in debugging a double fault. Since in your case the first fault occurred in the kernel space code, you should debug the first fault. As for debugging in *general*, there is no short receipt for it. – Tsyvarev Mar 17 '23 at 12:59
  • Hi @Tsyvarev, how can I debug in kernel space ? I've tried with gdb setting a breakpoint but it does not stop. – knip Mar 23 '23 at 16:15

0 Answers0