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
FS#544 - kmodloader segfault on ixp4xx (armeb) #5574
Comments
yousong:
_aliases[i] = ptr; <<-- this is the failing assignment
You mean "ptr" had correct value, but after the assignment "_aliases[i]" was endian-swapped? If that is the case, I think inspecting the assembly output with compiler -S flag will help. Can you also share the buggy binary here so that we can objdump it and check the final content. |
thess: Yes, that is exactly what I've narrowed it down to. Believe it or not, the statement:
inserted after the assignment is TRUE! Attached is the offending binary, the assembler output (-S to gcc) and objdump -D of the kmodloader.c.o output. |
kofec: Do you think that my issue can be related to this? part of log: |
yousong: This is very likely an address alignment issue. I will see if I can provide a patch. |
thess: Somewhat less than elegant solution - calloc_a() argument alignment is the most likely culprit. This patch does alleviate the issue.
--- a/kmodloader.c
+++ b/kmodloader.c
@@ -250,7 +250,6 @@ alloc_module(const char *name, const cha
{
struct module *m;
char *_name, *_dep;
- char **_aliases;
int i, len_aliases;
|
yousong: A patch has been posted to the mailing list, please test: http://lists.infradead.org/pipermail/lede-dev/2017-February/006235.html |
kofec: Ted, Yousong, |
yousong: Hi, kofec The two patches cannot be merged. I am fairly sure ted's patch should work and it has been run-tested by himself. But it's a temporary workaround not intended for final inclusion I guess. To try it
|
thess: I vote to go with @yousong patch - removes the extra copying of the aliases. Additionally, I will be submitting a patch to libubox to update calloc_a() to conform to malloc() alignment of pointers. |
kofec: I see your commit in LEDE project and may confirm that it is fine/working on my nsa310
[ 9.619284] NET: Registered protocol family 24
[ 9.630624] kmodloader: done loading kernel modules from /etc/modules.d/*
[ 9.873041] EXT4-fs (sda1): mounted filesystem with ordered data mode. Opts:
|
thess:
I believe this issue to be a really obscure endian problem which may be more toolchain related than a raw software bug in the source code. I've tried to work-around this issue with code changes, but the problem persists. I give up...
Inside the routine 'alloc_module' the following code produces the wrong result -- specifically byte-swapped pointers in the '_aliases' array.
char **_aliases;
...
char *ptr = (char *)_aliases + naliases * sizeof(_aliases[0]);
int len;
i = 0;
do {
len = strlen(aliases[i]) + 1;
memcpy(ptr, aliases[i], len);
_aliases[i] = ptr; <<-- this is the failing assignment
ptr += len;
i++;
} while (i < naliases);
The text was updated successfully, but these errors were encountered: