Skip to content
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

sysfs: cannot create duplicate filename '/kernel/kpatch/patches/kpatch_fix_stack_randomization/functions/load_elf_binary' #484

Closed
arighi opened this issue Mar 20, 2015 · 2 comments

Comments

@arighi
Copy link

arighi commented Mar 20, 2015

I get this error if I try to apply this patch live to a 3.12.38 (vanilla):
http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=4e7c22d447bb6d7e37bfe39ff658486ae78e8d77

When I compile the fix kpatch-build says:
...
Extracting new and modified ELF sections
mmap.o: changed function: stack_maxrandom_size
mmap.o: changed function: arch_pick_mmap_layout
compat_binfmt_elf.o: changed function: load_elf_binary
binfmt_elf.o: changed function: load_elf_binary

So, IIUC the reason of the duplicate load_elf_binary it's because kpatch-build thinks there's a load_elf_binary() also in compat_binfmt_elf.c... but apparently it's defined only in fs/binfmt_elf.c...

Could you clarify or point out how to address this problem? Any help appreciated.

Thanks!

Full kernel oops:
[ 1137.462576] ------------[ cut here ]------------
[ 1137.462685] WARNING: CPU: 1 PID: 31107 at fs/sysfs/dir.c:526 sysfs_add_one+0xa5/0xd0()
[ 1137.462695] sysfs: cannot create duplicate filename '/kernel/kpatch/patches/kpatch_fix_stack_randomization/functions/load_elf_binary'
[ 1137.462701] Modules linked in: kpatch_fix_stack_randomization(O+) kpatch(O) ipt_MASQUERADE iptable_nat nf_conntrack_ipv4 nf_defrag_ipv4 nf_nat_ipv4 nf_nat nf_conntrack ip_tables x_tables arc4 ath9k ath9k_common ath9k_hw dell_wmi sparse_keymap x86_pkg_temp_thermal kvm_intel kvm ath dell_laptop mac80211 dcdbas ath3k btusb snd_hda_codec_hdmi snd_hda_codec_realtek bluetooth snd_hda_intel snd_hda_codec snd_hwdep snd_pcm snd_page_alloc snd_seq_midi snd_seq_midi_event uvcvideo cfg80211 snd_rawmidi nfsd videobuf2_vmalloc videobuf2_memops videobuf2_core snd_seq videodev snd_timer snd_seq_device auth_rpcgss oid_registry joydev snd nfs parport_pc serio_raw ppdev soundcore lp wmi lockd parport mac_hid sunrpc raid1 psmouse i915 i2c_algo_bit drm_kms_helper drm video
[ 1137.462893] CPU: 1 PID: 31107 Comm: insmod Tainted: G O 3.12.38 #1
[ 1137.462895] Hardware name: Dell Inc. Dell System XPS L322X/0PJHXN, BIOS A09 05/15/2013
[ 1137.462897] 0000000000000009 ffff88009a571b00 ffffffff816b7c74 ffff88009a571b48
[ 1137.462903] ffff88009a571b38 ffffffff8104e23d 00000000ffffffef ffff88009a3fabe0
[ 1137.462908] ffff88009a571be0 ffff8802319e6000 0000000000000000 ffff88009a571b98
[ 1137.462914] Call Trace:
[ 1137.462920] [] dump_stack+0x54/0x74
[ 1137.462925] [] warn_slowpath_common+0x7d/0xa0
[ 1137.462929] [] warn_slowpath_fmt+0x4c/0x50
[ 1137.462932] [] sysfs_add_one+0xa5/0xd0
[ 1137.462936] [] create_dir+0x74/0xd0
[ 1137.462940] [] sysfs_create_dir+0x89/0xe0
[ 1137.462945] [] ? kvasprintf+0x6b/0x80
[ 1137.462950] [] kobject_add_internal+0xbb/0x2b0
[ 1137.462953] [] kobject_add+0x65/0xb0
[ 1137.462958] [] ? __kmalloc+0x1b0/0x1e0
[ 1137.462963] [] ? kzalloc.constprop.6+0xe/0x10 [kpatch_fix_stack_randomization]
[ 1137.462968] [] patch_init+0x1c1/0x1000 [kpatch_fix_stack_randomization]
[ 1137.462973] [] ? 0xffffffffa0680fff
[ 1137.462978] [] do_one_initcall+0x112/0x170
[ 1137.462983] [] ? set_memory_nx+0x43/0x50
[ 1137.462989] [] load_module+0x1caa/0x24f0
[ 1137.462992] [] ? symbol_put_addr+0x40/0x40
[ 1137.463017] [] SyS_finit_module+0x7e/0x80
[ 1137.463032] [] system_call_fastpath+0x16/0x1b
[ 1137.463040] ---[ end trace daaae26ff27a47fc ]---

@jpoimboe
Copy link
Member

So, IIUC the reason of the duplicate load_elf_binary it's because kpatch-build thinks there's a load_elf_binary() also in compat_binfmt_elf.c... but apparently it's defined only in fs/binfmt_elf.c...

Actually compat_binfmt_elf.c has #include "binfmt_elf.c", so it looks to me like kpatch-build is correctly detecting a change to both files.

The fact that kpatch doesn't allow the patching of two functions with the same name is probably a bug. But that will be going away soon when we change the kpatch sysfs interface to be more like upstream livepatch.

I think you should be able to work around this issue by adding the following change to your patch.

At the end of fs/compat_binfmt_elf.c:

#include "kpatch-macros.h"
KPATCH_IGNORE_FUNCTION(load_elf_binary);

That should tell kpatch-build to ignore the change to load_elf_binary() in compat_binfmt.c.

@arighi
Copy link
Author

arighi commented Mar 23, 2015

The suggested workaround works very well. For my point of view we can close this issue.

Thanks!

@arighi arighi closed this as completed Mar 23, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants