Re: Linux Kernel - Modifying a module_param variable from other drivers

2013-11-14 Thread Valdis . Kletnieks
On Thu, 14 Nov 2013 18:32:05 +0900, manty kuma said:

 I see that when we declare a variable as module_param from a driver, i can
 see it listed in /sys/module/xxx/parameters/

 Ex : /sys/module/usbcore/parameters/autosuspend

 we can modify and read it with echo and cat commands from terminal.

 But is there a way i can read this value from other drivers? Common sense
 says it should be there because if we are able to access them from user
 space, from kernel space we should definitely be able to do. Is it so? If
 yes, what are the API's?

It's just a variable.  Read the source and find out what it's name is.
You may need an EXPORT_SYMBOL() to make it available if it isn't already.
And depending on the variable and its use, you may need locking and/or
atomic operations to read it.

And *modifying* another module's variables is just asking for trouble,
mostly because very little code is written assuming that its variables may
be maliciously modified out from under it.  So consider code like:

int foo_size, i;
struct bar *stuff;

stuff = malloc(foo_size* sizeof(struct bar));

/* somebody raises the value of foo_size from outside */

for (i=0; i  foo_size; i++) do_something(stuff[i]);

You can see where that sort of stuff is heading


pgpWZOSEWDIZQ.pgp
Description: PGP signature
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Linux Kernel - Modifying a module_param variable from other drivers

2013-11-14 Thread manty kuma
Ideally, it depends on the platform you are working. You need to discuss
with them for the correct approach. For Qualcomm they have some hardware
caled as RPU(Register protection unit). They have systems calls exposed for
using them. You can associtate it to the register you want protection. I
dont know if there is any way you could do it in Linux itself?

Regards,
Sandeep


On Fri, Nov 15, 2013 at 6:03 AM, valdis.kletni...@vt.edu wrote:

 On Thu, 14 Nov 2013 18:32:05 +0900, manty kuma said:

  I see that when we declare a variable as module_param from a driver, i
 can
  see it listed in /sys/module/xxx/parameters/
 
  Ex : /sys/module/usbcore/parameters/autosuspend
 
  we can modify and read it with echo and cat commands from terminal.
 
  But is there a way i can read this value from other drivers? Common sense
  says it should be there because if we are able to access them from user
  space, from kernel space we should definitely be able to do. Is it so? If
  yes, what are the API's?

 It's just a variable.  Read the source and find out what it's name is.
 You may need an EXPORT_SYMBOL() to make it available if it isn't already.
 And depending on the variable and its use, you may need locking and/or
 atomic operations to read it.

 And *modifying* another module's variables is just asking for trouble,
 mostly because very little code is written assuming that its variables may
 be maliciously modified out from under it.  So consider code like:

 int foo_size, i;
 struct bar *stuff;

 stuff = malloc(foo_size* sizeof(struct bar));

 /* somebody raises the value of foo_size from outside */

 for (i=0; i  foo_size; i++) do_something(stuff[i]);

 You can see where that sort of stuff is heading

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Linux Kernel - Modifying a module_param variable from other drivers

2013-11-14 Thread manty kuma
Hi Valdis,
Thank you for the reply.
I am not talking about all the variables. i am talking about variables
which are declared as module_param. These variables can anyways be changed
from shell prompt using echo and cat like i mentioned in the desciption. SO
i was hoping i can do it from drivers aswell.


Regards,
Sandeep


