lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1282731815.2605.3473.camel@laptop>
Date:	Wed, 25 Aug 2010 12:23:35 +0200
From:	Peter Zijlstra <peterz@...radead.org>
To:	aijazbaig1@...il.com
Cc:	brgerst@...il.com, jengelh@...ozas.de,
	netfilter-devel@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: Fwd: help needed with EXPORT_SYMBOL

On Wed, 2010-08-25 at 14:57 +0530, Aijaz Baig wrote:

> I am trying to understand if its possible to add functions dynamically
> to the kernel source based on the presence of certain modules in the
> running kernel image.
> 
> I did try what brian suggested with the function pointer and yeah it
> does work. But I could not understand what peter was trying to say about
> modular users since I suppose he mentioned one module (B in this case)
> using a function pointer defined in (or by) module A. In my case, since
> it is the kernel that is gonna use the function, I need to make sure
> that the module doesn't get unloaded while we are using the function.

Right, so there's two problems there:

 - the exposed function pointer
 - unload serialization

The problem with the exposed function pointer is that two competing
modules can set the function pointer:

extern void (*ptr)(void);

static void (*old_ptr)(void);

void func(void)
{
  /* do something */
}

module_init()
{
  old_ptr = ptr;
  ptr = func;
}

module_exit()
{
  ptr = old_ptr;
  synchronize_stuff();
}

Now suppose two modules A and B both have that template, then load
module A, at that time ptr == A::func, A::old_ptr = NULL, right?

Then load B, then ptr == B:func, B::old_ptr = A::func.

then unload A, then ptr == NULL; /* hey where's B gone? */

Suppose module_exit() had read:

module_exit()
{
  if (ptr == func)
    ptr = old_ptr;
}

Then after A got unloaded, you'd have: ptr = B::func, B::old_ptr ==
A:func, and the world goes *bang* when you unload B.

If you'd have exposed the thing like:

static void (*callback)(void);

int set_foo_callback(void (*func)(void))
{
  if (callback && func)
    return -EBUSY;

  callback = func;
  synchronize_world();
  return 0;
}
EXPORT_SYMBOL_GPL(set_foo_callback);

Then there'd be no confusion, as loading B while A was already loaded
would fail since set_foo_callback() would fail with -EBUSY.


Now the synchronization issue, above represented by synchronize_world();
that will have to do something that ensures all current users of the ptr
have gone, taking a reference on the module will likely result in an
pinned module, since what will drop the ref again?

Module unload does a fairly heavy stop-machine thing, which might be
sufficient for some, but a sensible solution really depends on the
problem domain, RCU could be used in various ways.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