Text relocations in kernel modules
kostikbel at gmail.com
Fri Mar 30 20:36:23 UTC 2012
On Fri, Mar 30, 2012 at 04:11:29PM -0400, Richard Yao wrote:
> On 03/30/12 15:46, Konstantin Belousov wrote:
> > On Fri, Mar 30, 2012 at 03:42:22PM -0400, Richard Yao wrote:
> >> On 03/30/12 15:07, Konstantin Belousov wrote:
> >>>> Is this a bug?
> >>> No. This is by design.
> >>> Why do you consider this a bug ?
> >> It occurs on i386, but not amd64. It could be that something is wrong
> >> with how things are being compiled i386, or it could be that i386
> >> requires things to be compiled this way. I do not know which.
> > Again, let me repeat my question. Why do you consider the presence
> > of relocations against text section a problem ?
> The linker emits warnings:
> i686-gentoo-freebsd9.0-ld: warning: creating a DT_TEXTREL in object.
> Furthermore, this triggers a QA check in Gentoo/FreeBSD's package manager.
> * QA Notice: The following files contain runtime text relocations
> * Text relocations force the dynamic linker to perform extra
> * work at startup, waste system resources, and may pose a security
> * risk. On some architectures, the code may not even function
> * properly, if at all.
> * For more information, see http://hardened.gentoo.org/pic-fix-guide.xml
> * Please include the following list of files in your report:
> * TEXTREL boot/modules/if_vtnet.ko
> * TEXTREL boot/modules/virtio_blk.ko
> * TEXTREL boot/modules/virtio.ko
> * TEXTREL boot/modules/virtio_balloon.ko
> * TEXTREL boot/modules/virtio_pci.ko
> I wrote that ebuild as part of something entirely unrelated. If it is a
> feature, I can disable the QA check, but I should at least know why the
> text relocations are needed.
> Gentoo maintainers are expected to patch text relocations and send
> patches upstream. The only exception is in the case of binary packages,
> which they cannot patch.
> Investigating the text relocations in my port of emulators/virtio-kmod
> revealed that all kernel modules on i386 Gentoo/FreeBSD have text
> relocations, yet none have them on amd64 FreeBSD, so I do not know
> whether this is a bug or a feature.
First, there _are_ relocations against text in the amd64 modules, but I
suspect that your scripts do not detect this. Most likely, scripts look
for DT_TEXTREL dynamic tag, and tags are only present in the executables
or shared objects, not in the object files. The amd64 modules are object
files, so you just mis-interpret the situation.
Second, from what you wrote, I see the issue in either wrong policy
being established in your project, or (another) mis-interpretation of
the policy. Indeed, having text relocations in the shared objects is
bad, because said relocations hinder text pages sharing. Relocated page
is modified, so COW mechanism causes it to become private to process.
On the other hand, there is only one instance of the loaded kernel module,
its text segment (or section, for amd64) is not shared, so modifications
to the text pages do not cause increased memory use. More, not compiling
modules with -fPIC (absence of -fPIC is what makes the text relocations to
appear in the final link result) makes the code faster, esp. on i386.
So, there is nothing to report, and fix is outside the FreeBSD domain:
either fix your policy by not stating that text relocation in kernel
module is banned, or just find that policy only applicable to usermode
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 196 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-stable/attachments/20120330/09e5cd58/attachment.pgp
More information about the freebsd-stable