linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] RISC-V: Handle R_RISCV_32 in modules
@ 2018-06-07 10:27 Andreas Schwab
  2018-06-08 22:33 ` Palmer Dabbelt
  0 siblings, 1 reply; 4+ messages in thread
From: Andreas Schwab @ 2018-06-07 10:27 UTC (permalink / raw)
  To: linux-riscv; +Cc: linux-kernel

With CONFIG_MODVERSIONS=y the R_RISCV_32 relocation is used by the
__kcrctab section.

Signed-off-by: Andreas Schwab <schwab@suse.de>
---
 arch/riscv/kernel/module.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/arch/riscv/kernel/module.c b/arch/riscv/kernel/module.c
index 5dddba301d..1d5e9b934b 100644
--- a/arch/riscv/kernel/module.c
+++ b/arch/riscv/kernel/module.c
@@ -17,6 +17,17 @@
 #include <linux/errno.h>
 #include <linux/moduleloader.h>
 
+static int apply_r_riscv_32_rela(struct module *me, u32 *location, Elf_Addr v)
+{
+	if (v != (u32)v) {
+		pr_err("%s: value %016llx out of range for 32-bit field\n",
+		       me->name, v);
+		return -EINVAL;
+	}
+	*location = v;
+	return 0;
+}
+
 static int apply_r_riscv_64_rela(struct module *me, u32 *location, Elf_Addr v)
 {
 	*(u64 *)location = v;
@@ -265,6 +276,7 @@ static int apply_r_riscv_sub32_rela(struct module *me, u32 *location,
 
 static int (*reloc_handlers_rela[]) (struct module *me, u32 *location,
 				Elf_Addr v) = {
+	[R_RISCV_32]			= apply_r_riscv_32_rela,
 	[R_RISCV_64]			= apply_r_riscv_64_rela,
 	[R_RISCV_BRANCH]		= apply_r_riscv_branch_rela,
 	[R_RISCV_JAL]			= apply_r_riscv_jal_rela,
-- 
2.17.1


-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] RISC-V: Handle R_RISCV_32 in modules
  2018-06-07 10:27 [PATCH] RISC-V: Handle R_RISCV_32 in modules Andreas Schwab
@ 2018-06-08 22:33 ` Palmer Dabbelt
  2018-06-11  7:54   ` Andreas Schwab
  0 siblings, 1 reply; 4+ messages in thread
From: Palmer Dabbelt @ 2018-06-08 22:33 UTC (permalink / raw)
  To: schwab; +Cc: linux-riscv, linux-kernel

On Thu, 07 Jun 2018 03:27:27 PDT (-0700), schwab@suse.de wrote:
> With CONFIG_MODVERSIONS=y the R_RISCV_32 relocation is used by the
> __kcrctab section.
>
> Signed-off-by: Andreas Schwab <schwab@suse.de>
> ---
>  arch/riscv/kernel/module.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
>
> diff --git a/arch/riscv/kernel/module.c b/arch/riscv/kernel/module.c
> index 5dddba301d..1d5e9b934b 100644
> --- a/arch/riscv/kernel/module.c
> +++ b/arch/riscv/kernel/module.c
> @@ -17,6 +17,17 @@
>  #include <linux/errno.h>
>  #include <linux/moduleloader.h>
>
> +static int apply_r_riscv_32_rela(struct module *me, u32 *location, Elf_Addr v)
> +{
> +	if (v != (u32)v) {

My worry with this kind of check is that it relies on some sort of undefined 
behavior in C and that at some point in the future GCC will just go decide the 
check can never fail.  I checked and GCC doesn't elide these checks now, so I 
might be wrong.

Is this defined to do what it looks like it's doing?

> +		pr_err("%s: value %016llx out of range for 32-bit field\n",
> +		       me->name, v);
> +		return -EINVAL;
> +	}
> +	*location = v;
> +	return 0;
> +}
> +
>  static int apply_r_riscv_64_rela(struct module *me, u32 *location, Elf_Addr v)
>  {
>  	*(u64 *)location = v;
> @@ -265,6 +276,7 @@ static int apply_r_riscv_sub32_rela(struct module *me, u32 *location,
>
>  static int (*reloc_handlers_rela[]) (struct module *me, u32 *location,
>  				Elf_Addr v) = {
> +	[R_RISCV_32]			= apply_r_riscv_32_rela,
>  	[R_RISCV_64]			= apply_r_riscv_64_rela,
>  	[R_RISCV_BRANCH]		= apply_r_riscv_branch_rela,
>  	[R_RISCV_JAL]			= apply_r_riscv_jal_rela,

Thanks!

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] RISC-V: Handle R_RISCV_32 in modules
  2018-06-08 22:33 ` Palmer Dabbelt
