public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86: livepatch: Treat R_X86_64_PLT32 as R_X86_64_PC32
@ 2019-02-15  2:01 chenzefeng (A)
  2019-02-15  7:28 ` Jiri Kosina
  2019-02-18 11:47 ` gregkh
  0 siblings, 2 replies; 8+ messages in thread
From: chenzefeng (A) @ 2019-02-15  2:01 UTC (permalink / raw)
  To: hjl.tools@gmail.com, jpoimboe@redhat.com, sjenning@redhat.com,
	jikos@kernel.org, vojtech@suse.com, tglx@linutronix.de,
	mingo@redhat.com, hpa@zytor.com, gregkh@linuxfoundation.org
  Cc: x86@kernel.org, live-patching@vger.kernel.org,
	linux-kernel@vger.kernel.org, chengjian (D)

On x86-64, for 32-bit PC-relacive branches, we can generate PLT32 relocation, instead of PC32 relocation. and R_X86_64_PLT32 can be treated the same as R_X86_64_PC32 since linux kernel doesn't use PLT.

In linux 4.4 commit b21ebf2fb4cd ("x86: Treat R_X86_64_PLT32 as R_X86_64_PC32") been fixed for the module loading, but not fixed for livepatch relocation, which will fail to load livepatch with the error message as follow:
relocation failed for symbol <symbol name> at <symbol address>

Signed-off-by: chenzefeng <chenzefeng2@huawei.com>
---
 arch/x86/kernel/livepatch.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/x86/kernel/livepatch.c b/arch/x86/kernel/livepatch.c index d1d35cc..579f8f8 100644
--- a/arch/x86/kernel/livepatch.c
+++ b/arch/x86/kernel/livepatch.c
@@ -58,6 +58,7 @@ int klp_write_module_reloc(struct module *mod, unsigned long type,
 		val = (s32)value;
 		break;
 	case R_X86_64_PC32:
+	case R_X86_64_PLT32:
 		val = (u32)(value - loc);
 		break;
 	default:
--
1.8.5.6


^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: [PATCH] x86: livepatch: Treat R_X86_64_PLT32 as R_X86_64_PC32
@ 2019-02-19  8:16 chenzefeng (A)
  0 siblings, 0 replies; 8+ messages in thread
From: chenzefeng (A) @ 2019-02-19  8:16 UTC (permalink / raw)
  To: Petr Mladek, chengjian (D)
  Cc: stable@vger.kernel.org, Jiri Kosina, hjl.tools@gmail.com,
	jpoimboe@redhat.com, sjenning@redhat.com, vojtech@suse.com,
	tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com,
	gregkh@linuxfoundation.org, x86@kernel.org,
	live-patching@vger.kernel.org, linux-kernel@vger.kernel.org,
	Xiexiuqi

Hi,

I am sorry this email was sent by accident. Please ignore this email.

Best Regards



-----邮件原件-----
发件人: chenzefeng (A) 
发送时间: 2019年2月19日 14:38
收件人: 'Petr Mladek' <pmladek@suse.com>; chengjian (D) <cj.chengjian@huawei.com>
抄送: 'stable@vger.kernel.org' <stable@vger.kernel.org>; Jiri Kosina <jikos@kernel.org>; hjl.tools@gmail.com; jpoimboe@redhat.com; sjenning@redhat.com; vojtech@suse.com; tglx@linutronix.de; mingo@redhat.com; hpa@zytor.com; gregkh@linuxfoundation.org; x86@kernel.org; live-patching@vger.kernel.org; linux-kernel@vger.kernel.org; Xiexiuqi <xiexiuqi@huawei.com>
主题: Re:[PATCH] x86: livepatch: Treat R_X86_64_PLT32 as R_X86_64_PC32

On Mon 2019-02-18 17:22, Petr wrote:

> On Mon 2019-02-18 13:29:11, chengjian (D) wrote:
> > Hi,Jiri
> >
> >
> > This patch should be merged into 4.4 stable,
> >
> > which still use klp_write_module_reloc.
> >
> >
> > https://elixir.bootlin.com/linux/v4.4.174/source/arch/x86/kernel/livep
> > atch.c
> >
> >
> > ZeFeng may have sent a stable(4.4-y) patch to the wrong mail-list(mainline).
> 
> ZeFeng or Chengjian, please, send the patch once again with stable@vger.kernel.org in CC and explanation that it is needed only for 4.4 and why.
> 
> This thread is already too long and messed to be proceed by stable people effectively.
>
> Best Regards,
> Petr

On x86-64, for 32-bit PC-relacive branches, we can generate PLT32 relocation, instead of PC32 relocation. and R_X86_64_PLT32 can be treated the same as R_X86_64_PC32 since linux kernel doesn't use PLT.

commit b21ebf2fb4cd ("x86: Treat R_X86_64_PLT32 as R_X86_64_PC32") been fixed for the module loading, but not fixed for livepatch relocation, which will fail to load livepatch with the error message as follow:
relocation failed for symbol <symbol name> at <symbol address>

This issue only effacted the kernel version from 4.0 to 4.6, becauce the function klp_write_module_reloc is introduced by:
commit b700e7f03df5 ("livepatch: kernel: add support for live patching") and deleted by: commit 425595a7fc20
("livepatch: reuse module loader code to write relocations")

Signed-off-by: chenzefeng <chenzefeng2@huawei.com>
---
 arch/x86/kernel/livepatch.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/x86/kernel/livepatch.c b/arch/x86/kernel/livepatch.c index d1d35cc..579f8f8 100644
--- a/arch/x86/kernel/livepatch.c
+++ b/arch/x86/kernel/livepatch.c
@@ -58,6 +58,7 @@ int klp_write_module_reloc(struct module *mod, unsigned long type,
 		val = (s32)value;
 		break;
 	case R_X86_64_PC32:
+	case R_X86_64_PLT32:
 		val = (u32)(value - loc);
 		break;
 	default:
--
1.8.5.6



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

end of thread, other threads:[~2019-02-19  8:16 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-02-15  2:01 [PATCH] x86: livepatch: Treat R_X86_64_PLT32 as R_X86_64_PC32 chenzefeng (A)
2019-02-15  7:28 ` Jiri Kosina
2019-02-15  8:17   ` 答复: " chenzefeng (A)
2019-02-15  9:05     ` Petr Mladek
2019-02-18  5:29   ` chengjian (D)
2019-02-18  9:22     ` Petr Mladek
2019-02-18 11:47 ` gregkh
  -- strict thread matches above, loose matches on Subject: below --
2019-02-19  8:16 chenzefeng (A)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox