-
-
Notifications
You must be signed in to change notification settings - Fork 363
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
Linux rise in rizin: SLUB dumping, Kernel build configuration #4306
base: dev
Are you sure you want to change the base?
Conversation
The PR is very far from over.
Will add todo later. |
librz/core/cmd/cmd_linux_heap_slub.c
Outdated
#define call_handler(fun, ...) \ | ||
{ \ | ||
if (core->rasm->bits == 64) { \ | ||
return fun##_64(core, ##__VA_ARGS__); \ | ||
} else { \ | ||
return fun##_32(core, ##__VA_ARGS__); \ | ||
} \ | ||
} | ||
|
||
RZ_IPI RzCmdStatus rz_cmd_debug_slub_dump_freelist_handler(RzCore *core, int argc, const char **argv, RzCmdStateOutput *output_state) { | ||
call_handler(rz_cmd_debug_slub_dump_freelist_handler, argc, argv, output_state); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I'm wrong but can't we just do the following?
#define call_handler(fun, ...) \ | |
{ \ | |
if (core->rasm->bits == 64) { \ | |
return fun##_64(core, ##__VA_ARGS__); \ | |
} else { \ | |
return fun##_32(core, ##__VA_ARGS__); \ | |
} \ | |
} | |
RZ_IPI RzCmdStatus rz_cmd_debug_slub_dump_freelist_handler(RzCore *core, int argc, const char **argv, RzCmdStateOutput *output_state) { | |
call_handler(rz_cmd_debug_slub_dump_freelist_handler, argc, argv, output_state); | |
} | |
RZ_IPI RzCmdStatus rz_cmd_debug_slub_dump_freelist_handler(RzCore *core, int argc, const char **argv, RzCmdStateOutput *output_state) { | |
if (core->rasm->bits == 64) { | |
return rz_cmd_debug_slub_dump_freelist_handler_64(core, argc, argv, output_state); | |
} else { | |
return rz_cmd_debug_slub_dump_freelist_handler_32(core, argc, argv, output_state); | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will add more functions. Macro will come in handy.
See librz/core/cmd/cmd_linux_heap_glibc.c
librz/analysis/dwarf_process.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are these dwarf changes related to the linux heap changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, all the dwarf changes are for the sake of debugging the functionality.
I will remove them as soon as I am finished.
It speeds up rizin startup: takes 1 minute instead of 10+.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you can, please split them in a separate PR that we can merge sooner then! It would be great to have such an improvement :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But only if it's general enough, currently it just skips everything except specific file. cc @imbillow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @rockrid3r ! Please also add a short description of what you are trying to achieve so people reviewing know immediately and a better title for the PR |
My bad. I've pinned the issue link and changed PR title. |
Currently PR is in much better state. It's almost ready for merge.
Only tests are left. |
librz/core/cconfig.c
Outdated
RZ_LOG_INFO("Parsing config file '%s'...\n", vmlinux_config); | ||
vmlinux_parse_apply_config_file(vmlinux_config, core->analysis->vmlinux_config->config_tbl); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe before parsing, you should check if the string is empty and if the file exists.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello. I am verifying it inside the function vmlinux_parse_apply_config_file
librz/core/cconfig.c
Outdated
|
||
if (RZ_STR_ISNOTEMPTY(apply_config_file)) { | ||
printf("Parsing apply_config file '%s'\n", apply_config_file); | ||
RZ_LOG_INFO("Parsingconfig file '%s'\n", apply_config_file); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RZ_LOG_INFO("Parsingconfig file '%s'\n", apply_config_file); | |
RZ_LOG_INFO("Parsing config file '%s'\n", apply_config_file); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed, thanks
I've added basic tests for version handler and configuration handler |
There are merge conflicts, please rebase and solve them. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wargio @thestr4ng3r @ret2libc @Rot127 please take a look too, mostly at where things are located architecturally.
test/unit/test_vmlinux.c
Outdated
#include <stdbool.h> | ||
|
||
static bool test_vmlinux_vercmp(void) { | ||
unsigned long v1[3] = {6, 7, 1}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Broken indentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ran clang-format
librz/include/vmlinux.h
Outdated
@@ -0,0 +1,29 @@ | |||
#pragma once |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- SPDX
- Doxygen comments for added structures and the purpose of this file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please don't use #pragma once
but use proper #ifndef XXX
#define XXX
also add the c++ guards.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added doxygen & spdx. usnig #ifndef
now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wargio could you please elaborate more on c++ guards? what should be added?
librz/include/rz_analysis.h
Outdated
@@ -535,6 +537,7 @@ typedef struct rz_analysis_t { | |||
RzAnalysisDebugInfo *debug_info; ///< store all debug info parsed from DWARF, etc.. | |||
ut64 cmpval; ///< last compare value for jump table. | |||
ut64 lea_jmptbl_ip; ///< jump table x86 lea ip | |||
RzVmlinuxConfig* vmlinux_config; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not particularly happy about adding the vmlinux config directly in the RzAnalysis; honestly, it looks out of place. @wargio @ret2libc @Rot127 @thestr4ng3r any ideas?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The proper way would be to have it in it's own plugin IMHO. Because the logic is very much contained. But it is good how it is currently. Wouldn't know a place where the config fits else.
Added it #4334 as code which should be move to it's own plugin after refactoring. Please remove it if you disagree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i wonder if this should be a bin+io plugin with, like we have for dmp
librz/core/vmlinux.c
Outdated
|
||
static void add_config(RzVmlinuxConfigTable* config_tbl, char* config_name, char* config_value); | ||
|
||
RZ_API bool vmlinux_parse_apply_config_file(const char* config_filepath, RzVmlinuxConfigTable* config_tbl) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doxygen for every new or changed RZ_API
function except obvious ones like _free()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added doxygen.
librz/core/vmlinux.c
Outdated
static void add_config(RzVmlinuxConfigTable* config_tbl, char* config_name, char* config_value); | ||
|
||
RZ_API bool vmlinux_parse_apply_config_file(const char* config_filepath, RzVmlinuxConfigTable* config_tbl) { | ||
rz_return_val_if_fail(config_filepath && config_tbl, false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you add assert, please also add attributes like RZ_NONNULL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also add rz_
prefix for any new functionality that is RZ_API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added both prefix and NONNULL
librz/core/vmlinux.c
Outdated
free(vmlinux_config); | ||
} | ||
|
||
RZ_API void rz_vmlinux_config_table_free(RzVmlinuxConfigTable* config_tbl) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RZ_NULLABLE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
@@ -0,0 +1,33 @@ | |||
#include <rz_core.h> | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SPDX and Doxygen for file description
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added.
@@ -0,0 +1,1060 @@ | |||
#include <rz_core.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SPDX
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
librz/core/cmd_descs/cmd_slub.yaml
Outdated
@@ -0,0 +1,55 @@ | |||
# SPDX-FileCopyrightText: 2021 RizinOrg <[email protected]> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok.
librz/core/cmd/cmd_linux_heap_slub.c
Outdated
@@ -0,0 +1,34 @@ | |||
// SPDX-FileCopyrightText: 2021 Pulak Malhotra <[email protected]> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong SPDX, put yours
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed, thanks.
test/unit/test_vmlinux.c
Outdated
@@ -0,0 +1,50 @@ | |||
// SPDX-FileCopyrightText: 2017 Fangrui Song <[email protected]> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please put your copyright here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed, thanks.
test/unit/test_vmlinux.c
Outdated
|
||
size_t config_size = sizeof(config_lines) / sizeof(config_lines[0]); | ||
for (size_t i = 0; i < config_size; ++i) { | ||
// eprintf("%p, %p\n", config_lines[i], config_tbl); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, remove debug code when done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed, thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looked briefly. And in general LGTM. Please though, resolve comments from @XVilka. Especially the doxygen is important.
If you find the time it would be nice, if you could quickly run the unittest with valgrind --leak-check=full
.
2. Bug fixes. 3. Refactor.
a637b5c
to
62ac804
Compare
DO NOT MERGE IT'S STILL UNTESTED
Addresses #4257
SLUB dumping
Add integration tests(is not suitable)Vmlinux(TODO: Separate PR)Add support to rebase kernel binary (KASLR)Add unit testsKernel version handling
6.7
kernel as default kernel version-e linux.version=5.6.11
Add rizin shell command to change kernel version.Kernel configuration handling
defconfig
configuration file. It will contain all the default flags used while building kernel.It will be the presumed kernel configuration if user does not supply more. (User should set it up in
~/.config/rizin/defconfig
)Add CLI flag to support user-supplied kernel build configuration flags. For example, this:should openvmlinux
file and handle the fact that kernel was built with configurationdefconfig
+CONFIG_FREELIST_RANDOM=y
Add rizin shell command user-supplied configuration:> set_config CONFIG_FREELIST_RANDOM=y
(same as before, but in shell)implies that rizing will use
.config
instead ofdefconfig
.& integration testsBasic checklist