@ 2018-06-11  7:54   ` Andreas Schwab
  2018-06-11 20:53     ` Palmer Dabbelt
  0 siblings, 1 reply; 4+ messages in thread
From: Andreas Schwab @ 2018-06-11  7:54 UTC (permalink / raw)
  To: Palmer Dabbelt; +Cc: linux-riscv, linux-kernel

On Jun 08 2018, Palmer Dabbelt <palmer@sifive.com> wrote:

> On Thu, 07 Jun 2018 03:27:27 PDT (-0700), schwab@suse.de wrote:
>> With CONFIG_MODVERSIONS=y the R_RISCV_32 relocation is used by the
>> __kcrctab section.
>>
>> Signed-off-by: Andreas Schwab <schwab@suse.de>
>> ---
>>  arch/riscv/kernel/module.c | 12 ++++++++++++
>>  1 file changed, 12 insertions(+)
>>
>> diff --git a/arch/riscv/kernel/module.c b/arch/riscv/kernel/module.c
>> index 5dddba301d..1d5e9b934b 100644
>> --- a/arch/riscv/kernel/module.c
>> +++ b/arch/riscv/kernel/module.c
>> @@ -17,6 +17,17 @@
>>  #include <linux/errno.h>
>>  #include <linux/moduleloader.h>
>>
>> +static int apply_r_riscv_32_rela(struct module *me, u32 *location, Elf_Addr v)
>> +{
>> +	if (v != (u32)v) {
>
> My worry with this kind of check is that it relies on some sort of
> undefined behavior in C and that at some point in the future GCC will just
> go decide the check can never fail.  I checked and GCC doesn't elide these
> checks now, so I might be wrong.
>
> Is this defined to do what it looks like it's doing?

This is unsigned arithmetic, thus fully defined.

Andreas.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] RISC-V: Handle R_RISCV_32 in modules
  2018-06-11  7:54   ` Andreas Schwab
@ 2018-06-11 20:53     ` Palmer Dabbelt
  0 siblings, 0 replies; 4+ messages in thread
From: Palmer Dabbelt @ 2018-06-11 20:53 UTC (permalink / raw)
  To: schwab; +Cc: linux-riscv, linux-kernel

On Mon, 11 Jun 2018 00:54:00 PDT (-0700), schwab@suse.de wrote:
> On Jun 08 2018, Palmer Dabbelt <palmer@sifive.com> wrote:
>
>> On Thu, 07 Jun 2018 03:27:27 PDT (-0700), schwab@suse.de wrote:
>>> With CONFIG_MODVERSIONS=y the R_RISCV_32 relocation is used by the
>>> __kcrctab section.
>>>
>>> Signed-off-by: Andreas Schwab <schwab@suse.de>
>>> ---
>>>  arch/riscv/kernel/module.c | 12 ++++++++++++
>>>  1 file changed, 12 insertions(+)
>>>
>>> diff --git a/arch/riscv/kernel/module.c b/arch/riscv/kernel/module.c
>>> index 5dddba301d..1d5e9b934b 100644
>>> --- a/arch/riscv/kernel/module.c
>>> +++ b/arch/riscv/kernel/module.c
>>> @@ -17,6 +17,17 @@
>>>  #include <linux/errno.h>
>>>  #include <linux/moduleloader.h>
>>>
>>> +static int apply_r_riscv_32_rela(struct module *me, u32 *location, Elf_Addr v)
>>> +{
>>> +	if (v != (u32)v) {
>>
>> My worry with this kind of check is that it relies on some sort of
>> undefined behavior in C and that at some point in the future GCC will just
>> go decide the check can never fail.  I checked and GCC doesn't elide these
>> checks now, so I might be wrong.
>>
>> Is this defined to do what it looks like it's doing?
>
> This is unsigned arithmetic, thus fully defined.

Great, thanks!  I guess I'm just a bit paranoid :)

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-06-11 20:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-07 10:27 [PATCH] RISC-V: Handle R_RISCV_32 in modules Andreas Schwab
2018-06-08 22:33 ` Palmer Dabbelt
2018-06-11  7:54   ` Andreas Schwab
2018-06-11 20:53     ` Palmer Dabbelt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).