On Fri, Nov 15, 2013 at 10:30 AM, manty kuma mantyk...@gmail.com wrote:

 Sorry i was supposed to reply for another mail. Did it here by mistake.


 On Fri, Nov 15, 2013 at 10:29 AM, manty kuma mantyk...@gmail.com wrote:

 Ideally, it depends on the platform you are working. You need to discuss
 with them for the correct approach. For Qualcomm they have some hardware
 caled as RPU(Register protection unit). They have systems calls exposed for
 using them. You can associtate it to the register you want protection. I
 dont know if there is any way you could do it in Linux itself?

 Regards,
 Sandeep


 On Fri, Nov 15, 2013 at 6:03 AM, valdis.kletni...@vt.edu wrote:

 On Thu, 14 Nov 2013 18:32:05 +0900, manty kuma said:

  I see that when we declare a variable as module_param from a driver, i
 can
  see it listed in /sys/module/xxx/parameters/
 
  Ex : /sys/module/usbcore/parameters/autosuspend
 
  we can modify and read it with echo and cat commands from terminal.
 
  But is there a way i can read this value from other drivers? Common
 sense
  says it should be there because if we are able to access them from user
  space, from kernel space we should definitely be able to do. Is it so?
 If
  yes, what are the API's?

 It's just a variable.  Read the source and find out what it's name is.
 You may need an EXPORT_SYMBOL() to make it available if it isn't already.
 And depending on the variable and its use, you may need locking and/or
 atomic operations to read it.

 And *modifying* another module's variables is just asking for trouble,
 mostly because very little code is written assuming that its variables
 may
 be maliciously modified out from under it.  So consider code like:

 int foo_size, i;
 struct bar *stuff;

 stuff = malloc(foo_size* sizeof(struct bar));

 /* somebody raises the value of foo_size from outside */

 for (i=0; i  foo_size; i++) do_something(stuff[i]);

 You can see where that sort of stuff is heading




___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Linux Kernel - Modifying a module_param variable from other drivers

2013-11-14 Thread manty kuma
Sorry i was supposed to reply for another mail. Did it here by mistake.


On Fri, Nov 15, 2013 at 10:29 AM, manty kuma mantyk...@gmail.com wrote:

 Ideally, it depends on the platform you are working. You need to discuss
 with them for the correct approach. For Qualcomm they have some hardware
 caled as RPU(Register protection unit). They have systems calls exposed for
 using them. You can associtate it to the register you want protection. I
 dont know if there is any way you could do it in Linux itself?

 Regards,
 Sandeep


 On Fri, Nov 15, 2013 at 6:03 AM, valdis.kletni...@vt.edu wrote:

 On Thu, 14 Nov 2013 18:32:05 +0900, manty kuma said:

  I see that when we declare a variable as module_param from a driver, i
 can
  see it listed in /sys/module/xxx/parameters/
 
  Ex : /sys/module/usbcore/parameters/autosuspend
 
  we can modify and read it with echo and cat commands from terminal.
 
  But is there a way i can read this value from other drivers? Common
 sense
  says it should be there because if we are able to access them from user
  space, from kernel space we should definitely be able to do. Is it so?
 If
  yes, what are the API's?

 It's just a variable.  Read the source and find out what it's name is.
 You may need an EXPORT_SYMBOL() to make it available if it isn't already.
 And depending on the variable and its use, you may need locking and/or
 atomic operations to read it.

 And *modifying* another module's variables is just asking for trouble,
 mostly because very little code is written assuming that its variables may
 be maliciously modified out from under it.  So consider code like:

 int foo_size, i;
 struct bar *stuff;

 stuff = malloc(foo_size* sizeof(struct bar));

 /* somebody raises the value of foo_size from outside */

 for (i=0; i  foo_size; i++) do_something(stuff[i]);

 You can see where that sort of stuff is heading



___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Linux Kernel - Modifying a module_param variable from other drivers

2013-11-14 Thread Valdis . Kletnieks
On Fri, 15 Nov 2013 10:33:40 +0900, manty kuma said:

 I am not talking about all the variables. i am talking about variables
 which are declared as module_param. These variables can anyways be changed
 from shell prompt using echo and cat like i mentioned in the desciption.

If you actually chase through the code, you'll see that when you change a
module_param() variable, the module itself handles the parsing and then the
saving of the new value - which allows it to do any locking needed and
any cleanup of data that is required.

 SO i was hoping i can do it from drivers aswell.

The obvious first question is: Why are you trying to change a module's
variables from behind it's back, from another module?

There's no formal API for it, mostly because we don't usually create APIs
to support Usually Bad Ideas.


pgp9zfaAnkVc2.pgp
Description: PGP signature
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies