2015-04-13 11:32:03

by Rusty Russell

[permalink] [raw]
Subject: Re: [PATCH 7/7] modpost: handle relocations mismatch in __ex_table.

Quentin Casasnovas <[email protected]> writes:
> __ex_table is a simple table section where each entry is a pair of
> addresses - the first address is an address which can fault in kernel
> space, and the second address points to where the kernel should jump to
> when handling that fault. This is how copy_from_user() does not crash the
> kernel if userspace gives a borked pointer for example.

Warnings on 32-bit:

scripts/mod/modpost.c:1562:7: warning: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 4 has type ‘Elf32_Addr’ [-Wformat=]
to_pretty_name, tosec, tosym_name, to_pretty_name_p);
^
scripts/mod/modpost.c:1574:4: warning: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 4 has type ‘Elf32_Addr’ [-Wformat=]
fromsec, r->r_offset, tosec, tosec, tosec);
^
scripts/mod/modpost.c: In function ‘extable_mismatch_handler’:
scripts/mod/modpost.c:1596:9: warning: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 3 has type ‘Elf32_Addr’ [-Wformat=]
fromsec, r->r_offset, tosec, modname);
^
scripts/mod/modpost.c:1604:10: warning: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 3 has type ‘Elf32_Addr’ [-Wformat=]
fromsec, r->r_offset, tosec);
^
scripts/mod/modpost.c:1611:10: warning: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 3 has type ‘Elf32_Addr’ [-Wformat=]
fromsec, r->r_offset, tosec);
^

Fixed like so:

diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 7b56ae567fba..b495547e321f 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -1557,7 +1557,7 @@ static void report_extable_warnings(const char* modname, struct elf_info* elf,

warn("%s(%s+0x%lx): Section mismatch in reference"
" from the %s %s%s to the %s %s:%s%s\n",
- modname, fromsec, r->r_offset, from_pretty_name,
+ modname, fromsec, (long)r->r_offset, from_pretty_name,
fromsym_name, from_pretty_name_p,
to_pretty_name, tosec, tosym_name, to_pretty_name_p);

@@ -1571,7 +1571,7 @@ static void report_extable_warnings(const char* modname, struct elf_info* elf,
"list of authorized sections to jump to on fault.\n"
"This can be achieved by adding \"%s\" to \n"
"OTHER_TEXT_SECTIONS in scripts/mod/modpost.c.\n",
- fromsec, r->r_offset, tosec, tosec, tosec);
+ fromsec, (long)r->r_offset, tosec, tosec, tosec);
}

static void extable_mismatch_handler(const char* modname, struct elf_info *elf,
@@ -1593,7 +1593,7 @@ static void extable_mismatch_handler(const char* modname, struct elf_info *elf,
"Something is seriously wrong and should be fixed.\n"
"You might get more information about where this is\n"
"coming from by using scripts/check_extable.sh %s\n",
- fromsec, r->r_offset, tosec, modname);
+ fromsec, (long)r->r_offset, tosec, modname);
else if (!is_executable_section(elf, get_secindex(elf, sym))) {
if (is_extable_fault_address(r))
fatal("The relocation at %s+0x%lx references\n"
@@ -1601,14 +1601,14 @@ static void extable_mismatch_handler(const char* modname, struct elf_info *elf,
"it is not possible for the kernel to fault\n"
"at that address. Something is seriously wrong\n"
"and should be fixed.\n",
- fromsec, r->r_offset, tosec);
+ fromsec, (long)r->r_offset, tosec);
else
fatal("The relocation at %s+0x%lx references\n"
"section \"%s\" which is not executable, IOW\n"
"the kernel will fault if it ever tries to\n"
"jump to it. Something is seriously wrong\n"
"and should be fixed.\n",
- fromsec, r->r_offset, tosec);
+ fromsec, (long)r->r_offset, tosec);
}
}



Thanks,
Rusty.


2015-04-13 13:32:04

by Quentin Casasnovas

[permalink] [raw]
Subject: Re: [PATCH 7/7] modpost: handle relocations mismatch in __ex_table.

On Mon, Apr 13, 2015 at 08:48:56PM +0930, Rusty Russell wrote:
> Quentin Casasnovas <[email protected]> writes:
> > __ex_table is a simple table section where each entry is a pair of
> > addresses - the first address is an address which can fault in kernel
> > space, and the second address points to where the kernel should jump to
> > when handling that fault. This is how copy_from_user() does not crash the
> > kernel if userspace gives a borked pointer for example.
>
> Warnings on 32-bit:
>
> [snip/]
>
> Fixed like so:

Thanks for the fixing, and nice catch on the "mistmatch" ;)
^

Quentin