Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update several example code for newer kernel #70

Merged
merged 1 commit into from
Aug 23, 2021

Conversation

fennecJ
Copy link
Collaborator

@fennecJ fennecJ commented Aug 22, 2021

Known issues with current example code:
If you using newer kernel(e.g linux 5.11.x) to compile the example code,
you may meet following error:

  1. syscall.c:83:50: error: ‘ksys_close’ undeclared;
  2. cryptosk.c:17:24: error: field ‘sg’ has incomplete type
  3. cryptosk.c:143:9: error: implicit declaration of function
    ‘get_random_bytes’
  4. error: macro "DECLARE_TASKLET" passed 3 arguments, but takes just 2

Solutions/workaround:

  1. In syscall.c, replace #include <linux/syscalls.h> with
    #include <linux/fdtable.h> and replace ksys_close with close_fd
    if the kernel version >= 5.11. [1][2]
  2. Add #include <linux/scatterlist.h> into cryptosk.c
  3. Add #include <linux/random.h> into cryptosk.c
  4. In bottomhalf.c and example_tasklet.c, replace DECLARE_TASKLET
    with DECLARE_TASKLET_OLD and dispose third argument(0L). [3]

[1] - https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=1572bfdf21d4d50e51941498ffe0b56c2289f783
[2] - https://www.mail-archive.com/meta-arago@arago-project.org//msg11939.html
[3] - https://patchwork.kernel.org/project/kernel-hardening/patch/20200716030847.1564131-3-keescook@chromium.org/

@fennecJ
Copy link
Collaborator Author

fennecJ commented Aug 22, 2021

There are 2 things to worry about.

  • Currently I'm not sure if all module worked correctly after above changes.
  • Some function only worked on newer kernel (e.g. fd_close only worked in kernel >= 5.11) , I currently
    not sure if other version can compile the code via makefile smoothly after above changes.

My kernel version: 5.11.0-27-generic

@fennecJ
Copy link
Collaborator Author

fennecJ commented Aug 22, 2021

The error/warning I've met with previous code:

syscall.c:

lkmpg/examples/syscall.c:83:50: error: ‘ksys_close’ undeclared (first use in this function); did you mean ‘ksys_chown’?
   83 |         if (sct[__NR_close] == (unsigned long *) ksys_close)

cryptosk.c:

lkmpg/examples/cryptosk.c:17:24: error: field ‘sg’ has incomplete type
   17 |     struct scatterlist sg;

lkmpg/examples/cryptosk.c:143:9: error: implicit declaration of function ‘get_random_bytes’ [-Werror=implicit-function-declaration]
  143 |         get_random_bytes(sk->ivdata, CIPHER_BLOCK_SIZE);

lkmpg/examples/cryptosk.c:156:5: error: implicit declaration of function ‘sg_init_one’ [-Werror=implicit-function-declaration]
  156 |     sg_init_one(&sk->sg, sk->scratchpad, CIPHER_BLOCK_SIZE);

bottomhalf.c:
example_tasklet.c:

error: macro "DECLARE_TASKLET" passed 3 arguments, but takes just 2

@fennecJ
Copy link
Collaborator Author

fennecJ commented Aug 22, 2021

Seems like DECLARE_TASKLET_OLD is defined in include/linux/interrupt.h for kernel version >= v5.9
https://elixir.bootlin.com/linux/v5.9-rc1/C/ident/DECLARE_TASKLET_OLD

examples/syscall.c Outdated Show resolved Hide resolved
@fennecJ fennecJ force-pushed the patch branch 3 times, most recently from 5e2bb72 to ae2f994 Compare August 23, 2021 02:45
@fennecJ fennecJ force-pushed the patch branch 3 times, most recently from 872b02d to 9c79f0f Compare August 23, 2021 03:07
@fennecJ fennecJ requested a review from jserv August 23, 2021 03:12
examples/bottomhalf.c Outdated Show resolved Hide resolved
Copy link
Contributor

@jserv jserv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modify the the description in TeX document about DECLARE_TASKLET_OLD transition.

examples/syscall.c Outdated Show resolved Hide resolved
@fennecJ
Copy link
Collaborator Author

fennecJ commented Aug 23, 2021

There appears with a lot of *.dwo file after I using make in /example directory,
so I add *.dwo into .gitignore file.

examples/syscall.c Outdated Show resolved Hide resolved
examples/syscall.c Outdated Show resolved Hide resolved
lkmpg.tex Outdated Show resolved Hide resolved
lkmpg.tex Outdated Show resolved Hide resolved
lkmpg.tex Outdated Show resolved Hide resolved
@fennecJ
Copy link
Collaborator Author

fennecJ commented Aug 23, 2021

"fn-in" in Makefile is intended to prevent make4ht from
excluding footnote into a new html file.

Output can be checked in https://fennecj.github.io/lkmpg/#tasklets

lkmpg.tex Outdated Show resolved Hide resolved
Known issues with current example code:
If you using newer kernel(e.g linux 5.11.x) to compile the example code,
you may meet following error:
1. syscall.c:83:50: error: ‘ksys_close’ undeclared;
2. cryptosk.c:17:24: error: field ‘sg’ has incomplete type
3. cryptosk.c:143:9: error: implicit declaration of function
‘get_random_bytes’
4. error: macro "DECLARE_TASKLET" passed 3 arguments, but takes just 2

Solutions/workaround:
1. In syscall.c, replace #include <linux/syscalls.h> with
#include <linux/fdtable.h> and replace  ksys_close with close_fd
if the kernel version >= 5.11. [1][2]
2. Add #include <linux/scatterlist.h> into cryptosk.c
3. Add #include <linux/random.h> into cryptosk.c
4. In bottomhalf.c and example_tasklet.c, replace DECLARE_TASKLET
with DECLARE_TASKLET_OLD and dispose third argument(0L). [3]

[1] - https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=1572bfdf21d4d50e51941498ffe0b56c2289f783
[2] - https://www.mail-archive.com/meta-arago@arago-project.org//msg11939.html
[3] - https://patchwork.kernel.org/project/kernel-hardening/patch/20200716030847.1564131-3-keescook@chromium.org/
@jserv jserv merged commit fe3db9f into sysprog21:master Aug 23, 2021
@jserv
Copy link
Contributor

jserv commented Aug 23, 2021

Thank @fennecJ for the great work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants