failure to build kernel module that uses getname()/putname()

General support questions
Post Reply
gblues
Posts: 3
Joined: 2014/11/17 23:34:04

failure to build kernel module that uses getname()/putname()

Post by gblues » 2014/11/17 23:48:11

I am having trouble building a kernel module that makes use of getname() and putname(). I do not have a RHEL 7 image to test to see if it is also affected.

When I attempt to build the module, the compile succeeds but the modpost spits out a warning:

WARNING: "getname" [/root/mod/mod.ko] undefined!

If I attempt to insert the module, dmesg complains:

mod: Unknown symbol getname (err 0)

Below is sample code to reproduce the error:

Code: Select all

#include <linux/module.h>
#include <linux/fs.h>

static int __init mod_init(void)
{
  int retval = 0;
  const char __user *filename = "foo";
  struct filename *p_kernelname;

  p_kernelname = getname(filename);

  return retval;
}

static void __exit mod_exit(void)
{
}

module_init(mod_init);
module_exit(mod_exit);

MODULE_LICENSE("GPL");
Am I doing something wrong? Or is this a bug?

chemal
Posts: 776
Joined: 2013/12/08 19:44:49

Re: failure to build kernel module that uses getname()/putna

Post by chemal » 2014/11/18 02:30:28

Am I doing something wrong?
Yes.

(Better answers may require the whole story. I for example cannot load C code snippets into the kernel. I've heard you must compile this stuff first. How did you do it?)

gblues
Posts: 3
Joined: 2014/11/17 23:34:04

Re: failure to build kernel module that uses getname()/putna

Post by gblues » 2014/11/18 20:49:04

Sorry--it's a private project, but I've put together a very basic module to demonstrate the issue.

**do not try to insert the module**

Steps:

1. Ensure you have gcc and kernel-devel installed:

yum install gcc kernel-devel

2. Unpack the attached tgz file

3. Attempt to build issuing the 'make' command in the samplemod/ directory.

Expected results: a compiled samplemod.ko with no errors

Actual results:

Code: Select all

[root@localhost samplemod]# make
make -C /lib/modules/3.10.0-123.9.3.el7.x86_64/build M=/root/samplemod modules
make[1]: Entering directory `/usr/src/kernels/3.10.0-123.9.3.el7.x86_64'
  CC [M]  /root/samplemod/main.o
  LD [M]  /root/samplemod/samplemod.o
  Building modules, stage 2.
  MODPOST 1 modules
WARNING: "getname" [/root/samplemod/samplemod.ko] undefined!
  CC      /root/samplemod/samplemod.mod.o
  LD [M]  /root/samplemod/samplemod.ko
make[1]: Leaving directory `/usr/src/kernels/3.10.0-123.9.3.el7.x86_64'
Attachments
samplemod.tgz
(534 Bytes) Downloaded 106 times

chemal
Posts: 776
Joined: 2013/12/08 19:44:49

Re: failure to build kernel module that uses getname()/putna

Post by chemal » 2014/11/19 02:01:09

If you type 'make V=1' instead of just 'make' you can see that the warning comes from a comparison of the symbols needed by your module vs the symbols exported by the kernel (listed in /usr/src/kernels/`uname -r`/Module.symvers). In other words: you cannot use getname() in modules anymore. See also http://linux-kernel.2935.n7.nabble.com/ ... 66022.html

gblues
Posts: 3
Joined: 2014/11/17 23:34:04

Re: failure to build kernel module that uses getname()/putna

Post by gblues » 2014/11/19 02:54:45

Well, that's one mystery solved. Thanks!

Of course now it raises a new puzzle: figuring out the new way to do it (assuming there is a new way to do it) in the 3.10 kernel. I've got some idea of where to look, but if anyone's got tips to save me some time, I'm all ears. :)

Post Reply